From: Junio C Hamano Date: Sun, 18 Nov 2018 09:23:55 +0000 (+0900) Subject: Merge branch 'js/rebase-autostash-detach-fix' X-Git-Tag: v2.20.0-rc0~19 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/9aefd353804b744e05f253fb196029be620b26c0?ds=inline;hp=-c Merge branch 'js/rebase-autostash-detach-fix' "git rebase --autostash" did not correctly re-attach the HEAD at times. * js/rebase-autostash-detach-fix: built-in rebase --autostash: leave the current branch alone if possible built-in rebase: demonstrate regression with --autostash --- 9aefd353804b744e05f253fb196029be620b26c0 diff --combined builtin/rebase.c index b84568fc4e,d7239763c8..6db1b7cc56 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@@ -21,7 -21,6 +21,7 @@@ #include "diff.h" #include "wt-status.h" #include "revision.h" +#include "commit-reach.h" #include "rerere.h" static char const * const builtin_rebase_usage[] = { @@@ -613,7 -612,8 +613,8 @@@ static int reset_head(struct object_id reflog_head = msg.buf; } if (!switch_to_branch) - ret = update_ref(reflog_head, "HEAD", oid, orig, REF_NO_DEREF, + ret = update_ref(reflog_head, "HEAD", oid, orig, + detach_head ? REF_NO_DEREF : 0, UPDATE_REFS_MSG_ON_ERR); else { ret = create_symref("HEAD", switch_to_branch, msg.buf); @@@ -689,7 -689,7 +690,7 @@@ static int can_fast_forward(struct comm merge_bases = get_merge_bases(onto, head); if (merge_bases && !merge_bases->next) { oidcpy(merge_base, &merge_bases->item->object.oid); - res = !oidcmp(merge_base, &onto->object.oid); + res = oideq(merge_base, &onto->object.oid); } else { oidcpy(merge_base, &null_oid); res = 0; @@@ -703,9 -703,6 +704,9 @@@ static int parse_opt_merge(const struc { struct rebase_options *opts = opt->value; + BUG_ON_OPT_NEG(unset); + BUG_ON_OPT_ARG(arg); + if (!is_interactive(opts)) opts->type = REBASE_MERGE; @@@ -718,9 -715,6 +719,9 @@@ static int parse_opt_interactive(const { struct rebase_options *opts = opt->value; + BUG_ON_OPT_NEG(unset); + BUG_ON_OPT_ARG(arg); + opts->type = REBASE_INTERACTIVE; opts->flags |= REBASE_INTERACTIVE_EXPLICIT; @@@ -1224,15 -1218,15 +1225,15 @@@ int cmd_rebase(int argc, const char **a * git-rebase.txt caveats with "unless you know what you are doing" */ if (options.rebase_merges) - die(_("error: cannot combine '--preserve_merges' with " + die(_("error: cannot combine '--preserve-merges' with " "'--rebase-merges'")); if (options.rebase_merges) { if (strategy_options.nr) - die(_("error: cannot combine '--rebase_merges' with " + die(_("error: cannot combine '--rebase-merges' with " "'--strategy-option'")); if (options.strategy) - die(_("error: cannot combine '--rebase_merges' with " + die(_("error: cannot combine '--rebase-merges' with " "'--strategy'")); } diff --combined t/t3420-rebase-autostash.sh index f355c6825a,4e3d362d37..4c7494cc8f --- a/t/t3420-rebase-autostash.sh +++ b/t/t3420-rebase-autostash.sh @@@ -202,7 -202,7 +202,7 @@@ testrebase () echo dirty >>file3 && test_must_fail git rebase$type related-onto-branch && test_path_is_file $dotest/autostash && - ! grep dirty file3 && + test_path_is_missing file3 && rm -rf $dotest && git reset --hard && git checkout feature-branch @@@ -216,7 -216,7 +216,7 @@@ echo dirty >>file3 && test_must_fail git rebase$type related-onto-branch && test_path_is_file $dotest/autostash && - ! grep dirty file3 && + test_path_is_missing file3 && echo "conflicting-plus-goodbye" >file2 && git add file2 && git rebase --continue && @@@ -233,7 -233,7 +233,7 @@@ echo dirty >>file3 && test_must_fail git rebase$type related-onto-branch && test_path_is_file $dotest/autostash && - ! grep dirty file3 && + test_path_is_missing file3 && git rebase --skip && test_path_is_missing $dotest/autostash && grep dirty file3 && @@@ -248,7 -248,7 +248,7 @@@ echo dirty >>file3 && test_must_fail git rebase$type related-onto-branch && test_path_is_file $dotest/autostash && - ! grep dirty file3 && + test_path_is_missing file3 && git rebase --abort && test_path_is_missing $dotest/autostash && grep dirty file3 && @@@ -361,4 -361,12 +361,12 @@@ test_expect_success 'autostash with dir git rebase -i --autostash HEAD ' + test_expect_success 'branch is left alone when possible' ' + git checkout -b unchanged-branch && + echo changed >file0 && + git rebase --autostash unchanged-branch && + test changed = "$(cat file0)" && + test unchanged-branch = "$(git rev-parse --abbrev-ref HEAD)" + ' + test_done