@@ -39,6 +39,26 @@ test_push_failure () {
3939 test_cmp expect actual
4040}
4141
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 () {
47+ workflow=central
48+ pushdefault=parent1
49+ if test -n " ${4-} " ; then
50+ workflow=triangular
51+ pushdefault=parent2
52+ fi
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}
59+ "
60+ }
61+
4262test_expect_success ' "upstream" pushes to configured upstream' '
4363 git checkout master &&
4464 test_config branch.master.remote parent1 &&
@@ -115,4 +135,41 @@ test_expect_success 'push to existing branch, upstream configured with different
115135 test_cmp expect-other-name actual-other-name
116136'
117137
138+ # We are on 'master', which integrates with 'foo' from parent1
139+ # remote (set in test_pushdefault_workflow helper). Push to
140+ # parent1 in centralized, and push to parent2 in triangular workflow.
141+ # The parent1 repository has 'master' and 'foo' branches, while
142+ # the parent2 repository has only 'master' branch.
143+ #
144+ # test_pushdefault_workflow() arguments:
145+ # $1 = success or failure
146+ # $2 = push.default value
147+ # $3 = branch to check for actual output (master or foo)
148+ # $4 = [optional] switch to triangular workflow
149+
150+ # update parent1's master (which is not our upstream)
151+ test_pushdefault_workflow success current master
152+
153+ # update parent1's foo (which is our upstream)
154+ test_pushdefault_workflow success upstream foo
155+
156+ # upsream is foo which is not the name of the current branch
157+ test_pushdefault_workflow failure simple master
158+
159+ # master and foo are updated
160+ test_pushdefault_workflow success matching master
161+
162+ # master is updated
163+ test_pushdefault_workflow success current master triangular
164+
165+ # upstream mode cannot be used in triangular
166+ test_pushdefault_workflow failure upstream foo triangular
167+
168+ # in triangular, 'simple' works as 'current' and update the branch
169+ # with the same name.
170+ test_pushdefault_workflow success simple master triangular
171+
172+ # master is updated (parent2 does not have foo)
173+ test_pushdefault_workflow success matching master triangular
174+
118175test_done
0 commit comments