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
20 'git-update-ref $m $A &&
21 test $A = $(cat .git/$m)'
24 'git-update-ref $m $B $A &&
25 test $B = $(cat .git/$m)'
29 "create $m (by HEAD)" \
30 'git-update-ref HEAD $A &&
31 test $A = $(cat .git/$m)'
33 "create $m (by HEAD)" \
34 'git-update-ref HEAD $B $A &&
35 test $B = $(cat .git/$m)'
39 '(not) create HEAD with old sha1' \
40 'git-update-ref HEAD $A $B'
42 "(not) prior created .git/$m" \
48 'git-update-ref HEAD $A'
50 '(not) change HEAD with wrong SHA1' \
51 'git-update-ref HEAD $B $Z'
53 "(not) changed .git/$m" \
54 'test $B = $(cat .git/$m)'
57 mkdir -p .git/logs/refs/heads
58 touch .git/logs/refs/heads/master
60 "create $m (logged by touch)" \
61 'GIT_COMMITTER_DATE="2005-05-26 23:30" \
62 git-update-ref HEAD $A -m "Initial Creation" &&
63 test $A = $(cat .git/$m)'
65 "update $m (logged by touch)" \
66 'GIT_COMMITTER_DATE="2005-05-26 23:31" \
67 git-update-ref HEAD $B $A -m "Switch" &&
68 test $B = $(cat .git/$m)'
70 "set $m (logged by touch)" \
71 'GIT_COMMITTER_DATE="2005-05-26 23:41" \
72 git-update-ref HEAD $A &&
73 test $A = $(cat .git/$m)'
76 $Z $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 Initial Creation
77 $A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150260 +0000 Switch
78 $B $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150860 +0000
81 "verifying $m's log" \
82 'diff expect .git/logs/$m'
83 rm -rf .git/$m .git/logs expect
86 'enable core.logAllRefUpdates' \
87 'git-repo-config core.logAllRefUpdates true &&
88 test true = $(git-repo-config --bool --get core.logAllRefUpdates)'
91 "create $m (logged by config)" \
92 'GIT_COMMITTER_DATE="2005-05-26 23:32" \
93 git-update-ref HEAD $A -m "Initial Creation" &&
94 test $A = $(cat .git/$m)'
96 "update $m (logged by config)" \
97 'GIT_COMMITTER_DATE="2005-05-26 23:33" \
98 git-update-ref HEAD $B $A -m "Switch" &&
99 test $B = $(cat .git/$m)'
100 test_expect_success \
101 "set $m (logged by config)" \
102 'GIT_COMMITTER_DATE="2005-05-26 23:43" \
103 git-update-ref HEAD $A &&
104 test $A = $(cat .git/$m)'
107 $Z $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150320 +0000 Initial Creation
108 $A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150380 +0000 Switch
109 $B $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150980 +0000
111 test_expect_success \
112 "verifying $m's log" \
113 'diff expect .git/logs/$m'
114 rm -f .git/$m .git/logs/$m expect
117 cat >.git/logs/$m <<EOF
118 $C $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150320 -0500
119 $A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150380 -0500
120 $F $Z $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150680 -0500
121 $Z $E $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150980 -0500
124 ed="Thu, 26 May 2005 18:32:00 -0500"
125 gd="Thu, 26 May 2005 18:33:00 -0500"
126 ld="Thu, 26 May 2005 18:43:00 -0500"
127 test_expect_success \
128 'Query "master@{May 25 2005}" (before history)' \
130 git-rev-parse --verify "master@{May 25 2005}" >o 2>e &&
131 test $C = $(cat o) &&
132 test "warning: Log .git/logs/$m only goes back to $ed." = "$(cat e)"'
133 test_expect_success \
134 "Query master@{2005-05-25} (before history)" \
136 git-rev-parse --verify master@{2005-05-25} >o 2>e &&
137 test $C = $(cat o) &&
138 echo test "warning: Log .git/logs/$m only goes back to $ed." = "$(cat e)"'
139 test_expect_success \
140 'Query "master@{May 26 2005 23:31:59}" (1 second before history)' \
142 git-rev-parse --verify "master@{May 26 2005 23:31:59}" >o 2>e &&
143 test $C = $(cat o) &&
144 test "warning: Log .git/logs/$m only goes back to $ed." = "$(cat e)"'
145 test_expect_success \
146 'Query "master@{May 26 2005 23:32:00}" (exactly history start)' \
148 git-rev-parse --verify "master@{May 26 2005 23:32:00}" >o 2>e &&
149 test $A = $(cat o) &&
150 test "" = "$(cat e)"'
151 test_expect_success \
152 'Query "master@{2005-05-26 23:33:01}" (middle of history with gap)' \
154 git-rev-parse --verify "master@{2005-05-26 23:33:01}" >o 2>e &&
155 test $B = $(cat o) &&
156 test "warning: Log .git/logs/$m has gap after $gd." = "$(cat e)"'
157 test_expect_success \
158 'Query "master@{2005-05-26 23:38:00}" (middle of history)' \
160 git-rev-parse --verify "master@{2005-05-26 23:38:00}" >o 2>e &&
161 test $Z = $(cat o) &&
162 test "" = "$(cat e)"'
163 test_expect_success \
164 'Query "master@{2005-05-26 23:43:00}" (exact end of history)' \
166 git-rev-parse --verify "master@{2005-05-26 23:43:00}" >o 2>e &&
167 test $E = $(cat o) &&
168 test "" = "$(cat e)"'
169 test_expect_success \
170 'Query "master@{2005-05-28}" (past end of history)' \
172 git-rev-parse --verify "master@{2005-05-28}" >o 2>e &&
173 test $D = $(cat o) &&
174 test "warning: Log .git/logs/$m unexpectedly ended on $ld." = "$(cat e)"'
177 rm -f .git/$m .git/logs/$m expect
179 test_expect_success \
180 'creating initial files' \
181 'cp ../../COPYING COPYING &&
183 GIT_COMMITTER_DATE="2005-05-26 23:30" git-commit -m add -a &&
184 cp ../../Makefile COPYING &&
185 GIT_COMMITTER_DATE="2005-05-26 23:41" git-commit -m change -a'
187 test_expect_success \
188 'git-cat-file blob master:COPYING (expect Makefile)' \
189 'git-cat-file blob master:COPYING | diff - ../../Makefile'
190 test_expect_success \
191 'git-cat-file blob master@{2005-05-26 23:30}:COPYING (expect COPYING)' \
192 'git-cat-file blob "master@{2005-05-26 23:30}:COPYING" \
193 | diff - ../../COPYING'
194 test_expect_success \
195 'git-cat-file blob master@{2005-05-26 23:42}:COPYING (expect Makefile)' \
196 'git-cat-file blob "master@{2005-05-26 23:42}:COPYING" \
197 | diff - ../../Makefile'