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