3 test_description
='pushing to a repository using the atomic push option'
8 rm -rf workbench upstream
&&
9 test_create_repo upstream
&&
10 test_create_repo workbench
&&
13 git config receive.denyCurrentBranch warn
17 git remote add up ..
/upstream
21 # Compare the ref ($1) in upstream with a ref value from workbench ($2)
22 # i.e. test_refs second HEAD@{2}
25 git
-C upstream rev-parse
--verify "$1" >expect
&&
26 git
-C workbench rev-parse
--verify "$2" >actual
&&
27 test_cmp expect actual
30 test_expect_success
'atomic push works for a single branch' '
35 git push --mirror up &&
37 git push --atomic up master
39 test_refs master master
42 test_expect_success
'atomic push works for two branches' '
48 git push --mirror up &&
50 git checkout second &&
52 git push --atomic up master second
54 test_refs master master &&
55 test_refs second second
58 test_expect_success
'atomic push works in combination with --mirror' '
63 git checkout -b second &&
65 git push --atomic --mirror up
67 test_refs master master &&
68 test_refs second second
71 test_expect_success
'atomic push works in combination with --force' '
76 git branch second master &&
78 git checkout second &&
80 test_commit three_b &&
82 git push --mirror up &&
83 # The actual test is below
84 git checkout master &&
85 test_commit three_a &&
86 git checkout second &&
87 git reset --hard HEAD^ &&
88 git push --force --atomic up master second
90 test_refs master master &&
91 test_refs second second
94 # set up two branches where master can be pushed but second can not
95 # (non-fast-forward). Since second can not be pushed the whole operation
96 # will fail and leave master untouched.
97 test_expect_success
'atomic push fails if one branch fails' '
102 git checkout -b second master &&
106 git push --mirror up &&
107 git reset --hard HEAD~2 &&
109 git checkout master &&
111 test_must_fail git push --atomic --all up
113 test_refs master HEAD@{7} &&
114 test_refs second HEAD@{4}
117 test_expect_success
'atomic push fails if one tag fails remotely' '
123 git checkout -b second master &&
127 # a third party modifies the server side:
130 git checkout second &&
131 git tag test_tag second
133 # see if we can now push both branches.
136 git checkout master &&
138 git checkout second &&
141 test_must_fail git push --tags --atomic up master second
143 test_refs master HEAD@{3} &&
144 test_refs second HEAD@{1}
147 test_expect_success
'atomic push obeys update hook preventing a branch to be pushed' '
152 git checkout -b second master &&
158 HOOKDIR="$(git rev-parse --git-dir)/hooks" &&
159 HOOK="$HOOKDIR/update" &&
160 mkdir -p "$HOOKDIR" &&
161 write_script "$HOOK" <<-\EOF
162 # only allow update to master from now on
163 test "$1" = "refs/heads/master"
168 git checkout master &&
170 git checkout second &&
172 test_must_fail git push --atomic up master second
174 test_refs master HEAD@{3} &&
175 test_refs second HEAD@{1}
178 test_expect_success
'atomic push is not advertised if configured' '
182 git config receive.advertiseatomic 0
187 git push --mirror up &&
189 test_must_fail git push --atomic up master
191 test_refs master HEAD@{1}