Skip to content

Commit 6b010c8

Browse files
felipecgitster
authored andcommitted
push: reorganize setup_push_simple()
Simply move the code around and remove dead code. In particular the '!same_remote' conditional is a no-op since that part of the code is the same_remote leg of the conditional beforehand. No functional changes. Suggestions-by: Elijah Newren <[email protected]> Signed-off-by: Felipe Contreras <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d099b9c commit 6b010c8

File tree

1 file changed

+12
-17
lines changed

1 file changed

+12
-17
lines changed

builtin/push.c

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -225,13 +225,14 @@ 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+
const char *dst;
229+
230+
if (!branch)
231+
die(_(message_detached_head_die), remote->name);
232+
228233
if (!same_remote) {
229-
if (!branch)
230-
die(_(message_detached_head_die), remote->name);
231-
refspec_appendf(&rs, "%s:%s", branch->refname, branch->refname);
234+
dst = branch->refname;
232235
} else {
233-
if (!branch)
234-
die(_(message_detached_head_die), remote->name);
235236
if (!branch->merge_nr || !branch->merge || !branch->remote_name)
236237
die(_("The current branch %s has no upstream branch.\n"
237238
"To push the current branch and set the remote as upstream, use\n"
@@ -243,20 +244,14 @@ static void setup_push_simple(struct remote *remote, struct branch *branch, int
243244
if (branch->merge_nr != 1)
244245
die(_("The current branch %s has multiple upstream branches, "
245246
"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-
}
257247

258-
refspec_appendf(&rs, "%s:%s", branch->refname, branch->merge[0]->src);
248+
/* Additional safety */
249+
if (strcmp(branch->refname, branch->merge[0]->src))
250+
die_push_simple(branch, remote);
251+
252+
dst = branch->merge[0]->src;
259253
}
254+
refspec_appendf(&rs, "%s:%s", branch->refname, dst);
260255
}
261256

262257
static int is_same_remote(struct remote *remote)

0 commit comments

Comments
 (0)