Split up default "core" config parsing into helper routine
[git/dscho.git] / t / t1400-update-ref.sh
blobb8b7ab410354b01584092802365f4b53cd991b4a
1 #!/bin/sh
3 # Copyright (c) 2006 Shawn Pearce
6 test_description='Test git update-ref and basic ref logging'
7 . ./test-lib.sh
9 Z=0000000000000000000000000000000000000000
11 test_expect_success setup '
13 for name in A B C D E F
15 test_tick &&
16 T=$(git write-tree) &&
17 sha1=$(echo $name | git commit-tree $T) &&
18 eval $name=$sha1
19 done
23 m=refs/heads/master
24 n_dir=refs/heads/gu
25 n=$n_dir/fixes
27 test_expect_success \
28 "create $m" \
29 "git update-ref $m $A &&
30 test $A"' = $(cat .git/'"$m"')'
31 test_expect_success \
32 "create $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 &&
41 ! test -f .git/$m
43 rm -f .git/$m
45 test_expect_success \
46 "fail to create $n" \
47 "touch .git/$n_dir
48 git update-ref $n $A >out 2>err"'
49 test $? != 0'
50 rm -f .git/$n_dir out err
52 test_expect_success \
53 "create $m (by HEAD)" \
54 "git update-ref HEAD $A &&
55 test $A"' = $(cat .git/'"$m"')'
56 test_expect_success \
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 &&
66 ! test -f .git/$m
68 rm -f .git/$m
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" "
74 ! test -f .git/$m
76 rm -f .git/$m
78 test_expect_success \
79 "create HEAD" \
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"')
87 rm -f .git/$m
89 : a repository with working tree always has reflog these days...
90 : >.git/logs/refs/heads/master
91 test_expect_success \
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"')'
96 test_expect_success \
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"')'
107 cat >expect <<EOF
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"')'
138 cat >expect <<EOF
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
148 git update-ref $m $D
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)' \
161 'rm -f o e
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)" \
167 'rm -f o e
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)' \
173 'rm -f o e
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)' \
179 'rm -f o e
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)' \
185 'rm -f o e
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)' \
191 'rm -f o e
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)' \
197 'rm -f o e
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)' \
203 'rm -f o e
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' \
213 'echo TEST >F &&
214 git add F &&
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 &&
220 echo OTHER >F &&
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) &&
232 rm -f M'
234 cat >expect <<EOF
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")'
255 test_done