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 &&
48 git update-ref $n $A >out 2>err"'
50 rm -f .git/$n_dir out err
53 "create $m (by HEAD)" \
54 "git update-ref HEAD $A &&
55 test $A"' = $(cat .git/'"$m"')'
57 "create $m (by HEAD)" \
58 "git update-ref HEAD $B $A &&
59 test $B"' = $(cat .git/'"$m"')'
60 test_expect_success "fail to delete $m (by HEAD) with stale ref" '
61 test_must_fail git update-ref -d HEAD $A &&
62 test $B = $(cat .git/$m)
64 test_expect_success "delete $m (by HEAD)" '
65 git update-ref -d HEAD $B &&
70 test_expect_success '(not) create HEAD with old sha1' "
71 ! git update-ref HEAD $A $B
73 test_expect_success "(not) prior created .git/$m" "
80 "git update-ref HEAD $A"
81 test_expect_success '(not) change HEAD with wrong SHA1' "
82 ! git update-ref HEAD $B $Z
84 test_expect_success "(not) changed .git/$m" "
85 ! test $B"' = $(cat .git/'"$m"')
89 : a repository with working tree always has reflog these days...
90 : >.git/logs/refs/heads/master
92 "create $m (logged by touch)" \
93 'GIT_COMMITTER_DATE="2005-05-26 23:30" \
94 git update-ref HEAD '"$A"' -m "Initial Creation" &&
95 test '"$A"' = $(cat .git/'"$m"')'
97 "update $m (logged by touch)" \
98 'GIT_COMMITTER_DATE="2005-05-26 23:31" \
99 git update-ref HEAD'" $B $A "'-m "Switch" &&
100 test '"$B"' = $(cat .git/'"$m"')'
101 test_expect_success \
102 "set $m (logged by touch)" \
103 'GIT_COMMITTER_DATE="2005-05-26 23:41" \
104 git update-ref HEAD'" $A &&
105 test $A"' = $(cat .git/'"$m"')'
108 $Z $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 Initial Creation
109 $A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150260 +0000 Switch
110 $B $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150860 +0000
112 test_expect_success \
113 "verifying $m's log" \
114 "diff expect .git/logs/$m"
115 rm -rf .git/$m .git/logs expect
117 test_expect_success \
118 'enable core.logAllRefUpdates' \
119 'git config core.logAllRefUpdates true &&
120 test true = $(git config --bool --get core.logAllRefUpdates)'
122 test_expect_success \
123 "create $m (logged by config)" \
124 'GIT_COMMITTER_DATE="2005-05-26 23:32" \
125 git update-ref HEAD'" $A "'-m "Initial Creation" &&
126 test '"$A"' = $(cat .git/'"$m"')'
127 test_expect_success \
128 "update $m (logged by config)" \
129 'GIT_COMMITTER_DATE="2005-05-26 23:33" \
130 git update-ref HEAD'" $B $A "'-m "Switch" &&
131 test '"$B"' = $(cat .git/'"$m"')'
132 test_expect_success \
133 "set $m (logged by config)" \
134 'GIT_COMMITTER_DATE="2005-05-26 23:43" \
135 git update-ref HEAD '"$A &&
136 test $A"' = $(cat .git/'"$m"')'
139 $Z $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150320 +0000 Initial Creation
140 $A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150380 +0000 Switch
141 $B $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150980 +0000
143 test_expect_success \
144 "verifying $m's log" \
145 'diff expect .git/logs/$m'
146 rm -f .git/$m .git/logs/$m expect
149 cat >.git/logs/$m <<EOF
150 $C $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150320 -0500
151 $A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150380 -0500
152 $F $Z $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150680 -0500
153 $Z $E $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150980 -0500
156 ed="Thu, 26 May 2005 18:32:00 -0500"
157 gd="Thu, 26 May 2005 18:33:00 -0500"
158 ld="Thu, 26 May 2005 18:43:00 -0500"
159 test_expect_success \
160 'Query "master@{May 25 2005}" (before history)' \
162 git rev-parse --verify "master@{May 25 2005}" >o 2>e &&
163 test '"$C"' = $(cat o) &&
164 test "warning: Log for '\'master\'' only goes back to $ed." = "$(cat e)"'
165 test_expect_success \
166 "Query master@{2005-05-25} (before history)" \
168 git rev-parse --verify master@{2005-05-25} >o 2>e &&
169 test '"$C"' = $(cat o) &&
170 echo test "warning: Log for '\'master\'' only goes back to $ed." = "$(cat e)"'
171 test_expect_success \
172 'Query "master@{May 26 2005 23:31:59}" (1 second before history)' \
174 git rev-parse --verify "master@{May 26 2005 23:31:59}" >o 2>e &&
175 test '"$C"' = $(cat o) &&
176 test "warning: Log for '\''master'\'' only goes back to $ed." = "$(cat e)"'
177 test_expect_success \
178 'Query "master@{May 26 2005 23:32:00}" (exactly history start)' \
180 git rev-parse --verify "master@{May 26 2005 23:32:00}" >o 2>e &&
181 test '"$A"' = $(cat o) &&
182 test "" = "$(cat e)"'
183 test_expect_success \
184 'Query "master@{2005-05-26 23:33:01}" (middle of history with gap)' \
186 git rev-parse --verify "master@{2005-05-26 23:33:01}" >o 2>e &&
187 test '"$B"' = $(cat o) &&
188 test "warning: Log .git/logs/'"$m has gap after $gd"'." = "$(cat e)"'
189 test_expect_success \
190 'Query "master@{2005-05-26 23:38:00}" (middle of history)' \
192 git rev-parse --verify "master@{2005-05-26 23:38:00}" >o 2>e &&
193 test '"$Z"' = $(cat o) &&
194 test "" = "$(cat e)"'
195 test_expect_success \
196 'Query "master@{2005-05-26 23:43:00}" (exact end of history)' \
198 git rev-parse --verify "master@{2005-05-26 23:43:00}" >o 2>e &&
199 test '"$E"' = $(cat o) &&
200 test "" = "$(cat e)"'
201 test_expect_success \
202 'Query "master@{2005-05-28}" (past end of history)' \
204 git rev-parse --verify "master@{2005-05-28}" >o 2>e &&
205 test '"$D"' = $(cat o) &&
206 test "warning: Log .git/logs/'"$m unexpectedly ended on $ld"'." = "$(cat e)"'
209 rm -f .git/$m .git/logs/$m expect
211 test_expect_success \
212 'creating initial files' \
215 GIT_AUTHOR_DATE="2005-05-26 23:30" \
216 GIT_COMMITTER_DATE="2005-05-26 23:30" git-commit -m add -a &&
217 h_TEST=$(git rev-parse --verify HEAD)
218 echo The other day this did not work. >M &&
219 echo And then Bob told me how to fix it. >>M &&
221 GIT_AUTHOR_DATE="2005-05-26 23:41" \
222 GIT_COMMITTER_DATE="2005-05-26 23:41" git-commit -F M -a &&
223 h_OTHER=$(git rev-parse --verify HEAD) &&
224 GIT_AUTHOR_DATE="2005-05-26 23:44" \
225 GIT_COMMITTER_DATE="2005-05-26 23:44" git-commit --amend &&
226 h_FIXED=$(git rev-parse --verify HEAD) &&
227 echo Merged initial commit and a later commit. >M &&
228 echo $h_TEST >.git/MERGE_HEAD &&
229 GIT_AUTHOR_DATE="2005-05-26 23:45" \
230 GIT_COMMITTER_DATE="2005-05-26 23:45" git-commit -F M &&
231 h_MERGED=$(git rev-parse --verify HEAD) &&
235 $Z $h_TEST $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 commit (initial): add
236 $h_TEST $h_OTHER $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150860 +0000 commit: The other day this did not work.
237 $h_OTHER $h_FIXED $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117151040 +0000 commit (amend): The other day this did not work.
238 $h_FIXED $h_MERGED $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117151100 +0000 commit (merge): Merged initial commit and a later commit.
240 test_expect_success \
241 'git-commit logged updates' \
242 "diff expect .git/logs/$m"
243 unset h_TEST h_OTHER h_FIXED h_MERGED
245 test_expect_success \
246 'git cat-file blob master:F (expect OTHER)' \
247 'test OTHER = $(git cat-file blob master:F)'
248 test_expect_success \
249 'git cat-file blob master@{2005-05-26 23:30}:F (expect TEST)' \
250 'test TEST = $(git cat-file blob "master@{2005-05-26 23:30}:F")'
251 test_expect_success \
252 'git cat-file blob master@{2005-05-26 23:42}:F (expect OTHER)' \
253 'test OTHER = $(git cat-file blob "master@{2005-05-26 23:42}:F")'