94
test_must_fail git push parent2
95
'
96
97
-test_expect_success 'push from/to new branch with upstream, matching and simple' '
97
+test_expect_success '"current" does not push when multiple remotes and none origin' '
98
+ git checkout main &&
99
+ test_config push.default current &&
100
+ test_commit current-multi &&
101
+ test_must_fail git push
102
+'
103
+
104
+test_expect_success '"current" pushes when remote explicitly specified' '
105
+ git checkout main &&
106
+ test_config push.default current &&
107
+ test_commit current-specified &&
108
+ git push parent1
109
+'
110
+
111
+test_expect_success '"current" pushes to origin when no remote specified among multiple' '
112
+ git checkout main &&
113
+ test_config remote.origin.url repo1 &&
114
+ test_config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*" &&
115
+ test_commit current-origin &&
116
+ test_push_success current main
117
+'
118
+
119
+test_expect_success '"current" pushes to single remote even when not specified' '
120
+ git checkout main &&
121
+ test_when_finished git remote add parent1 repo1 &&
122
+ git remote remove parent1 &&
123
+ test_commit current-implied &&
124
+ test_push_success current main repo2
125
+'
126
+
127
+test_expect_success 'push from/to new branch with non-defaulted remote fails with upstream, matching, current and simple ' '
128
git checkout -b new-branch &&
129
test_push_failure simple &&
130
test_push_failure matching &&
131
+ test_push_failure upstream &&
132
+ test_push_failure current
133
+'
134
+
135
+test_expect_success 'push from/to new branch fails with upstream and simple ' '
136
+ git checkout -b new-branch-1 &&
137
+ test_config branch.new-branch-1.remote parent1 &&
138
+ test_push_failure simple &&
139
test_push_failure upstream
140
'
141
142
+# The behavior here is surprising but not entirely wrong:
143
+# - the current branch is used to determine the target remote
144
+# - the "matching" push default pushes matching branches, *ignoring* the
145
+# current new branch as it does not have upstream tracking
146
+# - the default push succeeds
147
+#
148
+# A previous test expected this to fail, but for the wrong reasons:
149
+# it expected a fail becaause the branch is new and cannot be pushed, but
150
+# in fact it was failing because of an ambiguous remote
151
+#
152
+test_expect_failure 'push from/to new branch fails with matching ' '
153
+ git checkout -b new-branch-2 &&
154
+ test_config branch.new-branch-2.remote parent1 &&
155
+ test_push_failure matching
156
+'
157
+
158
+test_expect_success 'push from/to branch with tracking fails with nothing ' '
159
+ git checkout -b tracked-branch &&
160
+ test_config branch.tracked-branch.remote parent1 &&
161
+ test_config branch.tracked-branch.merge refs/heads/tracked-branch &&
162
+ test_push_failure nothing
163
+'
164
+
165
test_expect_success '"matching" fails if none match' '
166
git init --bare empty &&
167
test_must_fail git push empty : 2>actual &&