From: Pratik Karki Date: Wed, 8 Aug 2018 15:36:30 +0000 (+0545) Subject: builtin rebase: optionally auto-detect the upstream X-Git-Tag: v2.20.0-rc0~90^2~5 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8f5986d95a9154d2ecbc4dd16b893380875cc83d;p=git builtin rebase: optionally auto-detect the upstream The `git rebase` command, when called without the `` command-line argument, automatically looks for the upstream branch configured for the current branch. With this commit, the builtin rebase learned that trick, too. Signed-off-by: Pratik Karki Signed-off-by: Junio C Hamano --- diff --git a/builtin/rebase.c b/builtin/rebase.c index b2cf779f1b..7e2f68eb28 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -622,6 +622,36 @@ static int parse_opt_interactive(const struct option *opt, const char *arg, return 0; } +static void NORETURN error_on_missing_default_upstream(void) +{ + struct branch *current_branch = branch_get(NULL); + + printf(_("%s\n" + "Please specify which branch you want to rebase against.\n" + "See git-rebase(1) for details.\n" + "\n" + " git rebase ''\n" + "\n"), + current_branch ? _("There is no tracking information for " + "the current branch.") : + _("You are not currently on a branch.")); + + if (current_branch) { + const char *remote = current_branch->remote_name; + + if (!remote) + remote = _(""); + + printf(_("If you wish to set tracking information for this " + "branch you can do so with:\n" + "\n" + " git branch --set-upstream-to=%s/ %s\n" + "\n"), + remote, current_branch->name); + } + exit(1); +} + int cmd_rebase(int argc, const char **argv, const char *prefix) { struct rebase_options options = { @@ -1057,9 +1087,17 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) } if (!options.root) { - if (argc < 1) - die("TODO: handle @{upstream}"); - else { + if (argc < 1) { + struct branch *branch; + + branch = branch_get(NULL); + options.upstream_name = branch_get_upstream(branch, + NULL); + if (!options.upstream_name) + error_on_missing_default_upstream(); + if (fork_point < 0) + fork_point = 1; + } else { options.upstream_name = argv[0]; argc--; argv++;