l10n: bg.po: Updated Bulgarian translation (5211t)
[git/debian.git] / t / t1416-ref-transaction-hooks.sh
blob6c941027a811a5fa2429f03b3092940b6fa2b782
1 #!/bin/sh
3 test_description='reference transaction hooks'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
8 . ./test-lib.sh
10 test_expect_success setup '
11 mkdir -p .git/hooks &&
12 test_commit PRE &&
13 PRE_OID=$(git rev-parse PRE) &&
14 test_commit POST &&
15 POST_OID=$(git rev-parse POST)
18 test_expect_success 'hook allows updating ref if successful' '
19 test_when_finished "rm .git/hooks/reference-transaction" &&
20 git reset --hard PRE &&
21 write_script .git/hooks/reference-transaction <<-\EOF &&
22 echo "$*" >>actual
23 EOF
24 cat >expect <<-EOF &&
25 prepared
26 committed
27 EOF
28 git update-ref HEAD POST &&
29 test_cmp expect actual
32 test_expect_success 'hook aborts updating ref in prepared state' '
33 test_when_finished "rm .git/hooks/reference-transaction" &&
34 git reset --hard PRE &&
35 write_script .git/hooks/reference-transaction <<-\EOF &&
36 if test "$1" = prepared
37 then
38 exit 1
40 EOF
41 test_must_fail git update-ref HEAD POST 2>err &&
42 test_i18ngrep "ref updates aborted by hook" err
45 test_expect_success 'hook gets all queued updates in prepared state' '
46 test_when_finished "rm .git/hooks/reference-transaction actual" &&
47 git reset --hard PRE &&
48 write_script .git/hooks/reference-transaction <<-\EOF &&
49 if test "$1" = prepared
50 then
51 while read -r line
53 printf "%s\n" "$line"
54 done >actual
56 EOF
57 cat >expect <<-EOF &&
58 $ZERO_OID $POST_OID HEAD
59 $ZERO_OID $POST_OID refs/heads/main
60 EOF
61 git update-ref HEAD POST <<-EOF &&
62 update HEAD $ZERO_OID $POST_OID
63 update refs/heads/main $ZERO_OID $POST_OID
64 EOF
65 test_cmp expect actual
68 test_expect_success 'hook gets all queued updates in committed state' '
69 test_when_finished "rm .git/hooks/reference-transaction actual" &&
70 git reset --hard PRE &&
71 write_script .git/hooks/reference-transaction <<-\EOF &&
72 if test "$1" = committed
73 then
74 while read -r line
76 printf "%s\n" "$line"
77 done >actual
79 EOF
80 cat >expect <<-EOF &&
81 $ZERO_OID $POST_OID HEAD
82 $ZERO_OID $POST_OID refs/heads/main
83 EOF
84 git update-ref HEAD POST &&
85 test_cmp expect actual
88 test_expect_success 'hook gets all queued updates in aborted state' '
89 test_when_finished "rm .git/hooks/reference-transaction actual" &&
90 git reset --hard PRE &&
91 write_script .git/hooks/reference-transaction <<-\EOF &&
92 if test "$1" = aborted
93 then
94 while read -r line
96 printf "%s\n" "$line"
97 done >actual
99 EOF
100 cat >expect <<-EOF &&
101 $ZERO_OID $POST_OID HEAD
102 $ZERO_OID $POST_OID refs/heads/main
104 git update-ref --stdin <<-EOF &&
105 start
106 update HEAD POST $ZERO_OID
107 update refs/heads/main POST $ZERO_OID
108 abort
110 test_cmp expect actual
113 test_expect_success 'interleaving hook calls succeed' '
114 test_when_finished "rm -r target-repo.git" &&
116 git init --bare target-repo.git &&
118 write_script target-repo.git/hooks/reference-transaction <<-\EOF &&
119 echo $0 "$@" >>actual
122 write_script target-repo.git/hooks/update <<-\EOF &&
123 echo $0 "$@" >>actual
126 cat >expect <<-EOF &&
127 hooks/update refs/tags/PRE $ZERO_OID $PRE_OID
128 hooks/reference-transaction prepared
129 hooks/reference-transaction committed
130 hooks/update refs/tags/POST $ZERO_OID $POST_OID
131 hooks/reference-transaction prepared
132 hooks/reference-transaction committed
135 git push ./target-repo.git PRE POST &&
136 test_cmp expect target-repo.git/actual
139 test_done