Merge branch 'lt/tree-2'
[git/git.git] / t / t1400-update-ref.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2006 Shawn Pearce
4 #
5
6 test_description='Test git-update-ref and basic ref logging'
7 . ./test-lib.sh
8
9 Z=0000000000000000000000000000000000000000
10 A=1111111111111111111111111111111111111111
11 B=2222222222222222222222222222222222222222
12 C=3333333333333333333333333333333333333333
13 D=4444444444444444444444444444444444444444
14 E=5555555555555555555555555555555555555555
15 F=6666666666666666666666666666666666666666
16 m=refs/heads/master
17
18 test_expect_success \
19 "create $m" \
20 'git-update-ref $m $A &&
21 test $A = $(cat .git/$m)'
22 test_expect_success \
23 "create $m" \
24 'git-update-ref $m $B $A &&
25 test $B = $(cat .git/$m)'
26 rm -f .git/$m
27
28 test_expect_success \
29 "create $m (by HEAD)" \
30 'git-update-ref HEAD $A &&
31 test $A = $(cat .git/$m)'
32 test_expect_success \
33 "create $m (by HEAD)" \
34 'git-update-ref HEAD $B $A &&
35 test $B = $(cat .git/$m)'
36 rm -f .git/$m
37
38 test_expect_failure \
39 '(not) create HEAD with old sha1' \
40 'git-update-ref HEAD $A $B'
41 test_expect_failure \
42 "(not) prior created .git/$m" \
43 'test -f .git/$m'
44 rm -f .git/$m
45
46 test_expect_success \
47 "create HEAD" \
48 'git-update-ref HEAD $A'
49 test_expect_failure \
50 '(not) change HEAD with wrong SHA1' \
51 'git-update-ref HEAD $B $Z'
52 test_expect_failure \
53 "(not) changed .git/$m" \
54 'test $B = $(cat .git/$m)'
55 rm -f .git/$m
56
57 mkdir -p .git/logs/refs/heads
58 touch .git/logs/refs/heads/master
59 test_expect_success \
60 "create $m (logged by touch)" \
61 'GIT_COMMITTER_DATE="2005-05-26 23:30" \
62 git-update-ref HEAD $A -m "Initial Creation" &&
63 test $A = $(cat .git/$m)'
64 test_expect_success \
65 "update $m (logged by touch)" \
66 'GIT_COMMITTER_DATE="2005-05-26 23:31" \
67 git-update-ref HEAD $B $A -m "Switch" &&
68 test $B = $(cat .git/$m)'
69 test_expect_success \
70 "set $m (logged by touch)" \
71 'GIT_COMMITTER_DATE="2005-05-26 23:41" \
72 git-update-ref HEAD $A &&
73 test $A = $(cat .git/$m)'
74
75 cat >expect <<EOF
76 $Z $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 Initial Creation
77 $A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150260 +0000 Switch
78 $B $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150860 +0000
79 EOF
80 test_expect_success \
81 "verifying $m's log" \
82 'diff expect .git/logs/$m'
83 rm -rf .git/$m .git/logs expect
84
85 test_expect_success \
86 'enable core.logAllRefUpdates' \
87 'git-repo-config core.logAllRefUpdates true &&
88 test true = $(git-repo-config --bool --get core.logAllRefUpdates)'
89
90 test_expect_success \
91 "create $m (logged by config)" \
92 'GIT_COMMITTER_DATE="2005-05-26 23:32" \
93 git-update-ref HEAD $A -m "Initial Creation" &&
94 test $A = $(cat .git/$m)'
95 test_expect_success \
96 "update $m (logged by config)" \
97 'GIT_COMMITTER_DATE="2005-05-26 23:33" \
98 git-update-ref HEAD $B $A -m "Switch" &&
99 test $B = $(cat .git/$m)'
100 test_expect_success \
101 "set $m (logged by config)" \
102 'GIT_COMMITTER_DATE="2005-05-26 23:43" \
103 git-update-ref HEAD $A &&
104 test $A = $(cat .git/$m)'
105
106 cat >expect <<EOF
107 $Z $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150320 +0000 Initial Creation
108 $A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150380 +0000 Switch
109 $B $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150980 +0000
110 EOF
111 test_expect_success \
112 "verifying $m's log" \
113 'diff expect .git/logs/$m'
114 rm -f .git/$m .git/logs/$m expect
115
116 git-update-ref $m $D
117 cat >.git/logs/$m <<EOF
118 $C $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150320 -0500
119 $A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150380 -0500
120 $F $Z $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150680 -0500
121 $Z $E $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150980 -0500
122 EOF
123
124 ed="Thu, 26 May 2005 18:32:00 -0500"
125 gd="Thu, 26 May 2005 18:33:00 -0500"
126 ld="Thu, 26 May 2005 18:43:00 -0500"
127 test_expect_success \
128 'Query "master@{May 25 2005}" (before history)' \
129 'rm -f o e
130 git-rev-parse --verify "master@{May 25 2005}" >o 2>e &&
131 test $C = $(cat o) &&
132 test "warning: Log .git/logs/$m only goes back to $ed." = "$(cat e)"'
133 test_expect_success \
134 "Query master@{2005-05-25} (before history)" \
135 'rm -f o e
136 git-rev-parse --verify master@{2005-05-25} >o 2>e &&
137 test $C = $(cat o) &&
138 echo test "warning: Log .git/logs/$m only goes back to $ed." = "$(cat e)"'
139 test_expect_success \
140 'Query "master@{May 26 2005 23:31:59}" (1 second before history)' \
141 'rm -f o e
142 git-rev-parse --verify "master@{May 26 2005 23:31:59}" >o 2>e &&
143 test $C = $(cat o) &&
144 test "warning: Log .git/logs/$m only goes back to $ed." = "$(cat e)"'
145 test_expect_success \
146 'Query "master@{May 26 2005 23:32:00}" (exactly history start)' \
147 'rm -f o e
148 git-rev-parse --verify "master@{May 26 2005 23:32:00}" >o 2>e &&
149 test $A = $(cat o) &&
150 test "" = "$(cat e)"'
151 test_expect_success \
152 'Query "master@{2005-05-26 23:33:01}" (middle of history with gap)' \
153 'rm -f o e
154 git-rev-parse --verify "master@{2005-05-26 23:33:01}" >o 2>e &&
155 test $B = $(cat o) &&
156 test "warning: Log .git/logs/$m has gap after $gd." = "$(cat e)"'
157 test_expect_success \
158 'Query "master@{2005-05-26 23:38:00}" (middle of history)' \
159 'rm -f o e
160 git-rev-parse --verify "master@{2005-05-26 23:38:00}" >o 2>e &&
161 test $Z = $(cat o) &&
162 test "" = "$(cat e)"'
163 test_expect_success \
164 'Query "master@{2005-05-26 23:43:00}" (exact end of history)' \
165 'rm -f o e
166 git-rev-parse --verify "master@{2005-05-26 23:43:00}" >o 2>e &&
167 test $E = $(cat o) &&
168 test "" = "$(cat e)"'
169 test_expect_success \
170 'Query "master@{2005-05-28}" (past end of history)' \
171 'rm -f o e
172 git-rev-parse --verify "master@{2005-05-28}" >o 2>e &&
173 test $D = $(cat o) &&
174 test "warning: Log .git/logs/$m unexpectedly ended on $ld." = "$(cat e)"'
175
176
177 rm -f .git/$m .git/logs/$m expect
178
179 test_expect_success \
180 'creating initial files' \
181 'echo TEST >F &&
182 git-add F &&
183 GIT_AUTHOR_DATE="2005-05-26 23:30" \
184 GIT_COMMITTER_DATE="2005-05-26 23:30" git-commit -m add -a &&
185 h_TEST=$(git-rev-parse --verify HEAD)
186 echo The other day this did not work. >M &&
187 echo And then Bob told me how to fix it. >>M &&
188 echo OTHER >F &&
189 GIT_AUTHOR_DATE="2005-05-26 23:41" \
190 GIT_COMMITTER_DATE="2005-05-26 23:41" git-commit -F M -a &&
191 h_OTHER=$(git-rev-parse --verify HEAD)
192 rm -f M'
193
194 cat >expect <<EOF
195 $Z $h_TEST $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 commit: add
196 $h_TEST $h_OTHER $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150860 +0000 commit: The other day this did not work.
197 EOF
198 test_expect_success \
199 'git-commit logged updates' \
200 'diff expect .git/logs/$m'
201 unset h_TEST h_OTHER
202
203 test_expect_success \
204 'git-cat-file blob master:F (expect OTHER)' \
205 'test OTHER = $(git-cat-file blob master:F)'
206 test_expect_success \
207 'git-cat-file blob master@{2005-05-26 23:30}:F (expect TEST)' \
208 'test TEST = $(git-cat-file blob "master@{2005-05-26 23:30}:F")'
209 test_expect_success \
210 'git-cat-file blob master@{2005-05-26 23:42}:F (expect OTHER)' \
211 'test OTHER = $(git-cat-file blob "master@{2005-05-26 23:42}:F")'
212
213 test_done