Display an error from update-ref if target ref name is invalid.
[git/jnareb-git.git] / t / t1400-update-ref.sh
blobddc80bbeae7703b8c4a2ddcf12d8b1ec9c6bbe46
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
10 A=1111111111111111111111111111111111111111
11 B=2222222222222222222222222222222222222222
12 C=3333333333333333333333333333333333333333
13 D=4444444444444444444444444444444444444444
14 E=5555555555555555555555555555555555555555
15 F=6666666666666666666666666666666666666666
16 m=refs/heads/master
17 n_dir=refs/heads/gu
18 n=$n_dir/fixes
20 test_expect_success \
21 "create $m" \
22 'git-update-ref $m $A &&
23 test $A = $(cat .git/$m)'
24 test_expect_success \
25 "create $m" \
26 'git-update-ref $m $B $A &&
27 test $B = $(cat .git/$m)'
28 rm -f .git/$m
30 test_expect_success \
31 "fail to create $n" \
32 'touch .git/$n_dir
33 git-update-ref $n $A >out 2>err
34 test $? = 1 &&
35 test "" = "$(cat out)" &&
36 grep "error: unable to resolve reference" err &&
37 grep $n err'
38 rm -f .git/$n_dir out err
40 test_expect_success \
41 "create $m (by HEAD)" \
42 'git-update-ref HEAD $A &&
43 test $A = $(cat .git/$m)'
44 test_expect_success \
45 "create $m (by HEAD)" \
46 'git-update-ref HEAD $B $A &&
47 test $B = $(cat .git/$m)'
48 rm -f .git/$m
50 test_expect_failure \
51 '(not) create HEAD with old sha1' \
52 'git-update-ref HEAD $A $B'
53 test_expect_failure \
54 "(not) prior created .git/$m" \
55 'test -f .git/$m'
56 rm -f .git/$m
58 test_expect_success \
59 "create HEAD" \
60 'git-update-ref HEAD $A'
61 test_expect_failure \
62 '(not) change HEAD with wrong SHA1' \
63 'git-update-ref HEAD $B $Z'
64 test_expect_failure \
65 "(not) changed .git/$m" \
66 'test $B = $(cat .git/$m)'
67 rm -f .git/$m
69 mkdir -p .git/logs/refs/heads
70 touch .git/logs/refs/heads/master
71 test_expect_success \
72 "create $m (logged by touch)" \
73 'GIT_COMMITTER_DATE="2005-05-26 23:30" \
74 git-update-ref HEAD $A -m "Initial Creation" &&
75 test $A = $(cat .git/$m)'
76 test_expect_success \
77 "update $m (logged by touch)" \
78 'GIT_COMMITTER_DATE="2005-05-26 23:31" \
79 git-update-ref HEAD $B $A -m "Switch" &&
80 test $B = $(cat .git/$m)'
81 test_expect_success \
82 "set $m (logged by touch)" \
83 'GIT_COMMITTER_DATE="2005-05-26 23:41" \
84 git-update-ref HEAD $A &&
85 test $A = $(cat .git/$m)'
87 cat >expect <<EOF
88 $Z $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 Initial Creation
89 $A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150260 +0000 Switch
90 $B $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150860 +0000
91 EOF
92 test_expect_success \
93 "verifying $m's log" \
94 'diff expect .git/logs/$m'
95 rm -rf .git/$m .git/logs expect
97 test_expect_success \
98 'enable core.logAllRefUpdates' \
99 'git-repo-config core.logAllRefUpdates true &&
100 test true = $(git-repo-config --bool --get core.logAllRefUpdates)'
102 test_expect_success \
103 "create $m (logged by config)" \
104 'GIT_COMMITTER_DATE="2005-05-26 23:32" \
105 git-update-ref HEAD $A -m "Initial Creation" &&
106 test $A = $(cat .git/$m)'
107 test_expect_success \
108 "update $m (logged by config)" \
109 'GIT_COMMITTER_DATE="2005-05-26 23:33" \
110 git-update-ref HEAD $B $A -m "Switch" &&
111 test $B = $(cat .git/$m)'
112 test_expect_success \
113 "set $m (logged by config)" \
114 'GIT_COMMITTER_DATE="2005-05-26 23:43" \
115 git-update-ref HEAD $A &&
116 test $A = $(cat .git/$m)'
118 cat >expect <<EOF
119 $Z $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150320 +0000 Initial Creation
120 $A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150380 +0000 Switch
121 $B $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150980 +0000
123 test_expect_success \
124 "verifying $m's log" \
125 'diff expect .git/logs/$m'
126 rm -f .git/$m .git/logs/$m expect
128 git-update-ref $m $D
129 cat >.git/logs/$m <<EOF
130 $C $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150320 -0500
131 $A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150380 -0500
132 $F $Z $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150680 -0500
133 $Z $E $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150980 -0500
136 ed="Thu, 26 May 2005 18:32:00 -0500"
137 gd="Thu, 26 May 2005 18:33:00 -0500"
138 ld="Thu, 26 May 2005 18:43:00 -0500"
139 test_expect_success \
140 'Query "master@{May 25 2005}" (before history)' \
141 'rm -f o e
142 git-rev-parse --verify "master@{May 25 2005}" >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@{2005-05-25} (before history)" \
147 'rm -f o e
148 git-rev-parse --verify master@{2005-05-25} >o 2>e &&
149 test $C = $(cat o) &&
150 echo test "warning: Log .git/logs/$m only goes back to $ed." = "$(cat e)"'
151 test_expect_success \
152 'Query "master@{May 26 2005 23:31:59}" (1 second before history)' \
153 'rm -f o e
154 git-rev-parse --verify "master@{May 26 2005 23:31:59}" >o 2>e &&
155 test $C = $(cat o) &&
156 test "warning: Log .git/logs/$m only goes back to $ed." = "$(cat e)"'
157 test_expect_success \
158 'Query "master@{May 26 2005 23:32:00}" (exactly history start)' \
159 'rm -f o e
160 git-rev-parse --verify "master@{May 26 2005 23:32:00}" >o 2>e &&
161 test $A = $(cat o) &&
162 test "" = "$(cat e)"'
163 test_expect_success \
164 'Query "master@{2005-05-26 23:33:01}" (middle of history with gap)' \
165 'rm -f o e
166 git-rev-parse --verify "master@{2005-05-26 23:33:01}" >o 2>e &&
167 test $B = $(cat o) &&
168 test "warning: Log .git/logs/$m has gap after $gd." = "$(cat e)"'
169 test_expect_success \
170 'Query "master@{2005-05-26 23:38:00}" (middle of history)' \
171 'rm -f o e
172 git-rev-parse --verify "master@{2005-05-26 23:38:00}" >o 2>e &&
173 test $Z = $(cat o) &&
174 test "" = "$(cat e)"'
175 test_expect_success \
176 'Query "master@{2005-05-26 23:43:00}" (exact end of history)' \
177 'rm -f o e
178 git-rev-parse --verify "master@{2005-05-26 23:43:00}" >o 2>e &&
179 test $E = $(cat o) &&
180 test "" = "$(cat e)"'
181 test_expect_success \
182 'Query "master@{2005-05-28}" (past end of history)' \
183 'rm -f o e
184 git-rev-parse --verify "master@{2005-05-28}" >o 2>e &&
185 test $D = $(cat o) &&
186 test "warning: Log .git/logs/$m unexpectedly ended on $ld." = "$(cat e)"'
189 rm -f .git/$m .git/logs/$m expect
191 test_expect_success \
192 'creating initial files' \
193 'echo TEST >F &&
194 git-add F &&
195 GIT_AUTHOR_DATE="2005-05-26 23:30" \
196 GIT_COMMITTER_DATE="2005-05-26 23:30" git-commit -m add -a &&
197 h_TEST=$(git-rev-parse --verify HEAD)
198 echo The other day this did not work. >M &&
199 echo And then Bob told me how to fix it. >>M &&
200 echo OTHER >F &&
201 GIT_AUTHOR_DATE="2005-05-26 23:41" \
202 GIT_COMMITTER_DATE="2005-05-26 23:41" git-commit -F M -a &&
203 h_OTHER=$(git-rev-parse --verify HEAD) &&
204 echo FIXED >F &&
205 GIT_AUTHOR_DATE="2005-05-26 23:44" \
206 GIT_COMMITTER_DATE="2005-05-26 23:44" git-commit --amend &&
207 h_FIXED=$(git-rev-parse --verify HEAD) &&
208 echo TEST+FIXED >F &&
209 echo Merged initial commit and a later commit. >M &&
210 echo $h_TEST >.git/MERGE_HEAD &&
211 GIT_AUTHOR_DATE="2005-05-26 23:45" \
212 GIT_COMMITTER_DATE="2005-05-26 23:45" git-commit -F M &&
213 h_MERGED=$(git-rev-parse --verify HEAD)
214 rm -f M'
216 cat >expect <<EOF
217 $Z $h_TEST $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 commit (initial): add
218 $h_TEST $h_OTHER $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150860 +0000 commit: The other day this did not work.
219 $h_OTHER $h_FIXED $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117151040 +0000 commit (amend): The other day this did not work.
220 $h_FIXED $h_MERGED $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117151100 +0000 commit (merge): Merged initial commit and a later commit.
222 test_expect_success \
223 'git-commit logged updates' \
224 'diff expect .git/logs/$m'
225 unset h_TEST h_OTHER h_FIXED h_MERGED
227 test_expect_success \
228 'git-cat-file blob master:F (expect OTHER)' \
229 'test OTHER = $(git-cat-file blob master:F)'
230 test_expect_success \
231 'git-cat-file blob master@{2005-05-26 23:30}:F (expect TEST)' \
232 'test TEST = $(git-cat-file blob "master@{2005-05-26 23:30}:F")'
233 test_expect_success \
234 'git-cat-file blob master@{2005-05-26 23:42}:F (expect OTHER)' \
235 'test OTHER = $(git-cat-file blob "master@{2005-05-26 23:42}:F")'
237 test_done