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"')'
40 git update-ref $n $A >out 2>err"'
42 rm -f .git
/$n_dir out err
45 "create $m (by HEAD)" \
46 "git update-ref HEAD $A &&
47 test $A"' = $(cat .git/'"$m"')'
49 "create $m (by HEAD)" \
50 "git update-ref HEAD $B $A &&
51 test $B"' = $(cat .git/'"$m"')'
55 '(not) create HEAD with old sha1' \
56 "git update-ref HEAD $A $B"
58 "(not) prior created .git/$m" \
64 "git update-ref HEAD $A"
66 '(not) change HEAD with wrong SHA1' \
67 "git update-ref HEAD $B $Z"
69 "(not) changed .git/$m" \
70 "test $B"' = $(cat .git/'"$m"')'
73 : a repository with working tree always has reflog these days...
74 : >.git
/logs
/refs
/heads
/master
76 "create $m (logged by touch)" \
77 'GIT_COMMITTER_DATE="2005-05-26 23:30" \
78 git update-ref HEAD '"$A"' -m "Initial Creation" &&
79 test '"$A"' = $(cat .git/'"$m"')'
81 "update $m (logged by touch)" \
82 'GIT_COMMITTER_DATE="2005-05-26 23:31" \
83 git update-ref HEAD'" $B $A "'-m "Switch" &&
84 test '"$B"' = $(cat .git/'"$m"')'
86 "set $m (logged by touch)" \
87 'GIT_COMMITTER_DATE="2005-05-26 23:41" \
88 git update-ref HEAD'" $A &&
89 test $A"' = $(cat .git/'"$m"')'
92 $Z $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 Initial Creation
93 $A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150260 +0000 Switch
94 $B $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150860 +0000
97 "verifying $m's log" \
98 "diff expect .git/logs/$m"
99 rm -rf .git
/$m .git
/logs expect
101 test_expect_success \
102 'enable core.logAllRefUpdates' \
103 'git config core.logAllRefUpdates true &&
104 test true = $(git config --bool --get core.logAllRefUpdates)'
106 test_expect_success \
107 "create $m (logged by config)" \
108 'GIT_COMMITTER_DATE="2005-05-26 23:32" \
109 git update-ref HEAD'" $A "'-m "Initial Creation" &&
110 test '"$A"' = $(cat .git/'"$m"')'
111 test_expect_success \
112 "update $m (logged by config)" \
113 'GIT_COMMITTER_DATE="2005-05-26 23:33" \
114 git update-ref HEAD'" $B $A "'-m "Switch" &&
115 test '"$B"' = $(cat .git/'"$m"')'
116 test_expect_success \
117 "set $m (logged by config)" \
118 'GIT_COMMITTER_DATE="2005-05-26 23:43" \
119 git update-ref HEAD '"$A &&
120 test $A"' = $(cat .git/'"$m"')'
123 $Z $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150320 +0000 Initial Creation
124 $A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150380 +0000 Switch
125 $B $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150980 +0000
127 test_expect_success \
128 "verifying $m's log" \
129 'diff expect .git/logs/$m'
130 rm -f .git
/$m .git
/logs
/$m expect
133 cat >.git
/logs
/$m <<EOF
134 $C $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150320 -0500
135 $A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150380 -0500
136 $F $Z $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150680 -0500
137 $Z $E $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150980 -0500
140 ed
="Thu, 26 May 2005 18:32:00 -0500"
141 gd
="Thu, 26 May 2005 18:33:00 -0500"
142 ld
="Thu, 26 May 2005 18:43:00 -0500"
143 test_expect_success \
144 'Query "master@{May 25 2005}" (before history)' \
146 git rev-parse --verify "master@{May 25 2005}" >o 2>e &&
147 test '"$C"' = $(cat o) &&
148 test "warning: Log for '\'master
\'' only goes back to $ed." = "$(cat e)"'
149 test_expect_success \
150 "Query master@{2005-05-25} (before history)" \
152 git rev-parse --verify master@{2005-05-25} >o 2>e &&
153 test '"$C"' = $(cat o) &&
154 echo test "warning: Log for '\'master
\'' only goes back to $ed." = "$(cat e)"'
155 test_expect_success \
156 'Query "master@{May 26 2005 23:31:59}" (1 second before history)' \
158 git rev-parse --verify "master@{May 26 2005 23:31:59}" >o 2>e &&
159 test '"$C"' = $(cat o) &&
160 test "warning: Log for '\''master'\'' only goes back to $ed." = "$(cat e)"'
161 test_expect_success \
162 'Query "master@{May 26 2005 23:32:00}" (exactly history start)' \
164 git rev-parse --verify "master@{May 26 2005 23:32:00}" >o 2>e &&
165 test '"$A"' = $(cat o) &&
166 test "" = "$(cat e)"'
167 test_expect_success \
168 'Query "master@{2005-05-26 23:33:01}" (middle of history with gap)' \
170 git rev-parse --verify "master@{2005-05-26 23:33:01}" >o 2>e &&
171 test '"$B"' = $(cat o) &&
172 test "warning: Log .git/logs/'"$m has gap after $gd"'." = "$(cat e)"'
173 test_expect_success \
174 'Query "master@{2005-05-26 23:38:00}" (middle of history)' \
176 git rev-parse --verify "master@{2005-05-26 23:38:00}" >o 2>e &&
177 test '"$Z"' = $(cat o) &&
178 test "" = "$(cat e)"'
179 test_expect_success \
180 'Query "master@{2005-05-26 23:43:00}" (exact end of history)' \
182 git rev-parse --verify "master@{2005-05-26 23:43:00}" >o 2>e &&
183 test '"$E"' = $(cat o) &&
184 test "" = "$(cat e)"'
185 test_expect_success \
186 'Query "master@{2005-05-28}" (past end of history)' \
188 git rev-parse --verify "master@{2005-05-28}" >o 2>e &&
189 test '"$D"' = $(cat o) &&
190 test "warning: Log .git/logs/'"$m unexpectedly ended on $ld"'." = "$(cat e)"'
193 rm -f .git
/$m .git
/logs
/$m expect
195 test_expect_success \
196 'creating initial files' \
199 GIT_AUTHOR_DATE="2005-05-26 23:30" \
200 GIT_COMMITTER_DATE="2005-05-26 23:30" git-commit -m add -a &&
201 h_TEST=$(git rev-parse --verify HEAD)
202 echo The other day this did not work. >M &&
203 echo And then Bob told me how to fix it. >>M &&
205 GIT_AUTHOR_DATE="2005-05-26 23:41" \
206 GIT_COMMITTER_DATE="2005-05-26 23:41" git-commit -F M -a &&
207 h_OTHER=$(git rev-parse --verify HEAD) &&
208 GIT_AUTHOR_DATE="2005-05-26 23:44" \
209 GIT_COMMITTER_DATE="2005-05-26 23:44" git-commit --amend &&
210 h_FIXED=$(git rev-parse --verify HEAD) &&
211 echo Merged initial commit and a later commit. >M &&
212 echo $h_TEST >.git/MERGE_HEAD &&
213 GIT_AUTHOR_DATE="2005-05-26 23:45" \
214 GIT_COMMITTER_DATE="2005-05-26 23:45" git-commit -F M &&
215 h_MERGED=$(git rev-parse --verify HEAD) &&
219 $Z $h_TEST $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 commit (initial): add
220 $h_TEST $h_OTHER $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150860 +0000 commit: The other day this did not work.
221 $h_OTHER $h_FIXED $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117151040 +0000 commit (amend): The other day this did not work.
222 $h_FIXED $h_MERGED $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117151100 +0000 commit (merge): Merged initial commit and a later commit.
224 test_expect_success \
225 'git-commit logged updates' \
226 "diff expect .git/logs/$m"
227 unset h_TEST h_OTHER h_FIXED h_MERGED
229 test_expect_success \
230 'git cat-file blob master:F (expect OTHER)' \
231 'test OTHER = $(git cat-file blob master:F)'
232 test_expect_success \
233 'git cat-file blob master@{2005-05-26 23:30}:F (expect TEST)' \
234 'test TEST = $(git cat-file blob "master@{2005-05-26 23:30}:F")'
235 test_expect_success \
236 'git cat-file blob master@{2005-05-26 23:42}:F (expect OTHER)' \
237 'test OTHER = $(git cat-file blob "master@{2005-05-26 23:42}:F")'