stop t1400 hiding errors in tests
[git/git.git] / t / t1400-update-ref.sh
CommitLineData
6de08ae6
SP
1#!/bin/sh
2#
3# Copyright (c) 2006 Shawn Pearce
4#
5
5be60078 6test_description='Test git update-ref and basic ref logging'
6de08ae6
SP
7. ./test-lib.sh
8
9Z=0000000000000000000000000000000000000000
10A=1111111111111111111111111111111111111111
11B=2222222222222222222222222222222222222222
e5229042
SP
12C=3333333333333333333333333333333333333333
13D=4444444444444444444444444444444444444444
14E=5555555555555555555555555555555555555555
15F=6666666666666666666666666666666666666666
6de08ae6 16m=refs/heads/master
818f477c
SP
17n_dir=refs/heads/gu
18n=$n_dir/fixes
6de08ae6
SP
19
20test_expect_success \
21 "create $m" \
5be60078 22 "git update-ref $m $A &&
8aac4b45 23 test $A"' = $(cat .git/'"$m"')'
6de08ae6
SP
24test_expect_success \
25 "create $m" \
5be60078 26 "git update-ref $m $B $A &&
8aac4b45 27 test $B"' = $(cat .git/'"$m"')'
6de08ae6
SP
28rm -f .git/$m
29
818f477c
SP
30test_expect_success \
31 "fail to create $n" \
8aac4b45 32 "touch .git/$n_dir
5be60078 33 git update-ref $n $A >out 2>err"'
ef176ad0 34 test $? != 0'
818f477c
SP
35rm -f .git/$n_dir out err
36
6de08ae6
SP
37test_expect_success \
38 "create $m (by HEAD)" \
5be60078 39 "git update-ref HEAD $A &&
8aac4b45 40 test $A"' = $(cat .git/'"$m"')'
6de08ae6
SP
41test_expect_success \
42 "create $m (by HEAD)" \
5be60078 43 "git update-ref HEAD $B $A &&
8aac4b45 44 test $B"' = $(cat .git/'"$m"')'
6de08ae6
SP
45rm -f .git/$m
46
47test_expect_failure \
48 '(not) create HEAD with old sha1' \
5be60078 49 "git update-ref HEAD $A $B"
6de08ae6
SP
50test_expect_failure \
51 "(not) prior created .git/$m" \
8aac4b45 52 "test -f .git/$m"
6de08ae6
SP
53rm -f .git/$m
54
55test_expect_success \
56 "create HEAD" \
5be60078 57 "git update-ref HEAD $A"
6de08ae6
SP
58test_expect_failure \
59 '(not) change HEAD with wrong SHA1' \
5be60078 60 "git update-ref HEAD $B $Z"
6de08ae6
SP
61test_expect_failure \
62 "(not) changed .git/$m" \
8aac4b45 63 "test $B"' = $(cat .git/'"$m"')'
6de08ae6
SP
64rm -f .git/$m
65
0bee5918
SP
66: a repository with working tree always has reflog these days...
67: >.git/logs/refs/heads/master
6de08ae6
SP
68test_expect_success \
69 "create $m (logged by touch)" \
70 'GIT_COMMITTER_DATE="2005-05-26 23:30" \
5be60078 71 git update-ref HEAD '"$A"' -m "Initial Creation" &&
8aac4b45 72 test '"$A"' = $(cat .git/'"$m"')'
6de08ae6
SP
73test_expect_success \
74 "update $m (logged by touch)" \
75 'GIT_COMMITTER_DATE="2005-05-26 23:31" \
5be60078 76 git update-ref HEAD'" $B $A "'-m "Switch" &&
8aac4b45 77 test '"$B"' = $(cat .git/'"$m"')'
6de08ae6
SP
78test_expect_success \
79 "set $m (logged by touch)" \
80 'GIT_COMMITTER_DATE="2005-05-26 23:41" \
5be60078 81 git update-ref HEAD'" $A &&
8aac4b45 82 test $A"' = $(cat .git/'"$m"')'
6de08ae6
SP
83
84cat >expect <<EOF
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
88EOF
89test_expect_success \
90 "verifying $m's log" \
8aac4b45 91 "diff expect .git/logs/$m"
6de08ae6
SP
92rm -rf .git/$m .git/logs expect
93
94test_expect_success \
95 'enable core.logAllRefUpdates' \
5be60078
JH
96 'git config core.logAllRefUpdates true &&
97 test true = $(git config --bool --get core.logAllRefUpdates)'
6de08ae6
SP
98
99test_expect_success \
100 "create $m (logged by config)" \
101 'GIT_COMMITTER_DATE="2005-05-26 23:32" \
5be60078 102 git update-ref HEAD'" $A "'-m "Initial Creation" &&
8aac4b45 103 test '"$A"' = $(cat .git/'"$m"')'
6de08ae6
SP
104test_expect_success \
105 "update $m (logged by config)" \
106 'GIT_COMMITTER_DATE="2005-05-26 23:33" \
5be60078 107 git update-ref HEAD'" $B $A "'-m "Switch" &&
8aac4b45 108 test '"$B"' = $(cat .git/'"$m"')'
6de08ae6
SP
109test_expect_success \
110 "set $m (logged by config)" \
111 'GIT_COMMITTER_DATE="2005-05-26 23:43" \
5be60078 112 git update-ref HEAD '"$A &&
8aac4b45 113 test $A"' = $(cat .git/'"$m"')'
6de08ae6
SP
114
115cat >expect <<EOF
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
119EOF
120test_expect_success \
121 "verifying $m's log" \
122 'diff expect .git/logs/$m'
123rm -f .git/$m .git/logs/$m expect
124
5be60078 125git update-ref $m $D
e5229042
SP
126cat >.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
131EOF
132
133ed="Thu, 26 May 2005 18:32:00 -0500"
134gd="Thu, 26 May 2005 18:33:00 -0500"
135ld="Thu, 26 May 2005 18:43:00 -0500"
136test_expect_success \
cce91a2c 137 'Query "master@{May 25 2005}" (before history)' \
e5229042 138 'rm -f o e
5be60078 139 git rev-parse --verify "master@{May 25 2005}" >o 2>e &&
8aac4b45 140 test '"$C"' = $(cat o) &&
16d7cc90 141 test "warning: Log for '\'master\'' only goes back to $ed." = "$(cat e)"'
e5229042 142test_expect_success \
cce91a2c 143 "Query master@{2005-05-25} (before history)" \
e5229042 144 'rm -f o e
5be60078 145 git rev-parse --verify master@{2005-05-25} >o 2>e &&
8aac4b45 146 test '"$C"' = $(cat o) &&
16d7cc90 147 echo test "warning: Log for '\'master\'' only goes back to $ed." = "$(cat e)"'
e5229042 148test_expect_success \
cce91a2c 149 'Query "master@{May 26 2005 23:31:59}" (1 second before history)' \
e5229042 150 'rm -f o e
5be60078 151 git rev-parse --verify "master@{May 26 2005 23:31:59}" >o 2>e &&
8aac4b45 152 test '"$C"' = $(cat o) &&
16d7cc90 153 test "warning: Log for '\''master'\'' only goes back to $ed." = "$(cat e)"'
e5229042 154test_expect_success \
cce91a2c 155 'Query "master@{May 26 2005 23:32:00}" (exactly history start)' \
e5229042 156 'rm -f o e
5be60078 157 git rev-parse --verify "master@{May 26 2005 23:32:00}" >o 2>e &&
8aac4b45 158 test '"$A"' = $(cat o) &&
e5229042
SP
159 test "" = "$(cat e)"'
160test_expect_success \
cce91a2c 161 'Query "master@{2005-05-26 23:33:01}" (middle of history with gap)' \
e5229042 162 'rm -f o e
5be60078 163 git rev-parse --verify "master@{2005-05-26 23:33:01}" >o 2>e &&
8aac4b45
JH
164 test '"$B"' = $(cat o) &&
165 test "warning: Log .git/logs/'"$m has gap after $gd"'." = "$(cat e)"'
e5229042 166test_expect_success \
cce91a2c 167 'Query "master@{2005-05-26 23:38:00}" (middle of history)' \
e5229042 168 'rm -f o e
5be60078 169 git rev-parse --verify "master@{2005-05-26 23:38:00}" >o 2>e &&
8aac4b45 170 test '"$Z"' = $(cat o) &&
e5229042
SP
171 test "" = "$(cat e)"'
172test_expect_success \
cce91a2c 173 'Query "master@{2005-05-26 23:43:00}" (exact end of history)' \
e5229042 174 'rm -f o e
5be60078 175 git rev-parse --verify "master@{2005-05-26 23:43:00}" >o 2>e &&
8aac4b45 176 test '"$E"' = $(cat o) &&
e5229042
SP
177 test "" = "$(cat e)"'
178test_expect_success \
cce91a2c 179 'Query "master@{2005-05-28}" (past end of history)' \
e5229042 180 'rm -f o e
5be60078 181 git rev-parse --verify "master@{2005-05-28}" >o 2>e &&
8aac4b45
JH
182 test '"$D"' = $(cat o) &&
183 test "warning: Log .git/logs/'"$m unexpectedly ended on $ld"'." = "$(cat e)"'
e5229042 184
cce91a2c
SP
185
186rm -f .git/$m .git/logs/$m expect
187
188test_expect_success \
189 'creating initial files' \
9c7466fa 190 'echo TEST >F &&
5be60078 191 git add F &&
9c7466fa 192 GIT_AUTHOR_DATE="2005-05-26 23:30" \
cce91a2c 193 GIT_COMMITTER_DATE="2005-05-26 23:30" git-commit -m add -a &&
5be60078 194 h_TEST=$(git rev-parse --verify HEAD)
9c7466fa
SP
195 echo The other day this did not work. >M &&
196 echo And then Bob told me how to fix it. >>M &&
197 echo OTHER >F &&
198 GIT_AUTHOR_DATE="2005-05-26 23:41" \
199 GIT_COMMITTER_DATE="2005-05-26 23:41" git-commit -F M -a &&
5be60078 200 h_OTHER=$(git rev-parse --verify HEAD) &&
a3a733e6
SP
201 GIT_AUTHOR_DATE="2005-05-26 23:44" \
202 GIT_COMMITTER_DATE="2005-05-26 23:44" git-commit --amend &&
5be60078 203 h_FIXED=$(git rev-parse --verify HEAD) &&
a3a733e6
SP
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 &&
d9c8344b 208 h_MERGED=$(git rev-parse --verify HEAD) &&
9c7466fa
SP
209 rm -f M'
210
211cat >expect <<EOF
a3a733e6 212$Z $h_TEST $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 commit (initial): add
9c7466fa 213$h_TEST $h_OTHER $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150860 +0000 commit: The other day this did not work.
a3a733e6
SP
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.
9c7466fa
SP
216EOF
217test_expect_success \
218 'git-commit logged updates' \
8aac4b45 219 "diff expect .git/logs/$m"
a3a733e6 220unset h_TEST h_OTHER h_FIXED h_MERGED
cce91a2c
SP
221
222test_expect_success \
5be60078
JH
223 'git cat-file blob master:F (expect OTHER)' \
224 'test OTHER = $(git cat-file blob master:F)'
cce91a2c 225test_expect_success \
5be60078
JH
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")'
cce91a2c 228test_expect_success \
5be60078
JH
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")'
cce91a2c 231
6de08ae6 232test_done