push: copy code to setup_push_simple()
In order to avoid doing unnecessary things and simplify it in further patches. In particular moving the additional name safety out of setup_push_upstream() and into setup_push_simple() and thus making both more straightforward. The code is copied exactly as-is; no functional changes. Reviewed-by: Elijah Newren <newren@gmail.com> Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Felipe Contreras committed
May 31, 2021 at 14:32 UTC
d099b9c9c723e8ca974e5ece027165e2824a1b89
1 file changed
+32
-4
builtin/push.c
+32
-4
@@ -225,10 +225,38 @@ static void setup_push_current(struct remote *remote, struct branch *branch)
225
226
static void setup_push_simple(struct remote *remote, struct branch *branch, int same_remote)
227
{
228
- if (!same_remote)
229
- setup_push_current(remote, branch);
230
- else
231
- setup_push_upstream(remote, branch, same_remote, 1);
228
+ if (!same_remote) {
229
+ if (!branch)
230
+ die(_(message_detached_head_die), remote->name);
231
+ refspec_appendf(&rs, "%s:%s", branch->refname, branch->refname);
232
+ } else {
233
+ if (!branch)
234
+ die(_(message_detached_head_die), remote->name);
235
+ if (!branch->merge_nr || !branch->merge || !branch->remote_name)
236
+ die(_("The current branch %s has no upstream branch.\n"
237
+ "To push the current branch and set the remote as upstream, use\n"
238
+ "\n"
239
+ " git push --set-upstream %s %s\n"),
240
+ branch->name,
241
+ remote->name,
242
+ branch->name);
243
+ if (branch->merge_nr != 1)
244
+ die(_("The current branch %s has multiple upstream branches, "
245
+ "refusing to push."), branch->name);
246
+ if (!same_remote)
247
+ die(_("You are pushing to remote '%s', which is not the upstream of\n"
248
+ "your current branch '%s', without telling me what to push\n"
249
+ "to update which remote branch."),
250
+ remote->name, branch->name);
251
+
252
+ if (1) {
253
+ /* Additional safety */
254
+ if (strcmp(branch->refname, branch->merge[0]->src))
255
+ die_push_simple(branch, remote);
256
+ }
257
+
258
+ refspec_appendf(&rs, "%s:%s", branch->refname, branch->merge[0]->src);
259
+ }
260
}
261
262
static int is_same_remote(struct remote *remote)