This patch series is the new second part of [1]. It borrows a few patches from v1, but it's mostly a ton of cleanups. In theory there should be no functional changes. There's too many changes to list them all, it's much easier to see the result: static const char *get_upstream_ref(struct branch *branch, const char *remote_name) { if (!branch->merge_nr || !branch->merge || !branch->remote_name) die(_("The current branch %s has no upstream branch.\n" "To push the current branch and set the remote as upstream, use\n" "\n" " git push --set-upstream %s %s\n"), branch->name, remote_name, branch->name); if (branch->merge_nr != 1) die(_("The current branch %s has multiple upstream branches, " "refusing to push."), branch->name); return branch->merge[0]->src; } static void setup_default_push_refspecs(struct remote *remote) { struct branch *branch; const char *dst; int same_remote; switch (push_default) { case PUSH_DEFAULT_MATCHING: refspec_append(&rs, ":"); return; case PUSH_DEFAULT_NOTHING: die(_("You didn't specify any refspecs to push, and " "push.default is \"nothing\".")); return; default: } branch = branch_get(NULL); if (!branch) die(_(message_detached_head_die), remote->name); dst = branch->refname; same_remote = !strcmp(remote->name, remote_for_branch(branch, NULL)); switch (push_default) { default: case PUSH_DEFAULT_UNSPECIFIED: case PUSH_DEFAULT_SIMPLE: if (!same_remote) break; if (strcmp(branch->refname, get_upstream_ref(branch, remote->name))) die_push_simple(branch, remote); break; case PUSH_DEFAULT_UPSTREAM: if (!same_remote) die(_("You are pushing to remote '%s', which is not the upstream of\n" "your current branch '%s', without telling me what to push\n" "to update which remote branch."), remote->name, branch->name); dst = get_upstream_ref(branch, remote->name); break; case PUSH_DEFAULT_CURRENT: break; } refspec_appendf(&rs, "%s:%s", branch->refname, dst); } [1] https://lore.kernel.org/git/20210529071115.1908310-1-felipe.contreras@xxxxxxxxx/ Felipe Contreras (15): push: create new get_upstream_ref() helper push: return immediately in trivial switch case push: reorder switch cases push: factor out null branch check push: only get the branch when needed push: make setup_push_* return the dst push: trivial simplifications push: get rid of all the setup_push_* functions push: factor out the typical case push: remove redundant check push: fix Yoda condition push: remove trivial function push: only get triangular when needed push: don't get a full remote object push: rename !triangular to same_remote builtin/push.c | 92 ++++++++++++++++++-------------------------------- 1 file changed, 33 insertions(+), 59 deletions(-) -- 2.32.0.rc0