summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--builtin/rebase.c5
-rwxr-xr-xt/t3400-rebase.sh18
2 files changed, 21 insertions, 2 deletions
diff --git a/builtin/rebase.c b/builtin/rebase.c
index 8081741..1c7d250 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'"),
diff --git a/t/t3400-rebase.sh b/t/t3400-rebase.sh
index 6e746dc..9aa5268 100755
--- a/t/t3400-rebase.sh
+++ b/t/t3400-rebase.sh
@@ -377,4 +377,22 @@ test_expect_success 'rebase -c rebase.useBuiltin=false warning' '
test_must_be_empty err
'
+test_expect_success 'switch to branch checked out here' '
+ git checkout master &&
+ git rebase master master
+'
+
+test_expect_success 'switch to branch not checked out' '
+ git checkout master &&
+ git branch other &&
+ git rebase master other
+'
+
+test_expect_success 'refuse to switch to branch checked out elsewhere' '
+ git checkout master &&
+ git worktree add wt &&
+ test_must_fail git -C wt rebase master master 2>err &&
+ test_i18ngrep "already checked out" err
+'
+
test_done