Update stale documentation links from the main documentation.
[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"')'
6de08ae6
SP
35rm -f .git/$m
36
818f477c
SP
37test_expect_success \
38 "fail to create $n" \
8aac4b45 39 "touch .git/$n_dir
5be60078 40 git update-ref $n $A >out 2>err"'
ef176ad0 41 test $? != 0'
818f477c
SP
42rm -f .git/$n_dir out err
43
6de08ae6
SP
44test_expect_success \
45 "create $m (by HEAD)" \
5be60078 46 "git update-ref HEAD $A &&
8aac4b45 47 test $A"' = $(cat .git/'"$m"')'
6de08ae6
SP
48test_expect_success \
49 "create $m (by HEAD)" \
5be60078 50 "git update-ref HEAD $B $A &&
8aac4b45 51 test $B"' = $(cat .git/'"$m"')'
6de08ae6
SP
52rm -f .git/$m
53
54test_expect_failure \
55 '(not) create HEAD with old sha1' \
5be60078 56 "git update-ref HEAD $A $B"
6de08ae6
SP
57test_expect_failure \
58 "(not) prior created .git/$m" \
8aac4b45 59 "test -f .git/$m"
6de08ae6
SP
60rm -f .git/$m
61
62test_expect_success \
63 "create HEAD" \
5be60078 64 "git update-ref HEAD $A"
6de08ae6
SP
65test_expect_failure \
66 '(not) change HEAD with wrong SHA1' \
5be60078 67 "git update-ref HEAD $B $Z"
6de08ae6
SP
68test_expect_failure \
69 "(not) changed .git/$m" \
8aac4b45 70 "test $B"' = $(cat .git/'"$m"')'
6de08ae6
SP
71rm -f .git/$m
72
0bee5918
SP
73: a repository with working tree always has reflog these days...
74: >.git/logs/refs/heads/master
6de08ae6
SP
75test_expect_success \
76 "create $m (logged by touch)" \
77 'GIT_COMMITTER_DATE="2005-05-26 23:30" \
5be60078 78 git update-ref HEAD '"$A"' -m "Initial Creation" &&
8aac4b45 79 test '"$A"' = $(cat .git/'"$m"')'
6de08ae6
SP
80test_expect_success \
81 "update $m (logged by touch)" \
82 'GIT_COMMITTER_DATE="2005-05-26 23:31" \
5be60078 83 git update-ref HEAD'" $B $A "'-m "Switch" &&
8aac4b45 84 test '"$B"' = $(cat .git/'"$m"')'
6de08ae6
SP
85test_expect_success \
86 "set $m (logged by touch)" \
87 'GIT_COMMITTER_DATE="2005-05-26 23:41" \
5be60078 88 git update-ref HEAD'" $A &&
8aac4b45 89 test $A"' = $(cat .git/'"$m"')'
6de08ae6
SP
90
91cat >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
95EOF
96test_expect_success \
97 "verifying $m's log" \
8aac4b45 98 "diff expect .git/logs/$m"
6de08ae6
SP
99rm -rf .git/$m .git/logs expect
100
101test_expect_success \
102 'enable core.logAllRefUpdates' \
5be60078
JH
103 'git config core.logAllRefUpdates true &&
104 test true = $(git config --bool --get core.logAllRefUpdates)'
6de08ae6
SP
105
106test_expect_success \
107 "create $m (logged by config)" \
108 'GIT_COMMITTER_DATE="2005-05-26 23:32" \
5be60078 109 git update-ref HEAD'" $A "'-m "Initial Creation" &&
8aac4b45 110 test '"$A"' = $(cat .git/'"$m"')'
6de08ae6
SP
111test_expect_success \
112 "update $m (logged by config)" \
113 'GIT_COMMITTER_DATE="2005-05-26 23:33" \
5be60078 114 git update-ref HEAD'" $B $A "'-m "Switch" &&
8aac4b45 115 test '"$B"' = $(cat .git/'"$m"')'
6de08ae6
SP
116test_expect_success \
117 "set $m (logged by config)" \
118 'GIT_COMMITTER_DATE="2005-05-26 23:43" \
5be60078 119 git update-ref HEAD '"$A &&
8aac4b45 120 test $A"' = $(cat .git/'"$m"')'
6de08ae6
SP
121
122cat >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
126EOF
127test_expect_success \
128 "verifying $m's log" \
129 'diff expect .git/logs/$m'
130rm -f .git/$m .git/logs/$m expect
131
5be60078 132git update-ref $m $D
e5229042
SP
133cat >.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
138EOF
139
140ed="Thu, 26 May 2005 18:32:00 -0500"
141gd="Thu, 26 May 2005 18:33:00 -0500"
142ld="Thu, 26 May 2005 18:43:00 -0500"
143test_expect_success \
cce91a2c 144 'Query "master@{May 25 2005}" (before history)' \
e5229042 145 'rm -f o e
5be60078 146 git rev-parse --verify "master@{May 25 2005}" >o 2>e &&
8aac4b45 147 test '"$C"' = $(cat o) &&
16d7cc90 148 test "warning: Log for '\'master\'' only goes back to $ed." = "$(cat e)"'
e5229042 149test_expect_success \
cce91a2c 150 "Query master@{2005-05-25} (before history)" \
e5229042 151 'rm -f o e
5be60078 152 git rev-parse --verify master@{2005-05-25} >o 2>e &&
8aac4b45 153 test '"$C"' = $(cat o) &&
16d7cc90 154 echo test "warning: Log for '\'master\'' only goes back to $ed." = "$(cat e)"'
e5229042 155test_expect_success \
cce91a2c 156 'Query "master@{May 26 2005 23:31:59}" (1 second before history)' \
e5229042 157 'rm -f o e
5be60078 158 git rev-parse --verify "master@{May 26 2005 23:31:59}" >o 2>e &&
8aac4b45 159 test '"$C"' = $(cat o) &&
16d7cc90 160 test "warning: Log for '\''master'\'' only goes back to $ed." = "$(cat e)"'
e5229042 161test_expect_success \
cce91a2c 162 'Query "master@{May 26 2005 23:32:00}" (exactly history start)' \
e5229042 163 'rm -f o e
5be60078 164 git rev-parse --verify "master@{May 26 2005 23:32:00}" >o 2>e &&
8aac4b45 165 test '"$A"' = $(cat o) &&
e5229042
SP
166 test "" = "$(cat e)"'
167test_expect_success \
cce91a2c 168 'Query "master@{2005-05-26 23:33:01}" (middle of history with gap)' \
e5229042 169 'rm -f o e
5be60078 170 git rev-parse --verify "master@{2005-05-26 23:33:01}" >o 2>e &&
8aac4b45
JH
171 test '"$B"' = $(cat o) &&
172 test "warning: Log .git/logs/'"$m has gap after $gd"'." = "$(cat e)"'
e5229042 173test_expect_success \
cce91a2c 174 'Query "master@{2005-05-26 23:38:00}" (middle of history)' \
e5229042 175 'rm -f o e
5be60078 176 git rev-parse --verify "master@{2005-05-26 23:38:00}" >o 2>e &&
8aac4b45 177 test '"$Z"' = $(cat o) &&
e5229042
SP
178 test "" = "$(cat e)"'
179test_expect_success \
cce91a2c 180 'Query "master@{2005-05-26 23:43:00}" (exact end of history)' \
e5229042 181 'rm -f o e
5be60078 182 git rev-parse --verify "master@{2005-05-26 23:43:00}" >o 2>e &&
8aac4b45 183 test '"$E"' = $(cat o) &&
e5229042
SP
184 test "" = "$(cat e)"'
185test_expect_success \
cce91a2c 186 'Query "master@{2005-05-28}" (past end of history)' \
e5229042 187 'rm -f o e
5be60078 188 git rev-parse --verify "master@{2005-05-28}" >o 2>e &&
8aac4b45
JH
189 test '"$D"' = $(cat o) &&
190 test "warning: Log .git/logs/'"$m unexpectedly ended on $ld"'." = "$(cat e)"'
e5229042 191
cce91a2c
SP
192
193rm -f .git/$m .git/logs/$m expect
194
195test_expect_success \
196 'creating initial files' \
9c7466fa 197 'echo TEST >F &&
5be60078 198 git add F &&
9c7466fa 199 GIT_AUTHOR_DATE="2005-05-26 23:30" \
cce91a2c 200 GIT_COMMITTER_DATE="2005-05-26 23:30" git-commit -m add -a &&
5be60078 201 h_TEST=$(git rev-parse --verify HEAD)
9c7466fa
SP
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 &&
5be60078 207 h_OTHER=$(git rev-parse --verify HEAD) &&
a3a733e6
SP
208 GIT_AUTHOR_DATE="2005-05-26 23:44" \
209 GIT_COMMITTER_DATE="2005-05-26 23:44" git-commit --amend &&
5be60078 210 h_FIXED=$(git rev-parse --verify HEAD) &&
a3a733e6
SP
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 &&
d9c8344b 215 h_MERGED=$(git rev-parse --verify HEAD) &&
9c7466fa
SP
216 rm -f M'
217
218cat >expect <<EOF
a3a733e6 219$Z $h_TEST $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 commit (initial): add
9c7466fa 220$h_TEST $h_OTHER $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150860 +0000 commit: The other day this did not work.
a3a733e6
SP
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.
9c7466fa
SP
223EOF
224test_expect_success \
225 'git-commit logged updates' \
8aac4b45 226 "diff expect .git/logs/$m"
a3a733e6 227unset h_TEST h_OTHER h_FIXED h_MERGED
cce91a2c
SP
228
229test_expect_success \
5be60078
JH
230 'git cat-file blob master:F (expect OTHER)' \
231 'test OTHER = $(git cat-file blob master:F)'
cce91a2c 232test_expect_success \
5be60078
JH
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")'
cce91a2c 235test_expect_success \
5be60078
JH
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")'
cce91a2c 238
6de08ae6 239test_done