Merge branch 'js/rebase-autostash-detach-fix'
authorJunio C Hamano <gitster@pobox.com>
Sun, 18 Nov 2018 09:23:55 +0000 (18:23 +0900)
committerJunio C Hamano <gitster@pobox.com>
Sun, 18 Nov 2018 09:23:55 +0000 (18:23 +0900)
"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

1  2 
builtin/rebase.c
t/t3420-rebase-autostash.sh
diff --combined builtin/rebase.c
index b84568fc4e6677e5f68c3b11e0798942ae19577a,d7239763c8096c88801ac03fb6250e7cd0517a12..6db1b7cc56fb274f56ba311f79296e9f2a373cd7
@@@ -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'"));
        }
  
index f355c6825a4a5ff6adef656c432a4e2fdaf0fea9,4e3d362d37b92177d31b71749f1cca4ddb5ad572..4c7494cc8f77a3ff92373cb130974825c4418ada
@@@ -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
                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 &&
                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 &&
                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