Log ref updates to logs/refs/<ref>
[git/git.git] / t / t1400-update-ref.sh
CommitLineData
6de08ae6
SP
1#!/bin/sh
2#
3# Copyright (c) 2006 Shawn Pearce
4#
5
6test_description='Test git-update-ref and basic ref logging'
7. ./test-lib.sh
8
9Z=0000000000000000000000000000000000000000
10A=1111111111111111111111111111111111111111
11B=2222222222222222222222222222222222222222
12m=refs/heads/master
13
14test_expect_success \
15 "create $m" \
16 'git-update-ref $m $A &&
17 test $A = $(cat .git/$m)'
18test_expect_success \
19 "create $m" \
20 'git-update-ref $m $B $A &&
21 test $B = $(cat .git/$m)'
22rm -f .git/$m
23
24test_expect_success \
25 "create $m (by HEAD)" \
26 'git-update-ref HEAD $A &&
27 test $A = $(cat .git/$m)'
28test_expect_success \
29 "create $m (by HEAD)" \
30 'git-update-ref HEAD $B $A &&
31 test $B = $(cat .git/$m)'
32rm -f .git/$m
33
34test_expect_failure \
35 '(not) create HEAD with old sha1' \
36 'git-update-ref HEAD $A $B'
37test_expect_failure \
38 "(not) prior created .git/$m" \
39 'test -f .git/$m'
40rm -f .git/$m
41
42test_expect_success \
43 "create HEAD" \
44 'git-update-ref HEAD $A'
45test_expect_failure \
46 '(not) change HEAD with wrong SHA1' \
47 'git-update-ref HEAD $B $Z'
48test_expect_failure \
49 "(not) changed .git/$m" \
50 'test $B = $(cat .git/$m)'
51rm -f .git/$m
52
53mkdir -p .git/logs/refs/heads
54touch .git/logs/refs/heads/master
55test_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)'
60test_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)'
65test_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)'
70
71cat >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
75EOF
76test_expect_success \
77 "verifying $m's log" \
78 'diff expect .git/logs/$m'
79rm -rf .git/$m .git/logs expect
80
81test_expect_success \
82 'enable core.logAllRefUpdates' \
83 'git-repo-config core.logAllRefUpdates true &&
84 test true = $(git-repo-config --bool --get core.logAllRefUpdates)'
85
86test_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)'
91test_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)'
96test_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)'
101
102cat >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
106EOF
107test_expect_success \
108 "verifying $m's log" \
109 'diff expect .git/logs/$m'
110rm -f .git/$m .git/logs/$m expect
111
112test_done