Skip to content

Commit 974bdb0

Browse files
committed
Merge branch 'bw/rebase-autostash-keep-current-branch'
"git rebase --autostash <upstream> <branch>", when <branch> is different from the current branch, incorrectly moved the tip of the current branch, which has been corrected. * bw/rebase-autostash-keep-current-branch: builtin/rebase.c: Remove pointless message builtin/rebase.c: make sure the active branch isn't moved when autostashing
2 parents 9755f70 + bf1e28e commit 974bdb0

File tree

2 files changed

+9
-16
lines changed

2 files changed

+9
-16
lines changed

builtin/rebase.c

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2002,9 +2002,6 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
20022002
state_dir_path("autostash", &options);
20032003
struct child_process stash = CHILD_PROCESS_INIT;
20042004
struct object_id oid;
2005-
struct commit *head =
2006-
lookup_commit_reference(the_repository,
2007-
&options.orig_head);
20082005

20092006
argv_array_pushl(&stash.args,
20102007
"stash", "create", "autostash", NULL);
@@ -2025,17 +2022,9 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
20252022
options.state_dir);
20262023
write_file(autostash, "%s", oid_to_hex(&oid));
20272024
printf(_("Created autostash: %s\n"), buf.buf);
2028-
if (reset_head(&head->object.oid, "reset --hard",
2025+
if (reset_head(NULL, "reset --hard",
20292026
NULL, RESET_HEAD_HARD, NULL, NULL) < 0)
20302027
die(_("could not reset --hard"));
2031-
printf(_("HEAD is now at %s"),
2032-
find_unique_abbrev(&head->object.oid,
2033-
DEFAULT_ABBREV));
2034-
strbuf_reset(&buf);
2035-
pp_commit_easy(CMIT_FMT_ONELINE, head, &buf);
2036-
if (buf.len > 0)
2037-
printf(" %s", buf.buf);
2038-
putchar('\n');
20392028

20402029
if (discard_index(the_repository->index) < 0 ||
20412030
repo_read_index(the_repository) < 0)

t/t3420-rebase-autostash.sh

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ test_expect_success setup '
3737
create_expected_success_am () {
3838
cat >expected <<-EOF
3939
$(grep "^Created autostash: [0-9a-f][0-9a-f]*\$" actual)
40-
HEAD is now at $(git rev-parse --short feature-branch) third commit
4140
First, rewinding head to replay your work on top of it...
4241
Applying: second commit
4342
Applying: third commit
@@ -48,7 +47,6 @@ create_expected_success_am () {
4847
create_expected_success_interactive () {
4948
q_to_cr >expected <<-EOF
5049
$(grep "^Created autostash: [0-9a-f][0-9a-f]*\$" actual)
51-
HEAD is now at $(git rev-parse --short feature-branch) third commit
5250
Applied autostash.
5351
Successfully rebased and updated refs/heads/rebased-feature-branch.
5452
EOF
@@ -57,7 +55,6 @@ create_expected_success_interactive () {
5755
create_expected_failure_am () {
5856
cat >expected <<-EOF
5957
$(grep "^Created autostash: [0-9a-f][0-9a-f]*\$" actual)
60-
HEAD is now at $(git rev-parse --short feature-branch) third commit
6158
First, rewinding head to replay your work on top of it...
6259
Applying: second commit
6360
Applying: third commit
@@ -70,7 +67,6 @@ create_expected_failure_am () {
7067
create_expected_failure_interactive () {
7168
cat >expected <<-EOF
7269
$(grep "^Created autostash: [0-9a-f][0-9a-f]*\$" actual)
73-
HEAD is now at $(git rev-parse --short feature-branch) third commit
7470
Applying autostash resulted in conflicts.
7571
Your changes are safe in the stash.
7672
You can run "git stash pop" or "git stash drop" at any time.
@@ -306,4 +302,12 @@ test_expect_success 'branch is left alone when possible' '
306302
test unchanged-branch = "$(git rev-parse --abbrev-ref HEAD)"
307303
'
308304

305+
test_expect_success 'never change active branch' '
306+
git checkout -b not-the-feature-branch unrelated-onto-branch &&
307+
test_when_finished "git reset --hard && git checkout master" &&
308+
echo changed >file0 &&
309+
git rebase --autostash not-the-feature-branch feature-branch &&
310+
test_cmp_rev not-the-feature-branch unrelated-onto-branch
311+
'
312+
309313
test_done

0 commit comments

Comments
 (0)