From fd4a3f486d97682a0f42dfc84fe7af742bd76230 Mon Sep 17 00:00:00 2001 From: Phillip Wood Date: Wed, 2 Aug 2017 11:44:15 +0100 Subject: [PATCH 1/6] am: remember --rerere-autoupdate setting Save the rerere-autoupdate setting so that it is remembered after stopping for the user to resolve conflicts. Signed-off-by: Phillip Wood Signed-off-by: Junio C Hamano --- builtin/am.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/builtin/am.c b/builtin/am.c index c973bd96dc..6962d4db5f 100644 --- a/builtin/am.c +++ b/builtin/am.c @@ -431,6 +431,14 @@ static void am_load(struct am_state *state) read_state_file(&sb, state, "utf8", 1); state->utf8 = !strcmp(sb.buf, "t"); + if (file_exists(am_path(state, "rerere-autoupdate"))) { + read_state_file(&sb, state, "rerere-autoupdate", 1); + state->allow_rerere_autoupdate = strcmp(sb.buf, "t") ? + RERERE_NOAUTOUPDATE : RERERE_AUTOUPDATE; + } else { + state->allow_rerere_autoupdate = 0; + } + read_state_file(&sb, state, "keep", 1); if (!strcmp(sb.buf, "t")) state->keep = KEEP_TRUE; @@ -1003,6 +1011,10 @@ static void am_setup(struct am_state *state, enum patch_format patch_format, write_state_bool(state, "sign", state->signoff); write_state_bool(state, "utf8", state->utf8); + if (state->allow_rerere_autoupdate) + write_state_bool(state, "rerere-autoupdate", + state->allow_rerere_autoupdate == RERERE_AUTOUPDATE); + switch (state->keep) { case KEEP_FALSE: str = "f"; From 5fb415b57f93330b5ceb743ac36d99da10ac00b1 Mon Sep 17 00:00:00 2001 From: Phillip Wood Date: Wed, 2 Aug 2017 11:44:16 +0100 Subject: [PATCH 2/6] rebase: honor --rerere-autoupdate Rebase accepts '--rerere-autoupdate' as an option but only honors it if '-m' is also given. Fix it for a non-interactive rebase by passing on the option to 'git am' and 'git cherry-pick'. Rework the tests so that they can be used for each rebase flavor and extend them. Reported-by: Junio C Hamano Signed-off-by: Phillip Wood Signed-off-by: Junio C Hamano --- git-rebase--am.sh | 3 +- t/t3418-rebase-continue.sh | 82 +++++++++++++++++++++++++------------- 2 files changed, 57 insertions(+), 28 deletions(-) diff --git a/git-rebase--am.sh b/git-rebase--am.sh index 375239341f..319933e70a 100644 --- a/git-rebase--am.sh +++ b/git-rebase--am.sh @@ -45,7 +45,7 @@ then # itself well to recording empty patches. fortunately, cherry-pick # makes this easy git cherry-pick ${gpg_sign_opt:+"$gpg_sign_opt"} --allow-empty \ - --right-only "$revisions" \ + $allow_rerere_autoupdate --right-only "$revisions" \ ${restrict_revision+^$restrict_revision} ret=$? else @@ -82,6 +82,7 @@ else fi git am $git_am_opt --rebasing --resolvemsg="$resolvemsg" \ + $allow_rerere_autoupdate \ ${gpg_sign_opt:+"$gpg_sign_opt"} <"$GIT_DIR/rebased-patches" ret=$? diff --git a/t/t3418-rebase-continue.sh b/t/t3418-rebase-continue.sh index 4428b9086e..2b746f1559 100755 --- a/t/t3418-rebase-continue.sh +++ b/t/t3418-rebase-continue.sh @@ -40,25 +40,6 @@ test_expect_success 'non-interactive rebase --continue works with touched file' git rebase --continue ' -test_expect_success 'non-interactive rebase --continue with rerere enabled' ' - test_config rerere.enabled true && - test_when_finished "test_might_fail git rebase --abort" && - git reset --hard commit-new-file-F2-on-topic-branch && - git checkout master && - rm -fr .git/rebase-* && - - test_must_fail git rebase --onto master master topic && - echo "Resolved" >F2 && - git add F2 && - cp F2 F2.expected && - git rebase --continue && - - git reset --hard commit-new-file-F2-on-topic-branch && - git checkout master && - test_must_fail git rebase --onto master master topic && - test_cmp F2.expected F2 -' - test_expect_success 'rebase --continue can not be used with other options' ' test_must_fail git rebase -v --continue && test_must_fail git rebase --continue -v @@ -93,25 +74,72 @@ test_expect_success 'rebase --continue remembers merge strategy and options' ' test -f funny.was.run ' -test_expect_success 'rebase --continue remembers --rerere-autoupdate' ' +test_expect_success 'setup rerere database' ' rm -fr .git/rebase-* && git reset --hard commit-new-file-F3-on-topic-branch && git checkout master && test_commit "commit-new-file-F3" F3 3 && - git config rerere.enabled true && + test_config rerere.enabled true && test_must_fail git rebase -m master topic && echo "Resolved" >F2 && + cp F2 expected-F2 && git add F2 && test_must_fail git rebase --continue && echo "Resolved" >F3 && + cp F3 expected-F3 && git add F3 && git rebase --continue && - git reset --hard topic@{1} && - test_must_fail git rebase -m --rerere-autoupdate master && - test "$(cat F2)" = "Resolved" && - test_must_fail git rebase --continue && - test "$(cat F3)" = "Resolved" && - git rebase --continue + git reset --hard topic@{1} ' +prepare () { + rm -fr .git/rebase-* && + git reset --hard commit-new-file-F3-on-topic-branch && + git checkout master && + test_config rerere.enabled true +} + +test_rerere_autoupdate () { + action=$1 && + test_expect_success "rebase $action --continue remembers --rerere-autoupdate" ' + prepare && + test_must_fail git rebase $action --rerere-autoupdate master topic && + test_cmp expected-F2 F2 && + git diff-files --quiet && + test_must_fail git rebase --continue && + test_cmp expected-F3 F3 && + git diff-files --quiet && + git rebase --continue + ' + + test_expect_success "rebase $action --continue honors rerere.autoUpdate" ' + prepare && + test_config rerere.autoupdate true && + test_must_fail git rebase $action master topic && + test_cmp expected-F2 F2 && + git diff-files --quiet && + test_must_fail git rebase --continue && + test_cmp expected-F3 F3 && + git diff-files --quiet && + git rebase --continue + ' + + test_expect_success "rebase $action --continue remembers --no-rerere-autoupdate" ' + prepare && + test_config rerere.autoupdate true && + test_must_fail git rebase $action --no-rerere-autoupdate master topic && + test_cmp expected-F2 F2 && + test_must_fail git diff-files --quiet && + git add F2 && + test_must_fail git rebase --continue && + test_cmp expected-F3 F3 && + test_must_fail git diff-files --quiet && + git add F3 && + git rebase --continue + ' +} + +test_rerere_autoupdate +test_rerere_autoupdate -m + test_done From 9b6d7a6245e3be34a50a94a1174d8aebf5b1a263 Mon Sep 17 00:00:00 2001 From: Phillip Wood Date: Wed, 2 Aug 2017 11:44:17 +0100 Subject: [PATCH 3/6] rebase -i: honor --rerere-autoupdate Interactive rebase was ignoring '--rerere-autoupdate'. Fix this by reading it appropriate file when restoring the sequencer state for an interactive rebase and passing '--rerere-autoupdate' to merge and cherry-pick when rebasing with '--preserve-merges'. Reported-by: Junio C Hamano Signed-off-by: Phillip Wood Signed-off-by: Junio C Hamano --- git-rebase--interactive.sh | 7 ++++--- sequencer.c | 10 ++++++++++ t/t3418-rebase-continue.sh | 3 +++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh index 90b1fbe9cf..29b7e8824b 100644 --- a/git-rebase--interactive.sh +++ b/git-rebase--interactive.sh @@ -281,7 +281,7 @@ pick_one () { test -d "$rewritten" && pick_one_preserving_merges "$@" && return - output eval git cherry-pick \ + output eval git cherry-pick $allow_rerere_autoupdate \ ${gpg_sign_opt:+$(git rev-parse --sq-quote "$gpg_sign_opt")} \ "$strategy_args" $empty_args $ff "$@" @@ -393,7 +393,8 @@ pick_one_preserving_merges () { merge_args="--no-log --no-ff" if ! do_with_author output eval \ 'git merge ${gpg_sign_opt:+"$gpg_sign_opt"} \ - $merge_args $strategy_args -m "$msg_content" $new_parents' + $allow_rerere_autoupdate $merge_args \ + $strategy_args -m "$msg_content" $new_parents' then printf "%s\n" "$msg_content" > "$GIT_DIR"/MERGE_MSG die_with_patch $sha1 "$(eval_gettext "Error redoing merge \$sha1")" @@ -401,7 +402,7 @@ pick_one_preserving_merges () { echo "$sha1 $(git rev-parse HEAD^0)" >> "$rewritten_list" ;; *) - output eval git cherry-pick \ + output eval git cherry-pick $allow_rerere_autoupdate \ ${gpg_sign_opt:+$(git rev-parse --sq-quote "$gpg_sign_opt")} \ "$strategy_args" "$@" || die_with_patch $sha1 "$(eval_gettext "Could not pick \$sha1")" diff --git a/sequencer.c b/sequencer.c index 3010faf863..7dc0670d90 100644 --- a/sequencer.c +++ b/sequencer.c @@ -127,6 +127,7 @@ static GIT_PATH_FUNC(rebase_path_onto, "rebase-merge/onto") static GIT_PATH_FUNC(rebase_path_autostash, "rebase-merge/autostash") static GIT_PATH_FUNC(rebase_path_strategy, "rebase-merge/strategy") static GIT_PATH_FUNC(rebase_path_strategy_opts, "rebase-merge/strategy_opts") +static GIT_PATH_FUNC(rebase_path_allow_rerere_autoupdate, "rebase-merge/allow_rerere_autoupdate") static inline int is_rebase_i(const struct replay_opts *opts) { @@ -1479,6 +1480,15 @@ static int read_populate_opts(struct replay_opts *opts) free(opts->gpg_sign); opts->gpg_sign = xstrdup(buf.buf + 2); } + strbuf_reset(&buf); + } + + if (read_oneliner(&buf, rebase_path_allow_rerere_autoupdate(), 1)) { + if (!strcmp(buf.buf, "--rerere-autoupdate")) + opts->allow_rerere_auto = RERERE_AUTOUPDATE; + else if (!strcmp(buf.buf, "--no-rerere-autoupdate")) + opts->allow_rerere_auto = RERERE_NOAUTOUPDATE; + strbuf_reset(&buf); } if (file_exists(rebase_path_verbose())) diff --git a/t/t3418-rebase-continue.sh b/t/t3418-rebase-continue.sh index 2b746f1559..fcfdd197bd 100755 --- a/t/t3418-rebase-continue.sh +++ b/t/t3418-rebase-continue.sh @@ -141,5 +141,8 @@ test_rerere_autoupdate () { test_rerere_autoupdate test_rerere_autoupdate -m +GIT_SEQUENCE_EDITOR=: && export GIT_SEQUENCE_EDITOR +test_rerere_autoupdate -i +test_rerere_autoupdate --preserve-merges test_done From 6f0e577e46619a15baefc48192abee34451effa5 Mon Sep 17 00:00:00 2001 From: Phillip Wood Date: Wed, 2 Aug 2017 11:44:18 +0100 Subject: [PATCH 4/6] t3504: use test_commit Using test_commit is simpler than chaining echo && git add && test_tick && commit. Also having tags makes it clearer which commit is being selecting by reset. Signed-off-by: Phillip Wood Signed-off-by: Junio C Hamano --- t/t3504-cherry-pick-rerere.sh | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/t/t3504-cherry-pick-rerere.sh b/t/t3504-cherry-pick-rerere.sh index e6a64816ef..33f902b1b0 100755 --- a/t/t3504-cherry-pick-rerere.sh +++ b/t/t3504-cherry-pick-rerere.sh @@ -5,14 +5,11 @@ test_description='cherry-pick should rerere for conflicts' . ./test-lib.sh test_expect_success setup ' - echo foo >foo && - git add foo && test_tick && git commit -q -m 1 && - echo foo-master >foo && - git add foo && test_tick && git commit -q -m 2 && + test_commit foo && + test_commit foo-master foo && - git checkout -b dev HEAD^ && - echo foo-dev >foo && - git add foo && test_tick && git commit -q -m 3 && + git checkout -b dev foo && + test_commit foo-dev foo && git config rerere.enabled true ' @@ -21,10 +18,10 @@ test_expect_success 'conflicting merge' ' ' test_expect_success 'fixup' ' - echo foo-dev >foo && - git add foo && test_tick && git commit -q -m 4 && - git reset --hard HEAD^ && - echo foo-dev >expect + echo foo-resolved >foo && + git commit -am resolved && + cp foo expect && + git reset --hard HEAD^ ' test_expect_success 'cherry-pick conflict' ' From 8d8cb4b047cef546ea80b8224c7b33707f6d6a4c Mon Sep 17 00:00:00 2001 From: Phillip Wood Date: Wed, 2 Aug 2017 11:44:19 +0100 Subject: [PATCH 5/6] cherry-pick/revert: remember --rerere-autoupdate When continuing after conflicts, cherry-pick forgot if the user had specified '--rerere-autoupdate'. Redo the cherry-pick rerere tests to check --rerere-autoupdate works as expected. Signed-off-by: Phillip Wood Signed-off-by: Junio C Hamano --- sequencer.c | 10 +++++- t/t3504-cherry-pick-rerere.sh | 60 +++++++++++++++++++++++++++++++---- 2 files changed, 62 insertions(+), 8 deletions(-) diff --git a/sequencer.c b/sequencer.c index 7dc0670d90..e0e66b987b 100644 --- a/sequencer.c +++ b/sequencer.c @@ -1439,7 +1439,11 @@ static int populate_opts_cb(const char *key, const char *value, void *data) else if (!strcmp(key, "options.strategy-option")) { ALLOC_GROW(opts->xopts, opts->xopts_nr + 1, opts->xopts_alloc); opts->xopts[opts->xopts_nr++] = xstrdup(value); - } else + } else if (!strcmp(key, "options.allow-rerere-auto")) + opts->allow_rerere_auto = + git_config_bool_or_int(key, value, &error_flag) ? + RERERE_AUTOUPDATE : RERERE_NOAUTOUPDATE; + else return error(_("invalid key: %s"), key); if (!error_flag) @@ -1752,6 +1756,10 @@ static int save_opts(struct replay_opts *opts) "options.strategy-option", opts->xopts[i], "^$", 0); } + if (opts->allow_rerere_auto) + res |= git_config_set_in_file_gently(opts_file, "options.allow-rerere-auto", + opts->allow_rerere_auto == RERERE_AUTOUPDATE ? + "true" : "false"); return res; } diff --git a/t/t3504-cherry-pick-rerere.sh b/t/t3504-cherry-pick-rerere.sh index 33f902b1b0..af316cb40b 100755 --- a/t/t3504-cherry-pick-rerere.sh +++ b/t/t3504-cherry-pick-rerere.sh @@ -7,9 +7,11 @@ test_description='cherry-pick should rerere for conflicts' test_expect_success setup ' test_commit foo && test_commit foo-master foo && + test_commit bar-master bar && git checkout -b dev foo && test_commit foo-dev foo && + test_commit bar-dev bar && git config rerere.enabled true ' @@ -19,22 +21,66 @@ test_expect_success 'conflicting merge' ' test_expect_success 'fixup' ' echo foo-resolved >foo && + echo bar-resolved >bar && git commit -am resolved && - cp foo expect && + cp foo foo-expect && + cp bar bar-expect && git reset --hard HEAD^ ' -test_expect_success 'cherry-pick conflict' ' - test_must_fail git cherry-pick master && - test_cmp expect foo +test_expect_success 'cherry-pick conflict with --rerere-autoupdate' ' + test_must_fail git cherry-pick --rerere-autoupdate foo..bar-master && + test_cmp foo-expect foo && + git diff-files --quiet && + test_must_fail git cherry-pick --continue && + test_cmp bar-expect bar && + git diff-files --quiet && + git cherry-pick --continue && + git reset --hard bar-dev ' -test_expect_success 'reconfigure' ' - git config rerere.enabled false && - git reset --hard +test_expect_success 'cherry-pick conflict repsects rerere.autoUpdate' ' + test_config rerere.autoUpdate true && + test_must_fail git cherry-pick foo..bar-master && + test_cmp foo-expect foo && + git diff-files --quiet && + test_must_fail git cherry-pick --continue && + test_cmp bar-expect bar && + git diff-files --quiet && + git cherry-pick --continue && + git reset --hard bar-dev +' + +test_expect_success 'cherry-pick conflict with --no-rerere-autoupdate' ' + test_config rerere.autoUpdate true && + test_must_fail git cherry-pick --no-rerere-autoupdate foo..bar-master && + test_cmp foo-expect foo && + test_must_fail git diff-files --quiet && + git add foo && + test_must_fail git cherry-pick --continue && + test_cmp bar-expect bar && + test_must_fail git diff-files --quiet && + git add bar && + git cherry-pick --continue && + git reset --hard bar-dev +' + +test_expect_success 'cherry-pick --rerere-autoupdate more than once' ' + test_must_fail git cherry-pick --rerere-autoupdate --rerere-autoupdate foo..bar-master && + test_cmp foo-expect foo && + git diff-files --quiet && + git cherry-pick --abort && + test_must_fail git cherry-pick --rerere-autoupdate --no-rerere-autoupdate --rerere-autoupdate foo..bar-master && + test_cmp foo-expect foo && + git diff-files --quiet && + git cherry-pick --abort && + test_must_fail git cherry-pick --rerere-autoupdate --no-rerere-autoupdate foo..bar-master && + test_must_fail git diff-files --quiet && + git cherry-pick --abort ' test_expect_success 'cherry-pick conflict without rerere' ' + test_config rerere.enabled false && test_must_fail git cherry-pick master && test_must_fail test_cmp expect foo ' From f826fb799ed06f2f9537466f6988bcabd1200ebd Mon Sep 17 00:00:00 2001 From: Phillip Wood Date: Wed, 2 Aug 2017 11:44:20 +0100 Subject: [PATCH 6/6] cherry-pick/revert: reject --rerere-autoupdate when continuing cherry-pick and revert should not accept --[no-]rerere-autoupdate once they have started. Signed-off-by: Phillip Wood Signed-off-by: Junio C Hamano --- builtin/revert.c | 2 ++ t/t3504-cherry-pick-rerere.sh | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/builtin/revert.c b/builtin/revert.c index 16028b9ea8..b9d927eb09 100644 --- a/builtin/revert.c +++ b/builtin/revert.c @@ -155,6 +155,8 @@ static int run_sequencer(int argc, const char **argv, struct replay_opts *opts) "--strategy-option", opts->xopts ? 1 : 0, "-x", opts->record_origin, "--ff", opts->allow_ff, + "--rerere-autoupdate", opts->allow_rerere_auto == RERERE_AUTOUPDATE, + "--no-rerere-autoupdate", opts->allow_rerere_auto == RERERE_NOAUTOUPDATE, NULL); } diff --git a/t/t3504-cherry-pick-rerere.sh b/t/t3504-cherry-pick-rerere.sh index af316cb40b..a267b2d144 100755 --- a/t/t3504-cherry-pick-rerere.sh +++ b/t/t3504-cherry-pick-rerere.sh @@ -65,6 +65,19 @@ test_expect_success 'cherry-pick conflict with --no-rerere-autoupdate' ' git reset --hard bar-dev ' +test_expect_success 'cherry-pick --continue rejects --rerere-autoupdate' ' + test_must_fail git cherry-pick --rerere-autoupdate foo..bar-master && + test_cmp foo-expect foo && + git diff-files --quiet && + test_must_fail git cherry-pick --continue --rerere-autoupdate >actual 2>&1 && + echo "fatal: cherry-pick: --rerere-autoupdate cannot be used with --continue" >expect && + test_i18ncmp expect actual && + test_must_fail git cherry-pick --continue --no-rerere-autoupdate >actual 2>&1 && + echo "fatal: cherry-pick: --no-rerere-autoupdate cannot be used with --continue" >expect && + test_i18ncmp expect actual && + git cherry-pick --abort +' + test_expect_success 'cherry-pick --rerere-autoupdate more than once' ' test_must_fail git cherry-pick --rerere-autoupdate --rerere-autoupdate foo..bar-master && test_cmp foo-expect foo &&