diff options
author | Eric Sunshine <sunshine@sunshineco.com> | 2020-02-23 13:14:07 +0300 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2020-02-24 22:34:41 +0300 |
commit | b5cabb4a967fa455378ee7ddfa831a9bf0244753 (patch) | |
tree | ff679012db6fa875e43265ced26a6e1548872b1c /builtin | |
parent | df126ca14269efaf4d28453743a386be81ebec85 (diff) |
rebase: refuse to switch to branch already checked out elsewhere
The invocation "git rebase <upstream> <branch>" switches to <branch>
before performing the rebase operation. However, unlike git-switch,
git-checkout, and git-worktree which all refuse to switch to a branch
that is already checked out in some other worktree, git-rebase switches
to <branch> unconditionally. Curb this careless behavior by making
git-rebase also refuse to switch to a branch checked out elsewhere.
Reported-by: Mike Hommey <mh@glandium.org>
Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin')
-rw-r--r-- | builtin/rebase.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/builtin/rebase.c b/builtin/rebase.c index 8081741f8a..1c7d250ba3 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -1953,10 +1953,11 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) /* Is it a local branch? */ strbuf_reset(&buf); strbuf_addf(&buf, "refs/heads/%s", branch_name); - if (!read_ref(buf.buf, &options.orig_head)) + if (!read_ref(buf.buf, &options.orig_head)) { + die_if_checked_out(buf.buf, 1); options.head_name = xstrdup(buf.buf); /* If not is it a valid ref (branch or commit)? */ - else if (!get_oid(branch_name, &options.orig_head)) + } else if (!get_oid(branch_name, &options.orig_head)) options.head_name = NULL; else die(_("fatal: no such branch/commit '%s'"), |