Documentation: fix broken "linkgit" links
[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
c3b0dec5
LT
10
11test_expect_success setup '
12
13 for name in A B C D E F
14 do
15 test_tick &&
16 T=$(git write-tree) &&
17 sha1=$(echo $name | git commit-tree $T) &&
18 eval $name=$sha1
19 done
20
21'
22
6de08ae6 23m=refs/heads/master
818f477c
SP
24n_dir=refs/heads/gu
25n=$n_dir/fixes
6de08ae6
SP
26
27test_expect_success \
28 "create $m" \
5be60078 29 "git update-ref $m $A &&
8aac4b45 30 test $A"' = $(cat .git/'"$m"')'
6de08ae6
SP
31test_expect_success \
32 "create $m" \
5be60078 33 "git update-ref $m $B $A &&
8aac4b45 34 test $B"' = $(cat .git/'"$m"')'
40672a19
KW
35test_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)"
38'
39test_expect_success "delete $m" '
40 git update-ref -d $m $B &&
41 ! test -f .git/$m
42'
6de08ae6
SP
43rm -f .git/$m
44
3fe8dce6
KW
45test_expect_success "delete $m without oldvalue verification" "
46 git update-ref $m $A &&
47 test $A = \$(cat .git/$m) &&
48 git update-ref -d $m &&
49 ! test -f .git/$m
50"
51rm -f .git/$m
52
818f477c
SP
53test_expect_success \
54 "fail to create $n" \
8aac4b45 55 "touch .git/$n_dir
5be60078 56 git update-ref $n $A >out 2>err"'
ef176ad0 57 test $? != 0'
818f477c
SP
58rm -f .git/$n_dir out err
59
6de08ae6
SP
60test_expect_success \
61 "create $m (by HEAD)" \
5be60078 62 "git update-ref HEAD $A &&
8aac4b45 63 test $A"' = $(cat .git/'"$m"')'
6de08ae6
SP
64test_expect_success \
65 "create $m (by HEAD)" \
5be60078 66 "git update-ref HEAD $B $A &&
8aac4b45 67 test $B"' = $(cat .git/'"$m"')'
40672a19
KW
68test_expect_success "fail to delete $m (by HEAD) with stale ref" '
69 test_must_fail git update-ref -d HEAD $A &&
70 test $B = $(cat .git/$m)
71'
72test_expect_success "delete $m (by HEAD)" '
73 git update-ref -d HEAD $B &&
74 ! test -f .git/$m
75'
6de08ae6
SP
76rm -f .git/$m
77
41ac414e
JH
78test_expect_success '(not) create HEAD with old sha1' "
79 ! git update-ref HEAD $A $B
80"
81test_expect_success "(not) prior created .git/$m" "
82 ! test -f .git/$m
83"
6de08ae6
SP
84rm -f .git/$m
85
86test_expect_success \
87 "create HEAD" \
5be60078 88 "git update-ref HEAD $A"
41ac414e
JH
89test_expect_success '(not) change HEAD with wrong SHA1' "
90 ! git update-ref HEAD $B $Z
91"
92test_expect_success "(not) changed .git/$m" "
93 ! test $B"' = $(cat .git/'"$m"')
94'
6de08ae6
SP
95rm -f .git/$m
96
0bee5918
SP
97: a repository with working tree always has reflog these days...
98: >.git/logs/refs/heads/master
6de08ae6
SP
99test_expect_success \
100 "create $m (logged by touch)" \
101 'GIT_COMMITTER_DATE="2005-05-26 23:30" \
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 touch)" \
106 'GIT_COMMITTER_DATE="2005-05-26 23:31" \
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 touch)" \
111 'GIT_COMMITTER_DATE="2005-05-26 23:41" \
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> 1117150200 +0000 Initial Creation
117$A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150260 +0000 Switch
118$B $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150860 +0000
119EOF
120test_expect_success \
121 "verifying $m's log" \
8aac4b45 122 "diff expect .git/logs/$m"
6de08ae6
SP
123rm -rf .git/$m .git/logs expect
124
125test_expect_success \
126 'enable core.logAllRefUpdates' \
5be60078
JH
127 'git config core.logAllRefUpdates true &&
128 test true = $(git config --bool --get core.logAllRefUpdates)'
6de08ae6
SP
129
130test_expect_success \
131 "create $m (logged by config)" \
132 'GIT_COMMITTER_DATE="2005-05-26 23:32" \
5be60078 133 git update-ref HEAD'" $A "'-m "Initial Creation" &&
8aac4b45 134 test '"$A"' = $(cat .git/'"$m"')'
6de08ae6
SP
135test_expect_success \
136 "update $m (logged by config)" \
137 'GIT_COMMITTER_DATE="2005-05-26 23:33" \
5be60078 138 git update-ref HEAD'" $B $A "'-m "Switch" &&
8aac4b45 139 test '"$B"' = $(cat .git/'"$m"')'
6de08ae6
SP
140test_expect_success \
141 "set $m (logged by config)" \
142 'GIT_COMMITTER_DATE="2005-05-26 23:43" \
5be60078 143 git update-ref HEAD '"$A &&
8aac4b45 144 test $A"' = $(cat .git/'"$m"')'
6de08ae6
SP
145
146cat >expect <<EOF
147$Z $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150320 +0000 Initial Creation
148$A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150380 +0000 Switch
149$B $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150980 +0000
150EOF
151test_expect_success \
152 "verifying $m's log" \
153 'diff expect .git/logs/$m'
154rm -f .git/$m .git/logs/$m expect
155
5be60078 156git update-ref $m $D
e5229042
SP
157cat >.git/logs/$m <<EOF
158$C $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150320 -0500
159$A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150380 -0500
160$F $Z $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150680 -0500
161$Z $E $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150980 -0500
162EOF
163
164ed="Thu, 26 May 2005 18:32:00 -0500"
165gd="Thu, 26 May 2005 18:33:00 -0500"
166ld="Thu, 26 May 2005 18:43:00 -0500"
167test_expect_success \
cce91a2c 168 'Query "master@{May 25 2005}" (before history)' \
e5229042 169 'rm -f o e
5be60078 170 git rev-parse --verify "master@{May 25 2005}" >o 2>e &&
8aac4b45 171 test '"$C"' = $(cat o) &&
16d7cc90 172 test "warning: Log for '\'master\'' only goes back to $ed." = "$(cat e)"'
e5229042 173test_expect_success \
cce91a2c 174 "Query master@{2005-05-25} (before history)" \
e5229042 175 'rm -f o e
5be60078 176 git rev-parse --verify master@{2005-05-25} >o 2>e &&
8aac4b45 177 test '"$C"' = $(cat o) &&
16d7cc90 178 echo test "warning: Log for '\'master\'' only goes back to $ed." = "$(cat e)"'
e5229042 179test_expect_success \
cce91a2c 180 'Query "master@{May 26 2005 23:31:59}" (1 second before history)' \
e5229042 181 'rm -f o e
5be60078 182 git rev-parse --verify "master@{May 26 2005 23:31:59}" >o 2>e &&
8aac4b45 183 test '"$C"' = $(cat o) &&
16d7cc90 184 test "warning: Log for '\''master'\'' only goes back to $ed." = "$(cat e)"'
e5229042 185test_expect_success \
cce91a2c 186 'Query "master@{May 26 2005 23:32:00}" (exactly history start)' \
e5229042 187 'rm -f o e
5be60078 188 git rev-parse --verify "master@{May 26 2005 23:32:00}" >o 2>e &&
8aac4b45 189 test '"$A"' = $(cat o) &&
e5229042
SP
190 test "" = "$(cat e)"'
191test_expect_success \
cce91a2c 192 'Query "master@{2005-05-26 23:33:01}" (middle of history with gap)' \
e5229042 193 'rm -f o e
5be60078 194 git rev-parse --verify "master@{2005-05-26 23:33:01}" >o 2>e &&
8aac4b45
JH
195 test '"$B"' = $(cat o) &&
196 test "warning: Log .git/logs/'"$m has gap after $gd"'." = "$(cat e)"'
e5229042 197test_expect_success \
cce91a2c 198 'Query "master@{2005-05-26 23:38:00}" (middle of history)' \
e5229042 199 'rm -f o e
5be60078 200 git rev-parse --verify "master@{2005-05-26 23:38:00}" >o 2>e &&
8aac4b45 201 test '"$Z"' = $(cat o) &&
e5229042
SP
202 test "" = "$(cat e)"'
203test_expect_success \
cce91a2c 204 'Query "master@{2005-05-26 23:43:00}" (exact end of history)' \
e5229042 205 'rm -f o e
5be60078 206 git rev-parse --verify "master@{2005-05-26 23:43:00}" >o 2>e &&
8aac4b45 207 test '"$E"' = $(cat o) &&
e5229042
SP
208 test "" = "$(cat e)"'
209test_expect_success \
cce91a2c 210 'Query "master@{2005-05-28}" (past end of history)' \
e5229042 211 'rm -f o e
5be60078 212 git rev-parse --verify "master@{2005-05-28}" >o 2>e &&
8aac4b45
JH
213 test '"$D"' = $(cat o) &&
214 test "warning: Log .git/logs/'"$m unexpectedly ended on $ld"'." = "$(cat e)"'
e5229042 215
cce91a2c
SP
216
217rm -f .git/$m .git/logs/$m expect
218
219test_expect_success \
220 'creating initial files' \
9c7466fa 221 'echo TEST >F &&
5be60078 222 git add F &&
9c7466fa 223 GIT_AUTHOR_DATE="2005-05-26 23:30" \
cce91a2c 224 GIT_COMMITTER_DATE="2005-05-26 23:30" git-commit -m add -a &&
5be60078 225 h_TEST=$(git rev-parse --verify HEAD)
9c7466fa
SP
226 echo The other day this did not work. >M &&
227 echo And then Bob told me how to fix it. >>M &&
228 echo OTHER >F &&
229 GIT_AUTHOR_DATE="2005-05-26 23:41" \
230 GIT_COMMITTER_DATE="2005-05-26 23:41" git-commit -F M -a &&
5be60078 231 h_OTHER=$(git rev-parse --verify HEAD) &&
a3a733e6
SP
232 GIT_AUTHOR_DATE="2005-05-26 23:44" \
233 GIT_COMMITTER_DATE="2005-05-26 23:44" git-commit --amend &&
5be60078 234 h_FIXED=$(git rev-parse --verify HEAD) &&
a3a733e6
SP
235 echo Merged initial commit and a later commit. >M &&
236 echo $h_TEST >.git/MERGE_HEAD &&
237 GIT_AUTHOR_DATE="2005-05-26 23:45" \
238 GIT_COMMITTER_DATE="2005-05-26 23:45" git-commit -F M &&
d9c8344b 239 h_MERGED=$(git rev-parse --verify HEAD) &&
9c7466fa
SP
240 rm -f M'
241
242cat >expect <<EOF
a3a733e6 243$Z $h_TEST $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 commit (initial): add
9c7466fa 244$h_TEST $h_OTHER $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150860 +0000 commit: The other day this did not work.
a3a733e6
SP
245$h_OTHER $h_FIXED $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117151040 +0000 commit (amend): The other day this did not work.
246$h_FIXED $h_MERGED $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117151100 +0000 commit (merge): Merged initial commit and a later commit.
9c7466fa
SP
247EOF
248test_expect_success \
249 'git-commit logged updates' \
8aac4b45 250 "diff expect .git/logs/$m"
a3a733e6 251unset h_TEST h_OTHER h_FIXED h_MERGED
cce91a2c
SP
252
253test_expect_success \
5be60078
JH
254 'git cat-file blob master:F (expect OTHER)' \
255 'test OTHER = $(git cat-file blob master:F)'
cce91a2c 256test_expect_success \
5be60078
JH
257 'git cat-file blob master@{2005-05-26 23:30}:F (expect TEST)' \
258 'test TEST = $(git cat-file blob "master@{2005-05-26 23:30}:F")'
cce91a2c 259test_expect_success \
5be60078
JH
260 'git cat-file blob master@{2005-05-26 23:42}:F (expect OTHER)' \
261 'test OTHER = $(git cat-file blob "master@{2005-05-26 23:42}:F")'
cce91a2c 262
6de08ae6 263test_done