3 # Copyright (c) 2006 Shawn Pearce
6 test_description
='Test git update-ref and basic ref logging'
9 Z
=0000000000000000000000000000000000000000
11 test_expect_success setup
'
13 for name in A B C D E F
16 T=$(git write-tree) &&
17 sha1=$(echo $name | git commit-tree $T) &&
29 "git update-ref $m $A &&
30 test $A"' = $(cat .git/'"$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 &&
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 &&
56 git update-ref $n $A >out 2>err"'
58 rm -f .git
/$n_dir out err
61 "create $m (by HEAD)" \
62 "git update-ref HEAD $A &&
63 test $A"' = $(cat .git/'"$m"')'
65 "create $m (by HEAD)" \
66 "git update-ref HEAD $B $A &&
67 test $B"' = $(cat .git/'"$m"')'
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)
72 test_expect_success
"delete $m (by HEAD)" '
73 git update-ref -d HEAD $B &&
78 test_expect_success
'(not) create HEAD with old sha1' "
79 ! git update-ref HEAD $A $B
81 test_expect_success
"(not) prior created .git/$m" "
88 "git update-ref HEAD $A"
89 test_expect_success
'(not) change HEAD with wrong SHA1' "
90 ! git update-ref HEAD $B $Z
92 test_expect_success
"(not) changed .git/$m" "
93 ! test $B"' = $(cat .git/'"$m"')
97 : a repository with working tree always has reflog these days...
98 : >.git
/logs
/refs
/heads
/master
100 "create $m (logged by touch)" \
101 'GIT_COMMITTER_DATE="2005-05-26 23:30" \
102 git update-ref HEAD '"$A"' -m "Initial Creation" &&
103 test '"$A"' = $(cat .git/'"$m"')'
104 test_expect_success \
105 "update $m (logged by touch)" \
106 'GIT_COMMITTER_DATE="2005-05-26 23:31" \
107 git update-ref HEAD'" $B $A "'-m "Switch" &&
108 test '"$B"' = $(cat .git/'"$m"')'
109 test_expect_success \
110 "set $m (logged by touch)" \
111 'GIT_COMMITTER_DATE="2005-05-26 23:41" \
112 git update-ref HEAD'" $A &&
113 test $A"' = $(cat .git/'"$m"')'
116 $Z $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 Initial Creation
117 $A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150260 +0000 Switch
118 $B $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150860 +0000
120 test_expect_success \
121 "verifying $m's log" \
122 "diff expect .git/logs/$m"
123 rm -rf .git
/$m .git
/logs expect
125 test_expect_success \
126 'enable core.logAllRefUpdates' \
127 'git config core.logAllRefUpdates true &&
128 test true = $(git config --bool --get core.logAllRefUpdates)'
130 test_expect_success \
131 "create $m (logged by config)" \
132 'GIT_COMMITTER_DATE="2005-05-26 23:32" \
133 git update-ref HEAD'" $A "'-m "Initial Creation" &&
134 test '"$A"' = $(cat .git/'"$m"')'
135 test_expect_success \
136 "update $m (logged by config)" \
137 'GIT_COMMITTER_DATE="2005-05-26 23:33" \
138 git update-ref HEAD'" $B $A "'-m "Switch" &&
139 test '"$B"' = $(cat .git/'"$m"')'
140 test_expect_success \
141 "set $m (logged by config)" \
142 'GIT_COMMITTER_DATE="2005-05-26 23:43" \
143 git update-ref HEAD '"$A &&
144 test $A"' = $(cat .git/'"$m"')'
147 $Z $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150320 +0000 Initial Creation
148 $A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150380 +0000 Switch
149 $B $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150980 +0000
151 test_expect_success \
152 "verifying $m's log" \
153 'diff expect .git/logs/$m'
154 rm -f .git
/$m .git
/logs
/$m expect
157 cat >.git
/logs
/$m <<EOF
158 $C $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150320 -0500
159 $A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150380 -0500
160 $F $Z $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150680 -0500
161 $Z $E $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150980 -0500
164 ed
="Thu, 26 May 2005 18:32:00 -0500"
165 gd
="Thu, 26 May 2005 18:33:00 -0500"
166 ld
="Thu, 26 May 2005 18:43:00 -0500"
167 test_expect_success \
168 'Query "master@{May 25 2005}" (before history)' \
170 git rev-parse --verify "master@{May 25 2005}" >o 2>e &&
171 test '"$C"' = $(cat o) &&
172 test "warning: Log for '\'master
\'' only goes back to $ed." = "$(cat e)"'
173 test_expect_success \
174 "Query master@{2005-05-25} (before history)" \
176 git rev-parse --verify master@{2005-05-25} >o 2>e &&
177 test '"$C"' = $(cat o) &&
178 echo test "warning: Log for '\'master
\'' only goes back to $ed." = "$(cat e)"'
179 test_expect_success \
180 'Query "master@{May 26 2005 23:31:59}" (1 second before history)' \
182 git rev-parse --verify "master@{May 26 2005 23:31:59}" >o 2>e &&
183 test '"$C"' = $(cat o) &&
184 test "warning: Log for '\''master'\'' only goes back to $ed." = "$(cat e)"'
185 test_expect_success \
186 'Query "master@{May 26 2005 23:32:00}" (exactly history start)' \
188 git rev-parse --verify "master@{May 26 2005 23:32:00}" >o 2>e &&
189 test '"$A"' = $(cat o) &&
190 test "" = "$(cat e)"'
191 test_expect_success \
192 'Query "master@{2005-05-26 23:33:01}" (middle of history with gap)' \
194 git rev-parse --verify "master@{2005-05-26 23:33:01}" >o 2>e &&
195 test '"$B"' = $(cat o) &&
196 test "warning: Log .git/logs/'"$m has gap after $gd"'." = "$(cat e)"'
197 test_expect_success \
198 'Query "master@{2005-05-26 23:38:00}" (middle of history)' \
200 git rev-parse --verify "master@{2005-05-26 23:38:00}" >o 2>e &&
201 test '"$Z"' = $(cat o) &&
202 test "" = "$(cat e)"'
203 test_expect_success \
204 'Query "master@{2005-05-26 23:43:00}" (exact end of history)' \
206 git rev-parse --verify "master@{2005-05-26 23:43:00}" >o 2>e &&
207 test '"$E"' = $(cat o) &&
208 test "" = "$(cat e)"'
209 test_expect_success \
210 'Query "master@{2005-05-28}" (past end of history)' \
212 git rev-parse --verify "master@{2005-05-28}" >o 2>e &&
213 test '"$D"' = $(cat o) &&
214 test "warning: Log .git/logs/'"$m unexpectedly ended on $ld"'." = "$(cat e)"'
217 rm -f .git
/$m .git
/logs
/$m expect
219 test_expect_success \
220 'creating initial files' \
223 GIT_AUTHOR_DATE="2005-05-26 23:30" \
224 GIT_COMMITTER_DATE="2005-05-26 23:30" git-commit -m add -a &&
225 h_TEST=$(git rev-parse --verify HEAD)
226 echo The other day this did not work. >M &&
227 echo And then Bob told me how to fix it. >>M &&
229 GIT_AUTHOR_DATE="2005-05-26 23:41" \
230 GIT_COMMITTER_DATE="2005-05-26 23:41" git-commit -F M -a &&
231 h_OTHER=$(git rev-parse --verify HEAD) &&
232 GIT_AUTHOR_DATE="2005-05-26 23:44" \
233 GIT_COMMITTER_DATE="2005-05-26 23:44" git-commit --amend &&
234 h_FIXED=$(git rev-parse --verify HEAD) &&
235 echo Merged initial commit and a later commit. >M &&
236 echo $h_TEST >.git/MERGE_HEAD &&
237 GIT_AUTHOR_DATE="2005-05-26 23:45" \
238 GIT_COMMITTER_DATE="2005-05-26 23:45" git-commit -F M &&
239 h_MERGED=$(git rev-parse --verify HEAD) &&
243 $Z $h_TEST $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 commit (initial): add
244 $h_TEST $h_OTHER $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150860 +0000 commit: The other day this did not work.
245 $h_OTHER $h_FIXED $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117151040 +0000 commit (amend): The other day this did not work.
246 $h_FIXED $h_MERGED $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117151100 +0000 commit (merge): Merged initial commit and a later commit.
248 test_expect_success \
249 'git-commit logged updates' \
250 "diff expect .git/logs/$m"
251 unset h_TEST h_OTHER h_FIXED h_MERGED
253 test_expect_success \
254 'git cat-file blob master:F (expect OTHER)' \
255 'test OTHER = $(git cat-file blob master:F)'
256 test_expect_success \
257 'git cat-file blob master@{2005-05-26 23:30}:F (expect TEST)' \
258 'test TEST = $(git cat-file blob "master@{2005-05-26 23:30}:F")'
259 test_expect_success \
260 'git cat-file blob master@{2005-05-26 23:42}:F (expect OTHER)' \
261 'test OTHER = $(git cat-file blob "master@{2005-05-26 23:42}:F")'