Log ref updates to logs/refs/<ref>
[git/jnareb-git.git] / t / t1400-update-ref.sh
blobf338c53774c6a3f837437e1ac9bbf2cc140b8b56
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 m=refs/heads/master
14 test_expect_success \
15 "create $m" \
16 'git-update-ref $m $A &&
17 test $A = $(cat .git/$m)'
18 test_expect_success \
19 "create $m" \
20 'git-update-ref $m $B $A &&
21 test $B = $(cat .git/$m)'
22 rm -f .git/$m
24 test_expect_success \
25 "create $m (by HEAD)" \
26 'git-update-ref HEAD $A &&
27 test $A = $(cat .git/$m)'
28 test_expect_success \
29 "create $m (by HEAD)" \
30 'git-update-ref HEAD $B $A &&
31 test $B = $(cat .git/$m)'
32 rm -f .git/$m
34 test_expect_failure \
35 '(not) create HEAD with old sha1' \
36 'git-update-ref HEAD $A $B'
37 test_expect_failure \
38 "(not) prior created .git/$m" \
39 'test -f .git/$m'
40 rm -f .git/$m
42 test_expect_success \
43 "create HEAD" \
44 'git-update-ref HEAD $A'
45 test_expect_failure \
46 '(not) change HEAD with wrong SHA1' \
47 'git-update-ref HEAD $B $Z'
48 test_expect_failure \
49 "(not) changed .git/$m" \
50 'test $B = $(cat .git/$m)'
51 rm -f .git/$m
53 mkdir -p .git/logs/refs/heads
54 touch .git/logs/refs/heads/master
55 test_expect_success \
56 "create $m (logged by touch)" \
57 'GIT_COMMITTER_DATE="2005-05-26 23:30" \
58 git-update-ref HEAD $A -m "Initial Creation" &&
59 test $A = $(cat .git/$m)'
60 test_expect_success \
61 "update $m (logged by touch)" \
62 'GIT_COMMITTER_DATE="2005-05-26 23:31" \
63 git-update-ref HEAD $B $A -m "Switch" &&
64 test $B = $(cat .git/$m)'
65 test_expect_success \
66 "set $m (logged by touch)" \
67 'GIT_COMMITTER_DATE="2005-05-26 23:41" \
68 git-update-ref HEAD $A &&
69 test $A = $(cat .git/$m)'
71 cat >expect <<EOF
72 $Z $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 Initial Creation
73 $A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150260 +0000 Switch
74 $B $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150860 +0000
75 EOF
76 test_expect_success \
77 "verifying $m's log" \
78 'diff expect .git/logs/$m'
79 rm -rf .git/$m .git/logs expect
81 test_expect_success \
82 'enable core.logAllRefUpdates' \
83 'git-repo-config core.logAllRefUpdates true &&
84 test true = $(git-repo-config --bool --get core.logAllRefUpdates)'
86 test_expect_success \
87 "create $m (logged by config)" \
88 'GIT_COMMITTER_DATE="2005-05-26 23:32" \
89 git-update-ref HEAD $A -m "Initial Creation" &&
90 test $A = $(cat .git/$m)'
91 test_expect_success \
92 "update $m (logged by config)" \
93 'GIT_COMMITTER_DATE="2005-05-26 23:33" \
94 git-update-ref HEAD $B $A -m "Switch" &&
95 test $B = $(cat .git/$m)'
96 test_expect_success \
97 "set $m (logged by config)" \
98 'GIT_COMMITTER_DATE="2005-05-26 23:43" \
99 git-update-ref HEAD $A &&
100 test $A = $(cat .git/$m)'
102 cat >expect <<EOF
103 $Z $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150320 +0000 Initial Creation
104 $A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150380 +0000 Switch
105 $B $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150980 +0000
107 test_expect_success \
108 "verifying $m's log" \
109 'diff expect .git/logs/$m'
110 rm -f .git/$m .git/logs/$m expect
112 test_done