3 test_description
='check various push.default settings'
6 test_expect_success
'setup bare remotes' '
7 git init --bare repo1 &&
8 git remote add parent1 repo1 &&
9 git init --bare repo2 &&
10 git remote add parent2 repo2 &&
12 git push parent1 HEAD &&
17 # $2 = remote revision (tested to be equal to the local one)
18 # $3 = [optional] repo to check for actual output (repo1 by default)
19 check_pushed_commit
() {
20 git log
-1 --format='%h %s' "$1" >expect
&&
21 git
--git-dir="${3:-repo1}" log
-1 --format='%h %s' "$2" >actual
&&
22 test_cmp expect actual
25 # $1 = push.default value
26 # $2 = expected target branch for the push
27 # $3 = [optional] repo to check for actual output (repo1 by default)
28 test_push_success
() {
29 git
${1:+-c} ${1:+push.default="$1"} push
&&
30 check_pushed_commit HEAD
"$2" "$3"
33 # $1 = push.default value
34 # check that push fails and does not modify any remote branch
35 test_push_failure
() {
36 git
--git-dir=repo1 log
--no-walk --format='%h %s' --all >expect
&&
37 test_must_fail git
${1:+-c} ${1:+push.default="$1"} push
&&
38 git
--git-dir=repo1 log
--no-walk --format='%h %s' --all >actual
&&
39 test_cmp expect actual
42 # $1 = success or failure
43 # $2 = push.default value
44 # $3 = branch to check for actual output (master or foo)
45 # $4 = [optional] switch to triangular workflow
46 test_pushdefault_workflow
() {
49 if test -n "${4-}"; then
53 test_expect_success
"push.default = $2 $1 in $workflow workflows" "
54 test_config branch.master.remote parent1 &&
55 test_config branch.master.merge refs/heads/foo &&
56 test_config remote.pushdefault $pushdefault &&
57 test_commit commit-for-$2${4+-triangular} &&
58 test_push_$1 $2 $3 ${4+repo2}
62 test_expect_success
'"upstream" pushes to configured upstream' '
63 git checkout master &&
64 test_config branch.master.remote parent1 &&
65 test_config branch.master.merge refs/heads/foo &&
67 test_push_success upstream foo
70 test_expect_success
'"upstream" does not push on unconfigured remote' '
71 git checkout master &&
72 test_unconfig branch.master.remote &&
74 test_push_failure upstream
77 test_expect_success
'"upstream" does not push on unconfigured branch' '
78 git checkout master &&
79 test_config branch.master.remote parent1 &&
80 test_unconfig branch.master.merge &&
82 test_push_failure upstream
85 test_expect_success
'"upstream" does not push when remotes do not match' '
86 git checkout master &&
87 test_config branch.master.remote parent1 &&
88 test_config branch.master.merge refs/heads/foo &&
89 test_config push.default upstream &&
91 test_must_fail git push parent2
94 test_expect_success
'push from/to new branch with upstream, matching and simple' '
95 git checkout -b new-branch &&
96 test_push_failure simple &&
97 test_push_failure matching &&
98 test_push_failure upstream
101 test_expect_success
'"matching" fails if none match' '
102 git init --bare empty &&
103 test_must_fail git push empty : 2>actual &&
104 test_i18ngrep "Perhaps you should specify a branch" actual
107 test_expect_success
'push ambiguously named branch with upstream, matching and simple' '
108 git checkout -b ambiguous &&
109 test_config branch.ambiguous.remote parent1 &&
110 test_config branch.ambiguous.merge refs/heads/ambiguous &&
112 test_push_success simple ambiguous &&
113 test_push_success matching ambiguous &&
114 test_push_success upstream ambiguous
117 test_expect_success
'push from/to new branch with current creates remote branch' '
118 test_config branch.new-branch.remote repo1 &&
119 git checkout new-branch &&
120 test_push_success current new-branch
123 test_expect_success
'push to existing branch, with no upstream configured' '
124 test_config branch.master.remote repo1 &&
125 git checkout master &&
126 test_push_failure simple &&
127 test_push_failure upstream
130 test_expect_success
'push to existing branch, upstream configured with same name' '
131 test_config branch.master.remote repo1 &&
132 test_config branch.master.merge refs/heads/master &&
133 git checkout master &&
135 test_push_success upstream master &&
137 test_push_success simple master
140 test_expect_success
'push to existing branch, upstream configured with different name' '
141 test_config branch.master.remote repo1 &&
142 test_config branch.master.merge refs/heads/other-name &&
143 git checkout master &&
145 test_push_success upstream other-name &&
147 test_push_failure simple &&
148 git --git-dir=repo1 log -1 --format="%h %s" "other-name" >expect-other-name &&
149 test_push_success current master &&
150 git --git-dir=repo1 log -1 --format="%h %s" "other-name" >actual-other-name &&
151 test_cmp expect-other-name actual-other-name
154 # We are on 'master', which integrates with 'foo' from parent1
155 # remote (set in test_pushdefault_workflow helper). Push to
156 # parent1 in centralized, and push to parent2 in triangular workflow.
157 # The parent1 repository has 'master' and 'foo' branches, while
158 # the parent2 repository has only 'master' branch.
160 # test_pushdefault_workflow() arguments:
161 # $1 = success or failure
162 # $2 = push.default value
163 # $3 = branch to check for actual output (master or foo)
164 # $4 = [optional] switch to triangular workflow
166 # update parent1's master (which is not our upstream)
167 test_pushdefault_workflow success current master
169 # update parent1's foo (which is our upstream)
170 test_pushdefault_workflow success upstream foo
172 # upstream is foo which is not the name of the current branch
173 test_pushdefault_workflow failure simple master
175 # master and foo are updated
176 test_pushdefault_workflow success matching master
179 test_pushdefault_workflow success current master triangular
181 # upstream mode cannot be used in triangular
182 test_pushdefault_workflow failure upstream foo triangular
184 # in triangular, 'simple' works as 'current' and update the branch
185 # with the same name.
186 test_pushdefault_workflow success simple master triangular
188 # master is updated (parent2 does not have foo)
189 test_pushdefault_workflow success matching master triangular
191 # default tests, when no push-default is specified. This
192 # should behave the same as "simple" in non-triangular
193 # settings, and as "current" otherwise.
195 test_expect_success
'default behavior allows "simple" push' '
196 test_config branch.master.remote parent1 &&
197 test_config branch.master.merge refs/heads/master &&
198 test_config remote.pushdefault parent1 &&
199 test_commit default-master-master &&
200 test_push_success "" master
203 test_expect_success
'default behavior rejects non-simple push' '
204 test_config branch.master.remote parent1 &&
205 test_config branch.master.merge refs/heads/foo &&
206 test_config remote.pushdefault parent1 &&
207 test_commit default-master-foo &&
211 test_expect_success
'default triangular behavior acts like "current"' '
212 test_config branch.master.remote parent1 &&
213 test_config branch.master.merge refs/heads/foo &&
214 test_config remote.pushdefault parent2 &&
215 test_commit default-triangular &&
216 test_push_success "" master repo2