]>
Commit | Line | Data |
---|---|---|
6de08ae6 SP |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2006 Shawn Pearce | |
4 | # | |
5 | ||
5be60078 | 6 | test_description='Test git update-ref and basic ref logging' |
6de08ae6 SP |
7 | . ./test-lib.sh |
8 | ||
3749fde5 | 9 | Z=$_z40 |
c3b0dec5 LT |
10 | |
11 | test_expect_success setup ' | |
12 | ||
13 | for name in A B C D E F | |
14 | do | |
15 | test_tick && | |
16 | T=$(git write-tree) && | |
17 | sha1=$(echo $name | git commit-tree $T) && | |
18 | eval $name=$sha1 | |
19 | done | |
20 | ||
21 | ' | |
22 | ||
6de08ae6 | 23 | m=refs/heads/master |
818f477c SP |
24 | n_dir=refs/heads/gu |
25 | n=$n_dir/fixes | |
6de08ae6 SP |
26 | |
27 | test_expect_success \ | |
28 | "create $m" \ | |
5be60078 | 29 | "git update-ref $m $A && |
8aac4b45 | 30 | test $A"' = $(cat .git/'"$m"')' |
6de08ae6 SP |
31 | test_expect_success \ |
32 | "create $m" \ | |
5be60078 | 33 | "git update-ref $m $B $A && |
8aac4b45 | 34 | test $B"' = $(cat .git/'"$m"')' |
40672a19 KW |
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)" | |
38 | ' | |
39 | test_expect_success "delete $m" ' | |
40 | git update-ref -d $m $B && | |
41 | ! test -f .git/$m | |
42 | ' | |
6de08ae6 SP |
43 | rm -f .git/$m |
44 | ||
3fe8dce6 KW |
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 | |
50 | " | |
51 | rm -f .git/$m | |
52 | ||
818f477c SP |
53 | test_expect_success \ |
54 | "fail to create $n" \ | |
598f0877 JN |
55 | "touch .git/$n_dir && |
56 | test_must_fail git update-ref $n $A >out 2>err" | |
818f477c SP |
57 | rm -f .git/$n_dir out err |
58 | ||
6de08ae6 SP |
59 | test_expect_success \ |
60 | "create $m (by HEAD)" \ | |
5be60078 | 61 | "git update-ref HEAD $A && |
8aac4b45 | 62 | test $A"' = $(cat .git/'"$m"')' |
6de08ae6 SP |
63 | test_expect_success \ |
64 | "create $m (by HEAD)" \ | |
5be60078 | 65 | "git update-ref HEAD $B $A && |
8aac4b45 | 66 | test $B"' = $(cat .git/'"$m"')' |
40672a19 KW |
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) | |
70 | ' | |
71 | test_expect_success "delete $m (by HEAD)" ' | |
72 | git update-ref -d HEAD $B && | |
73 | ! test -f .git/$m | |
74 | ' | |
6de08ae6 SP |
75 | rm -f .git/$m |
76 | ||
75c96e05 JH |
77 | test_expect_success \ |
78 | "create $m (by HEAD)" \ | |
79 | "git update-ref HEAD $A && | |
80 | test $A"' = $(cat .git/'"$m"')' | |
81 | test_expect_success \ | |
82 | "pack refs" \ | |
83 | "git pack-refs --all" | |
84 | test_expect_success \ | |
85 | "move $m (by HEAD)" \ | |
86 | "git update-ref HEAD $B $A && | |
87 | test $B"' = $(cat .git/'"$m"')' | |
b274a714 | 88 | test_expect_success "delete $m (by HEAD) should remove both packed and loose $m" ' |
75c96e05 JH |
89 | git update-ref -d HEAD $B && |
90 | ! grep "$m" .git/packed-refs && | |
91 | ! test -f .git/$m | |
92 | ' | |
93 | rm -f .git/$m | |
94 | ||
569740bd MV |
95 | cp -f .git/HEAD .git/HEAD.orig |
96 | test_expect_success "delete symref without dereference" ' | |
97 | git update-ref --no-deref -d HEAD && | |
98 | ! test -f .git/HEAD | |
99 | ' | |
100 | cp -f .git/HEAD.orig .git/HEAD | |
101 | ||
045a476f MV |
102 | test_expect_success "delete symref without dereference when the referred ref is packed" ' |
103 | echo foo >foo.c && | |
104 | git add foo.c && | |
105 | git commit -m foo && | |
106 | git pack-refs --all && | |
107 | git update-ref --no-deref -d HEAD && | |
108 | ! test -f .git/HEAD | |
109 | ' | |
110 | cp -f .git/HEAD.orig .git/HEAD | |
111 | git update-ref -d $m | |
112 | ||
41ac414e | 113 | test_expect_success '(not) create HEAD with old sha1' " |
d492b31c | 114 | test_must_fail git update-ref HEAD $A $B |
41ac414e JH |
115 | " |
116 | test_expect_success "(not) prior created .git/$m" " | |
117 | ! test -f .git/$m | |
118 | " | |
6de08ae6 SP |
119 | rm -f .git/$m |
120 | ||
121 | test_expect_success \ | |
122 | "create HEAD" \ | |
5be60078 | 123 | "git update-ref HEAD $A" |
41ac414e | 124 | test_expect_success '(not) change HEAD with wrong SHA1' " |
d492b31c | 125 | test_must_fail git update-ref HEAD $B $Z |
41ac414e JH |
126 | " |
127 | test_expect_success "(not) changed .git/$m" " | |
128 | ! test $B"' = $(cat .git/'"$m"') | |
129 | ' | |
6de08ae6 SP |
130 | rm -f .git/$m |
131 | ||
0bee5918 SP |
132 | : a repository with working tree always has reflog these days... |
133 | : >.git/logs/refs/heads/master | |
6de08ae6 SP |
134 | test_expect_success \ |
135 | "create $m (logged by touch)" \ | |
136 | 'GIT_COMMITTER_DATE="2005-05-26 23:30" \ | |
5be60078 | 137 | git update-ref HEAD '"$A"' -m "Initial Creation" && |
8aac4b45 | 138 | test '"$A"' = $(cat .git/'"$m"')' |
6de08ae6 SP |
139 | test_expect_success \ |
140 | "update $m (logged by touch)" \ | |
141 | 'GIT_COMMITTER_DATE="2005-05-26 23:31" \ | |
5be60078 | 142 | git update-ref HEAD'" $B $A "'-m "Switch" && |
8aac4b45 | 143 | test '"$B"' = $(cat .git/'"$m"')' |
6de08ae6 SP |
144 | test_expect_success \ |
145 | "set $m (logged by touch)" \ | |
146 | 'GIT_COMMITTER_DATE="2005-05-26 23:41" \ | |
5be60078 | 147 | git update-ref HEAD'" $A && |
8aac4b45 | 148 | test $A"' = $(cat .git/'"$m"')' |
6de08ae6 SP |
149 | |
150 | cat >expect <<EOF | |
151 | $Z $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 Initial Creation | |
152 | $A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150260 +0000 Switch | |
153 | $B $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150860 +0000 | |
154 | EOF | |
155 | test_expect_success \ | |
156 | "verifying $m's log" \ | |
188c3827 | 157 | "test_cmp expect .git/logs/$m" |
6de08ae6 SP |
158 | rm -rf .git/$m .git/logs expect |
159 | ||
160 | test_expect_success \ | |
161 | 'enable core.logAllRefUpdates' \ | |
5be60078 JH |
162 | 'git config core.logAllRefUpdates true && |
163 | test true = $(git config --bool --get core.logAllRefUpdates)' | |
6de08ae6 SP |
164 | |
165 | test_expect_success \ | |
166 | "create $m (logged by config)" \ | |
167 | 'GIT_COMMITTER_DATE="2005-05-26 23:32" \ | |
5be60078 | 168 | git update-ref HEAD'" $A "'-m "Initial Creation" && |
8aac4b45 | 169 | test '"$A"' = $(cat .git/'"$m"')' |
6de08ae6 SP |
170 | test_expect_success \ |
171 | "update $m (logged by config)" \ | |
172 | 'GIT_COMMITTER_DATE="2005-05-26 23:33" \ | |
5be60078 | 173 | git update-ref HEAD'" $B $A "'-m "Switch" && |
8aac4b45 | 174 | test '"$B"' = $(cat .git/'"$m"')' |
6de08ae6 SP |
175 | test_expect_success \ |
176 | "set $m (logged by config)" \ | |
177 | 'GIT_COMMITTER_DATE="2005-05-26 23:43" \ | |
5be60078 | 178 | git update-ref HEAD '"$A && |
8aac4b45 | 179 | test $A"' = $(cat .git/'"$m"')' |
6de08ae6 SP |
180 | |
181 | cat >expect <<EOF | |
182 | $Z $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150320 +0000 Initial Creation | |
183 | $A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150380 +0000 Switch | |
184 | $B $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150980 +0000 | |
185 | EOF | |
186 | test_expect_success \ | |
187 | "verifying $m's log" \ | |
188c3827 | 188 | 'test_cmp expect .git/logs/$m' |
6de08ae6 SP |
189 | rm -f .git/$m .git/logs/$m expect |
190 | ||
5be60078 | 191 | git update-ref $m $D |
e5229042 | 192 | cat >.git/logs/$m <<EOF |
d1a4489a JK |
193 | 0000000000000000000000000000000000000000 $C $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150320 -0500 |
194 | $C $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150350 -0500 | |
e5229042 SP |
195 | $A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150380 -0500 |
196 | $F $Z $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150680 -0500 | |
197 | $Z $E $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150980 -0500 | |
198 | EOF | |
199 | ||
200 | ed="Thu, 26 May 2005 18:32:00 -0500" | |
201 | gd="Thu, 26 May 2005 18:33:00 -0500" | |
202 | ld="Thu, 26 May 2005 18:43:00 -0500" | |
203 | test_expect_success \ | |
cce91a2c | 204 | 'Query "master@{May 25 2005}" (before history)' \ |
2dec68cf | 205 | 'rm -f o e && |
5be60078 | 206 | git rev-parse --verify "master@{May 25 2005}" >o 2>e && |
8aac4b45 | 207 | test '"$C"' = $(cat o) && |
16d7cc90 | 208 | test "warning: Log for '\'master\'' only goes back to $ed." = "$(cat e)"' |
e5229042 | 209 | test_expect_success \ |
cce91a2c | 210 | "Query master@{2005-05-25} (before history)" \ |
2dec68cf | 211 | 'rm -f o e && |
5be60078 | 212 | git rev-parse --verify master@{2005-05-25} >o 2>e && |
8aac4b45 | 213 | test '"$C"' = $(cat o) && |
16d7cc90 | 214 | echo test "warning: Log for '\'master\'' only goes back to $ed." = "$(cat e)"' |
e5229042 | 215 | test_expect_success \ |
cce91a2c | 216 | 'Query "master@{May 26 2005 23:31:59}" (1 second before history)' \ |
2dec68cf | 217 | 'rm -f o e && |
5be60078 | 218 | git rev-parse --verify "master@{May 26 2005 23:31:59}" >o 2>e && |
8aac4b45 | 219 | test '"$C"' = $(cat o) && |
16d7cc90 | 220 | test "warning: Log for '\''master'\'' only goes back to $ed." = "$(cat e)"' |
e5229042 | 221 | test_expect_success \ |
cce91a2c | 222 | 'Query "master@{May 26 2005 23:32:00}" (exactly history start)' \ |
2dec68cf | 223 | 'rm -f o e && |
5be60078 | 224 | git rev-parse --verify "master@{May 26 2005 23:32:00}" >o 2>e && |
d1a4489a JK |
225 | test '"$C"' = $(cat o) && |
226 | test "" = "$(cat e)"' | |
227 | test_expect_success \ | |
228 | 'Query "master@{May 26 2005 23:32:30}" (first non-creation change)' \ | |
2dec68cf | 229 | 'rm -f o e && |
d1a4489a | 230 | git rev-parse --verify "master@{May 26 2005 23:32:30}" >o 2>e && |
8aac4b45 | 231 | test '"$A"' = $(cat o) && |
e5229042 SP |
232 | test "" = "$(cat e)"' |
233 | test_expect_success \ | |
cce91a2c | 234 | 'Query "master@{2005-05-26 23:33:01}" (middle of history with gap)' \ |
2dec68cf | 235 | 'rm -f o e && |
5be60078 | 236 | git rev-parse --verify "master@{2005-05-26 23:33:01}" >o 2>e && |
8aac4b45 JH |
237 | test '"$B"' = $(cat o) && |
238 | test "warning: Log .git/logs/'"$m has gap after $gd"'." = "$(cat e)"' | |
e5229042 | 239 | test_expect_success \ |
cce91a2c | 240 | 'Query "master@{2005-05-26 23:38:00}" (middle of history)' \ |
2dec68cf | 241 | 'rm -f o e && |
5be60078 | 242 | git rev-parse --verify "master@{2005-05-26 23:38:00}" >o 2>e && |
8aac4b45 | 243 | test '"$Z"' = $(cat o) && |
e5229042 SP |
244 | test "" = "$(cat e)"' |
245 | test_expect_success \ | |
cce91a2c | 246 | 'Query "master@{2005-05-26 23:43:00}" (exact end of history)' \ |
2dec68cf | 247 | 'rm -f o e && |
5be60078 | 248 | git rev-parse --verify "master@{2005-05-26 23:43:00}" >o 2>e && |
8aac4b45 | 249 | test '"$E"' = $(cat o) && |
e5229042 SP |
250 | test "" = "$(cat e)"' |
251 | test_expect_success \ | |
cce91a2c | 252 | 'Query "master@{2005-05-28}" (past end of history)' \ |
2dec68cf | 253 | 'rm -f o e && |
5be60078 | 254 | git rev-parse --verify "master@{2005-05-28}" >o 2>e && |
8aac4b45 JH |
255 | test '"$D"' = $(cat o) && |
256 | test "warning: Log .git/logs/'"$m unexpectedly ended on $ld"'." = "$(cat e)"' | |
e5229042 | 257 | |
cce91a2c SP |
258 | |
259 | rm -f .git/$m .git/logs/$m expect | |
260 | ||
261 | test_expect_success \ | |
262 | 'creating initial files' \ | |
9c7466fa | 263 | 'echo TEST >F && |
5be60078 | 264 | git add F && |
9c7466fa | 265 | GIT_AUTHOR_DATE="2005-05-26 23:30" \ |
0cb0e143 | 266 | GIT_COMMITTER_DATE="2005-05-26 23:30" git commit -m add -a && |
2dec68cf | 267 | h_TEST=$(git rev-parse --verify HEAD) && |
9c7466fa SP |
268 | echo The other day this did not work. >M && |
269 | echo And then Bob told me how to fix it. >>M && | |
270 | echo OTHER >F && | |
271 | GIT_AUTHOR_DATE="2005-05-26 23:41" \ | |
0cb0e143 | 272 | GIT_COMMITTER_DATE="2005-05-26 23:41" git commit -F M -a && |
5be60078 | 273 | h_OTHER=$(git rev-parse --verify HEAD) && |
a3a733e6 | 274 | GIT_AUTHOR_DATE="2005-05-26 23:44" \ |
0cb0e143 | 275 | GIT_COMMITTER_DATE="2005-05-26 23:44" git commit --amend && |
5be60078 | 276 | h_FIXED=$(git rev-parse --verify HEAD) && |
a3a733e6 SP |
277 | echo Merged initial commit and a later commit. >M && |
278 | echo $h_TEST >.git/MERGE_HEAD && | |
279 | GIT_AUTHOR_DATE="2005-05-26 23:45" \ | |
0cb0e143 | 280 | GIT_COMMITTER_DATE="2005-05-26 23:45" git commit -F M && |
d9c8344b | 281 | h_MERGED=$(git rev-parse --verify HEAD) && |
9c7466fa SP |
282 | rm -f M' |
283 | ||
284 | cat >expect <<EOF | |
a3a733e6 | 285 | $Z $h_TEST $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 commit (initial): add |
9c7466fa | 286 | $h_TEST $h_OTHER $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150860 +0000 commit: The other day this did not work. |
a3a733e6 SP |
287 | $h_OTHER $h_FIXED $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117151040 +0000 commit (amend): The other day this did not work. |
288 | $h_FIXED $h_MERGED $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117151100 +0000 commit (merge): Merged initial commit and a later commit. | |
9c7466fa SP |
289 | EOF |
290 | test_expect_success \ | |
0cb0e143 | 291 | 'git commit logged updates' \ |
188c3827 | 292 | "test_cmp expect .git/logs/$m" |
a3a733e6 | 293 | unset h_TEST h_OTHER h_FIXED h_MERGED |
cce91a2c SP |
294 | |
295 | test_expect_success \ | |
5be60078 JH |
296 | 'git cat-file blob master:F (expect OTHER)' \ |
297 | 'test OTHER = $(git cat-file blob master:F)' | |
cce91a2c | 298 | test_expect_success \ |
5be60078 JH |
299 | 'git cat-file blob master@{2005-05-26 23:30}:F (expect TEST)' \ |
300 | 'test TEST = $(git cat-file blob "master@{2005-05-26 23:30}:F")' | |
cce91a2c | 301 | test_expect_success \ |
5be60078 JH |
302 | 'git cat-file blob master@{2005-05-26 23:42}:F (expect OTHER)' \ |
303 | 'test OTHER = $(git cat-file blob "master@{2005-05-26 23:42}:F")' | |
cce91a2c | 304 | |
6de08ae6 | 305 | test_done |