Skip to content

Commit d099b9c

Browse files
felipecgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Felipe Contreras <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3b9fd83 commit d099b9c

File tree

1 file changed

+32
-4
lines changed

1 file changed

+32
-4
lines changed

builtin/push.c

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,38 @@ static void setup_push_current(struct remote *remote, struct branch *branch)
225225

226226
static void setup_push_simple(struct remote *remote, struct branch *branch, int same_remote)
227227
{
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+
}
232260
}
233261

234262
static int is_same_remote(struct remote *remote)

0 commit comments

Comments
 (0)