120
"\n"
121
" git push %s HEAD:<name-of-remote-branch>\n");
122
123
-static void setup_push_upstream(struct remote *remote, int simple)
123
+static void setup_push_upstream(struct remote *remote, struct branch *branch,
124
+ int triangular)
125
{
126
struct strbuf refspec = STRBUF_INIT;
126
- struct branch *branch = branch_get(NULL);
127
+
128
if (!branch)
129
die(_(message_detached_head_die), remote->name);
130
if (!branch->merge_nr || !branch->merge || !branch->remote_name)
138
if (branch->merge_nr != 1)
139
die(_("The current branch %s has multiple upstream branches, "
140
"refusing to push."), branch->name);
140
- if (strcmp(branch->remote_name, remote->name))
141
+ if (triangular)
142
die(_("You are pushing to remote '%s', which is not the upstream of\n"
143
"your current branch '%s', without telling me what to push\n"
144
"to update which remote branch."),
145
remote->name, branch->name);
145
- if (simple && strcmp(branch->refname, branch->merge[0]->src))
146
- die_push_simple(branch, remote);
146
+
147
+ if (push_default == PUSH_DEFAULT_SIMPLE) {
148
+ /* Additional safety */
149
+ if (strcmp(branch->refname, branch->merge[0]->src))
150
+ die_push_simple(branch, remote);
151
+ }
152
153
strbuf_addf(&refspec, "%s:%s", branch->name, branch->merge[0]->src);
154
add_refspec(refspec.buf);
155
}
156
157
+static void setup_push_current(struct remote *remote, struct branch *branch)
158
+{
159
+ if (!branch)
160
+ die(_(message_detached_head_die), remote->name);
161
+ add_refspec(branch->name);
162
+}
163
+
164
static char warn_unspecified_push_default_msg[] =
165
N_("push.default is unset; its implicit value is changing in\n"
166
"Git 2.0 from 'matching' to 'simple'. To squelch this message\n"
185
warning("%s\n", _(warn_unspecified_push_default_msg));
186
}
187
188
+static int is_workflow_triangular(struct remote *remote)
189
+{
190
+ struct remote *fetch_remote = remote_get(NULL);
191
+ return (fetch_remote && fetch_remote != remote);
192
+}
193
+
194
static void setup_default_push_refspecs(struct remote *remote)
195
{
178
- struct branch *branch;
196
+ struct branch *branch = branch_get(NULL);
197
+ int triangular = is_workflow_triangular(remote);
198
199
switch (push_default) {
200
default:
207
break;
208
209
case PUSH_DEFAULT_SIMPLE:
191
- setup_push_upstream(remote, 1);
210
+ if (triangular)
211
+ setup_push_current(remote, branch);
212
+ else
213
+ setup_push_upstream(remote, branch, triangular);
214
break;
215
216
case PUSH_DEFAULT_UPSTREAM:
195
- setup_push_upstream(remote, 0);
217
+ setup_push_upstream(remote, branch, triangular);
218
break;
219
220
case PUSH_DEFAULT_CURRENT:
199
- branch = branch_get(NULL);
200
- if (!branch)
201
- die(_(message_detached_head_die), remote->name);
202
- add_refspec(branch->name);
221
+ setup_push_current(remote, branch);
222
break;
223
224
case PUSH_DEFAULT_NOTHING: