3 # Copyright (c) 2006 Shawn Pearce
6 test_description='Test git update-ref and basic ref logging'
9 Z=0000000000000000000000000000000000000000
10 A=1111111111111111111111111111111111111111
11 B=2222222222222222222222222222222222222222
12 C=3333333333333333333333333333333333333333
13 D=4444444444444444444444444444444444444444
14 E=5555555555555555555555555555555555555555
15 F=6666666666666666666666666666666666666666
22 "git update-ref $m $A &&
23 test $A"' = $(cat .git/'"$m"')'
26 "git update-ref $m $B $A &&
27 test $B"' = $(cat .git/'"$m"')'
33 git update-ref $n $A >out 2>err"'
35 rm -f .git/$n_dir out err
38 "create $m (by HEAD)" \
39 "git update-ref HEAD $A &&
40 test $A"' = $(cat .git/'"$m"')'
42 "create $m (by HEAD)" \
43 "git update-ref HEAD $B $A &&
44 test $B"' = $(cat .git/'"$m"')'
48 '(not) create HEAD with old sha1' \
49 "git update-ref HEAD $A $B"
51 "(not) prior created .git/$m" \
57 "git update-ref HEAD $A"
59 '(not) change HEAD with wrong SHA1' \
60 "git update-ref HEAD $B $Z"
62 "(not) changed .git/$m" \
63 "test $B"' = $(cat .git/'"$m"')'
66 : a repository with working tree always has reflog these days...
67 : >.git/logs/refs/heads/master
69 "create $m (logged by touch)" \
70 'GIT_COMMITTER_DATE="2005-05-26 23:30" \
71 git update-ref HEAD '"$A"' -m "Initial Creation" &&
72 test '"$A"' = $(cat .git/'"$m"')'
74 "update $m (logged by touch)" \
75 'GIT_COMMITTER_DATE="2005-05-26 23:31" \
76 git update-ref HEAD'" $B $A "'-m "Switch" &&
77 test '"$B"' = $(cat .git/'"$m"')'
79 "set $m (logged by touch)" \
80 'GIT_COMMITTER_DATE="2005-05-26 23:41" \
81 git update-ref HEAD'" $A &&
82 test $A"' = $(cat .git/'"$m"')'
85 $Z $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 Initial Creation
86 $A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150260 +0000 Switch
87 $B $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150860 +0000
90 "verifying $m's log" \
91 "diff expect .git/logs/$m"
92 rm -rf .git/$m .git/logs expect
95 'enable core.logAllRefUpdates' \
96 'git config core.logAllRefUpdates true &&
97 test true = $(git config --bool --get core.logAllRefUpdates)'
100 "create $m (logged by config)" \
101 'GIT_COMMITTER_DATE="2005-05-26 23:32" \
102 git update-ref HEAD'" $A "'-m "Initial Creation" &&
103 test '"$A"' = $(cat .git/'"$m"')'
104 test_expect_success \
105 "update $m (logged by config)" \
106 'GIT_COMMITTER_DATE="2005-05-26 23:33" \
107 git update-ref HEAD'" $B $A "'-m "Switch" &&
108 test '"$B"' = $(cat .git/'"$m"')'
109 test_expect_success \
110 "set $m (logged by config)" \
111 'GIT_COMMITTER_DATE="2005-05-26 23:43" \
112 git update-ref HEAD '"$A &&
113 test $A"' = $(cat .git/'"$m"')'
116 $Z $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150320 +0000 Initial Creation
117 $A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150380 +0000 Switch
118 $B $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150980 +0000
120 test_expect_success \
121 "verifying $m's log" \
122 'diff expect .git/logs/$m'
123 rm -f .git/$m .git/logs/$m expect
126 cat >.git/logs/$m <<EOF
127 $C $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150320 -0500
128 $A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150380 -0500
129 $F $Z $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150680 -0500
130 $Z $E $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150980 -0500
133 ed="Thu, 26 May 2005 18:32:00 -0500"
134 gd="Thu, 26 May 2005 18:33:00 -0500"
135 ld="Thu, 26 May 2005 18:43:00 -0500"
136 test_expect_success \
137 'Query "master@{May 25 2005}" (before history)' \
139 git rev-parse --verify "master@{May 25 2005}" >o 2>e &&
140 test '"$C"' = $(cat o) &&
141 test "warning: Log for '\'master\'' only goes back to $ed." = "$(cat e)"'
142 test_expect_success \
143 "Query master@{2005-05-25} (before history)" \
145 git rev-parse --verify master@{2005-05-25} >o 2>e &&
146 test '"$C"' = $(cat o) &&
147 echo test "warning: Log for '\'master\'' only goes back to $ed." = "$(cat e)"'
148 test_expect_success \
149 'Query "master@{May 26 2005 23:31:59}" (1 second before history)' \
151 git rev-parse --verify "master@{May 26 2005 23:31:59}" >o 2>e &&
152 test '"$C"' = $(cat o) &&
153 test "warning: Log for '\''master'\'' only goes back to $ed." = "$(cat e)"'
154 test_expect_success \
155 'Query "master@{May 26 2005 23:32:00}" (exactly history start)' \
157 git rev-parse --verify "master@{May 26 2005 23:32:00}" >o 2>e &&
158 test '"$A"' = $(cat o) &&
159 test "" = "$(cat e)"'
160 test_expect_success \
161 'Query "master@{2005-05-26 23:33:01}" (middle of history with gap)' \
163 git rev-parse --verify "master@{2005-05-26 23:33:01}" >o 2>e &&
164 test '"$B"' = $(cat o) &&
165 test "warning: Log .git/logs/'"$m has gap after $gd"'." = "$(cat e)"'
166 test_expect_success \
167 'Query "master@{2005-05-26 23:38:00}" (middle of history)' \
169 git rev-parse --verify "master@{2005-05-26 23:38:00}" >o 2>e &&
170 test '"$Z"' = $(cat o) &&
171 test "" = "$(cat e)"'
172 test_expect_success \
173 'Query "master@{2005-05-26 23:43:00}" (exact end of history)' \
175 git rev-parse --verify "master@{2005-05-26 23:43:00}" >o 2>e &&
176 test '"$E"' = $(cat o) &&
177 test "" = "$(cat e)"'
178 test_expect_success \
179 'Query "master@{2005-05-28}" (past end of history)' \
181 git rev-parse --verify "master@{2005-05-28}" >o 2>e &&
182 test '"$D"' = $(cat o) &&
183 test "warning: Log .git/logs/'"$m unexpectedly ended on $ld"'." = "$(cat e)"'
186 rm -f .git/$m .git/logs/$m expect
188 test_expect_success \
189 'creating initial files' \
192 GIT_AUTHOR_DATE="2005-05-26 23:30" \
193 GIT_COMMITTER_DATE="2005-05-26 23:30" git-commit -m add -a &&
194 h_TEST=$(git rev-parse --verify HEAD)
195 echo The other day this did not work. >M &&
196 echo And then Bob told me how to fix it. >>M &&
198 GIT_AUTHOR_DATE="2005-05-26 23:41" \
199 GIT_COMMITTER_DATE="2005-05-26 23:41" git-commit -F M -a &&
200 h_OTHER=$(git rev-parse --verify HEAD) &&
201 GIT_AUTHOR_DATE="2005-05-26 23:44" \
202 GIT_COMMITTER_DATE="2005-05-26 23:44" git-commit --amend &&
203 h_FIXED=$(git rev-parse --verify HEAD) &&
204 echo Merged initial commit and a later commit. >M &&
205 echo $h_TEST >.git/MERGE_HEAD &&
206 GIT_AUTHOR_DATE="2005-05-26 23:45" \
207 GIT_COMMITTER_DATE="2005-05-26 23:45" git-commit -F M &&
208 h_MERGED=$(git rev-parse --verify HEAD) &&
212 $Z $h_TEST $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 commit (initial): add
213 $h_TEST $h_OTHER $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150860 +0000 commit: The other day this did not work.
214 $h_OTHER $h_FIXED $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117151040 +0000 commit (amend): The other day this did not work.
215 $h_FIXED $h_MERGED $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117151100 +0000 commit (merge): Merged initial commit and a later commit.
217 test_expect_success \
218 'git-commit logged updates' \
219 "diff expect .git/logs/$m"
220 unset h_TEST h_OTHER h_FIXED h_MERGED
222 test_expect_success \
223 'git cat-file blob master:F (expect OTHER)' \
224 'test OTHER = $(git cat-file blob master:F)'
225 test_expect_success \
226 'git cat-file blob master@{2005-05-26 23:30}:F (expect TEST)' \
227 'test TEST = $(git cat-file blob "master@{2005-05-26 23:30}:F")'
228 test_expect_success \
229 'git cat-file blob master@{2005-05-26 23:42}:F (expect OTHER)' \
230 'test OTHER = $(git cat-file blob "master@{2005-05-26 23:42}:F")'