Start 1.7.5.4 draft release notes
[git/mingw.git] / t / t1400-update-ref.sh
blob4fd83a667ac8b08bef090d303bc4434969874780
1 #!/bin/sh
3 # Copyright (c) 2006 Shawn Pearce
6 test_description='Test git update-ref and basic ref logging'
7 . ./test-lib.sh
9 Z=$_z40
11 test_expect_success setup '
13 for name in A B C D E F
15 test_tick &&
16 T=$(git write-tree) &&
17 sha1=$(echo $name | git commit-tree $T) &&
18 eval $name=$sha1
19 done
23 m=refs/heads/master
24 n_dir=refs/heads/gu
25 n=$n_dir/fixes
27 test_expect_success \
28 "create $m" \
29 "git update-ref $m $A &&
30 test $A"' = $(cat .git/'"$m"')'
31 test_expect_success \
32 "create $m" \
33 "git update-ref $m $B $A &&
34 test $B"' = $(cat .git/'"$m"')'
35 test_expect_success "fail to delete $m with stale ref" '
36 test_must_fail git update-ref -d $m $A &&
37 test $B = "$(cat .git/$m)"
39 test_expect_success "delete $m" '
40 git update-ref -d $m $B &&
41 ! test -f .git/$m
43 rm -f .git/$m
45 test_expect_success "delete $m without oldvalue verification" "
46 git update-ref $m $A &&
47 test $A = \$(cat .git/$m) &&
48 git update-ref -d $m &&
49 ! test -f .git/$m
51 rm -f .git/$m
53 test_expect_success \
54 "fail to create $n" \
55 "touch .git/$n_dir &&
56 test_must_fail git update-ref $n $A >out 2>err"
57 rm -f .git/$n_dir out err
59 test_expect_success \
60 "create $m (by HEAD)" \
61 "git update-ref HEAD $A &&
62 test $A"' = $(cat .git/'"$m"')'
63 test_expect_success \
64 "create $m (by HEAD)" \
65 "git update-ref HEAD $B $A &&
66 test $B"' = $(cat .git/'"$m"')'
67 test_expect_success "fail to delete $m (by HEAD) with stale ref" '
68 test_must_fail git update-ref -d HEAD $A &&
69 test $B = $(cat .git/$m)
71 test_expect_success "delete $m (by HEAD)" '
72 git update-ref -d HEAD $B &&
73 ! test -f .git/$m
75 rm -f .git/$m
77 cp -f .git/HEAD .git/HEAD.orig
78 test_expect_success "delete symref without dereference" '
79 git update-ref --no-deref -d HEAD &&
80 ! test -f .git/HEAD
82 cp -f .git/HEAD.orig .git/HEAD
84 test_expect_success "delete symref without dereference when the referred ref is packed" '
85 echo foo >foo.c &&
86 git add foo.c &&
87 git commit -m foo &&
88 git pack-refs --all &&
89 git update-ref --no-deref -d HEAD &&
90 ! test -f .git/HEAD
92 cp -f .git/HEAD.orig .git/HEAD
93 git update-ref -d $m
95 test_expect_success '(not) create HEAD with old sha1' "
96 test_must_fail git update-ref HEAD $A $B
98 test_expect_success "(not) prior created .git/$m" "
99 ! test -f .git/$m
101 rm -f .git/$m
103 test_expect_success \
104 "create HEAD" \
105 "git update-ref HEAD $A"
106 test_expect_success '(not) change HEAD with wrong SHA1' "
107 test_must_fail git update-ref HEAD $B $Z
109 test_expect_success "(not) changed .git/$m" "
110 ! test $B"' = $(cat .git/'"$m"')
112 rm -f .git/$m
114 : a repository with working tree always has reflog these days...
115 : >.git/logs/refs/heads/master
116 test_expect_success \
117 "create $m (logged by touch)" \
118 'GIT_COMMITTER_DATE="2005-05-26 23:30" \
119 git update-ref HEAD '"$A"' -m "Initial Creation" &&
120 test '"$A"' = $(cat .git/'"$m"')'
121 test_expect_success \
122 "update $m (logged by touch)" \
123 'GIT_COMMITTER_DATE="2005-05-26 23:31" \
124 git update-ref HEAD'" $B $A "'-m "Switch" &&
125 test '"$B"' = $(cat .git/'"$m"')'
126 test_expect_success \
127 "set $m (logged by touch)" \
128 'GIT_COMMITTER_DATE="2005-05-26 23:41" \
129 git update-ref HEAD'" $A &&
130 test $A"' = $(cat .git/'"$m"')'
132 cat >expect <<EOF
133 $Z $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 Initial Creation
134 $A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150260 +0000 Switch
135 $B $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150860 +0000
137 test_expect_success \
138 "verifying $m's log" \
139 "test_cmp expect .git/logs/$m"
140 rm -rf .git/$m .git/logs expect
142 test_expect_success \
143 'enable core.logAllRefUpdates' \
144 'git config core.logAllRefUpdates true &&
145 test true = $(git config --bool --get core.logAllRefUpdates)'
147 test_expect_success \
148 "create $m (logged by config)" \
149 'GIT_COMMITTER_DATE="2005-05-26 23:32" \
150 git update-ref HEAD'" $A "'-m "Initial Creation" &&
151 test '"$A"' = $(cat .git/'"$m"')'
152 test_expect_success \
153 "update $m (logged by config)" \
154 'GIT_COMMITTER_DATE="2005-05-26 23:33" \
155 git update-ref HEAD'" $B $A "'-m "Switch" &&
156 test '"$B"' = $(cat .git/'"$m"')'
157 test_expect_success \
158 "set $m (logged by config)" \
159 'GIT_COMMITTER_DATE="2005-05-26 23:43" \
160 git update-ref HEAD '"$A &&
161 test $A"' = $(cat .git/'"$m"')'
163 cat >expect <<EOF
164 $Z $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150320 +0000 Initial Creation
165 $A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150380 +0000 Switch
166 $B $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150980 +0000
168 test_expect_success \
169 "verifying $m's log" \
170 'test_cmp expect .git/logs/$m'
171 rm -f .git/$m .git/logs/$m expect
173 git update-ref $m $D
174 cat >.git/logs/$m <<EOF
175 0000000000000000000000000000000000000000 $C $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150320 -0500
176 $C $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150350 -0500
177 $A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150380 -0500
178 $F $Z $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150680 -0500
179 $Z $E $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150980 -0500
182 ed="Thu, 26 May 2005 18:32:00 -0500"
183 gd="Thu, 26 May 2005 18:33:00 -0500"
184 ld="Thu, 26 May 2005 18:43:00 -0500"
185 test_expect_success \
186 'Query "master@{May 25 2005}" (before history)' \
187 'rm -f o e &&
188 git rev-parse --verify "master@{May 25 2005}" >o 2>e &&
189 test '"$C"' = $(cat o) &&
190 test "warning: Log for '\'master\'' only goes back to $ed." = "$(cat e)"'
191 test_expect_success \
192 "Query master@{2005-05-25} (before history)" \
193 'rm -f o e &&
194 git rev-parse --verify master@{2005-05-25} >o 2>e &&
195 test '"$C"' = $(cat o) &&
196 echo test "warning: Log for '\'master\'' only goes back to $ed." = "$(cat e)"'
197 test_expect_success \
198 'Query "master@{May 26 2005 23:31:59}" (1 second before history)' \
199 'rm -f o e &&
200 git rev-parse --verify "master@{May 26 2005 23:31:59}" >o 2>e &&
201 test '"$C"' = $(cat o) &&
202 test "warning: Log for '\''master'\'' only goes back to $ed." = "$(cat e)"'
203 test_expect_success \
204 'Query "master@{May 26 2005 23:32:00}" (exactly history start)' \
205 'rm -f o e &&
206 git rev-parse --verify "master@{May 26 2005 23:32:00}" >o 2>e &&
207 test '"$C"' = $(cat o) &&
208 test "" = "$(cat e)"'
209 test_expect_success \
210 'Query "master@{May 26 2005 23:32:30}" (first non-creation change)' \
211 'rm -f o e &&
212 git rev-parse --verify "master@{May 26 2005 23:32:30}" >o 2>e &&
213 test '"$A"' = $(cat o) &&
214 test "" = "$(cat e)"'
215 test_expect_success \
216 'Query "master@{2005-05-26 23:33:01}" (middle of history with gap)' \
217 'rm -f o e &&
218 git rev-parse --verify "master@{2005-05-26 23:33:01}" >o 2>e &&
219 test '"$B"' = $(cat o) &&
220 test "warning: Log .git/logs/'"$m has gap after $gd"'." = "$(cat e)"'
221 test_expect_success \
222 'Query "master@{2005-05-26 23:38:00}" (middle of history)' \
223 'rm -f o e &&
224 git rev-parse --verify "master@{2005-05-26 23:38:00}" >o 2>e &&
225 test '"$Z"' = $(cat o) &&
226 test "" = "$(cat e)"'
227 test_expect_success \
228 'Query "master@{2005-05-26 23:43:00}" (exact end of history)' \
229 'rm -f o e &&
230 git rev-parse --verify "master@{2005-05-26 23:43:00}" >o 2>e &&
231 test '"$E"' = $(cat o) &&
232 test "" = "$(cat e)"'
233 test_expect_success \
234 'Query "master@{2005-05-28}" (past end of history)' \
235 'rm -f o e &&
236 git rev-parse --verify "master@{2005-05-28}" >o 2>e &&
237 test '"$D"' = $(cat o) &&
238 test "warning: Log .git/logs/'"$m unexpectedly ended on $ld"'." = "$(cat e)"'
241 rm -f .git/$m .git/logs/$m expect
243 test_expect_success \
244 'creating initial files' \
245 'echo TEST >F &&
246 git add F &&
247 GIT_AUTHOR_DATE="2005-05-26 23:30" \
248 GIT_COMMITTER_DATE="2005-05-26 23:30" git commit -m add -a &&
249 h_TEST=$(git rev-parse --verify HEAD) &&
250 echo The other day this did not work. >M &&
251 echo And then Bob told me how to fix it. >>M &&
252 echo OTHER >F &&
253 GIT_AUTHOR_DATE="2005-05-26 23:41" \
254 GIT_COMMITTER_DATE="2005-05-26 23:41" git commit -F M -a &&
255 h_OTHER=$(git rev-parse --verify HEAD) &&
256 GIT_AUTHOR_DATE="2005-05-26 23:44" \
257 GIT_COMMITTER_DATE="2005-05-26 23:44" git commit --amend &&
258 h_FIXED=$(git rev-parse --verify HEAD) &&
259 echo Merged initial commit and a later commit. >M &&
260 echo $h_TEST >.git/MERGE_HEAD &&
261 GIT_AUTHOR_DATE="2005-05-26 23:45" \
262 GIT_COMMITTER_DATE="2005-05-26 23:45" git commit -F M &&
263 h_MERGED=$(git rev-parse --verify HEAD) &&
264 rm -f M'
266 cat >expect <<EOF
267 $Z $h_TEST $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 commit (initial): add
268 $h_TEST $h_OTHER $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150860 +0000 commit: The other day this did not work.
269 $h_OTHER $h_FIXED $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117151040 +0000 commit (amend): The other day this did not work.
270 $h_FIXED $h_MERGED $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117151100 +0000 commit (merge): Merged initial commit and a later commit.
272 test_expect_success \
273 'git commit logged updates' \
274 "test_cmp expect .git/logs/$m"
275 unset h_TEST h_OTHER h_FIXED h_MERGED
277 test_expect_success \
278 'git cat-file blob master:F (expect OTHER)' \
279 'test OTHER = $(git cat-file blob master:F)'
280 test_expect_success \
281 'git cat-file blob master@{2005-05-26 23:30}:F (expect TEST)' \
282 'test TEST = $(git cat-file blob "master@{2005-05-26 23:30}:F")'
283 test_expect_success \
284 'git cat-file blob master@{2005-05-26 23:42}:F (expect OTHER)' \
285 'test OTHER = $(git cat-file blob "master@{2005-05-26 23:42}:F")'
287 test_done