revert: actually check for a dirty index
[alt-git.git] / t / t1400-update-ref.sh
blob71ab2dd0eedd5fa79300fe84fbd168b538dfd36c
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 rm -f .git/$m
37 test_expect_success \
38 "fail to create $n" \
39 "touch .git/$n_dir
40 git update-ref $n $A >out 2>err"'
41 test $? != 0'
42 rm -f .git/$n_dir out err
44 test_expect_success \
45 "create $m (by HEAD)" \
46 "git update-ref HEAD $A &&
47 test $A"' = $(cat .git/'"$m"')'
48 test_expect_success \
49 "create $m (by HEAD)" \
50 "git update-ref HEAD $B $A &&
51 test $B"' = $(cat .git/'"$m"')'
52 rm -f .git/$m
54 test_expect_failure \
55 '(not) create HEAD with old sha1' \
56 "git update-ref HEAD $A $B"
57 test_expect_failure \
58 "(not) prior created .git/$m" \
59 "test -f .git/$m"
60 rm -f .git/$m
62 test_expect_success \
63 "create HEAD" \
64 "git update-ref HEAD $A"
65 test_expect_failure \
66 '(not) change HEAD with wrong SHA1' \
67 "git update-ref HEAD $B $Z"
68 test_expect_failure \
69 "(not) changed .git/$m" \
70 "test $B"' = $(cat .git/'"$m"')'
71 rm -f .git/$m
73 : a repository with working tree always has reflog these days...
74 : >.git/logs/refs/heads/master
75 test_expect_success \
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"')'
80 test_expect_success \
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"')'
85 test_expect_success \
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"')'
91 cat >expect <<EOF
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
95 EOF
96 test_expect_success \
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"')'
122 cat >expect <<EOF
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
132 git update-ref $m $D
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)' \
145 'rm -f o e
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)" \
151 'rm -f o e
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)' \
157 'rm -f o e
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)' \
163 'rm -f o e
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)' \
169 'rm -f o e
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)' \
175 'rm -f o e
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)' \
181 'rm -f o e
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)' \
187 'rm -f o e
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' \
197 'echo TEST >F &&
198 git add F &&
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 &&
204 echo OTHER >F &&
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) &&
216 rm -f M'
218 cat >expect <<EOF
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")'
239 test_done