From 1df9bf46d656970d0db254cb7faab0d0505802e0 Mon Sep 17 00:00:00 2001 From: Jonathan Nieder Date: Sat, 10 Dec 2011 06:47:36 -0600 Subject: revert: give --continue handling its own function This makes pick_revisions() a little shorter and easier to read straight through. Signed-off-by: Jonathan Nieder Signed-off-by: Junio C Hamano diff --git a/builtin/revert.c b/builtin/revert.c index 1ea525c..9f6c85c 100644 --- a/builtin/revert.c +++ b/builtin/revert.c @@ -1038,6 +1038,21 @@ static int pick_commits(struct commit_list *todo_list, struct replay_opts *opts) return 0; } +static int sequencer_continue(struct replay_opts *opts) +{ + struct commit_list *todo_list = NULL; + + if (!file_exists(git_path(SEQ_TODO_FILE))) + return error(_("No %s in progress"), action_name(opts)); + read_populate_opts(&opts); + read_populate_todo(&todo_list, opts); + + /* Verify that the conflict has been resolved */ + if (!index_differs_from("HEAD", 0)) + todo_list = todo_list->next; + return pick_commits(todo_list, opts); +} + static int pick_revisions(struct replay_opts *opts) { struct commit_list *todo_list = NULL; @@ -1056,17 +1071,8 @@ static int pick_revisions(struct replay_opts *opts) } if (opts->subcommand == REPLAY_ROLLBACK) return sequencer_rollback(opts); - if (opts->subcommand == REPLAY_CONTINUE) { - if (!file_exists(git_path(SEQ_TODO_FILE))) - return error(_("No %s in progress"), action_name(opts)); - read_populate_opts(&opts); - read_populate_todo(&todo_list, opts); - - /* Verify that the conflict has been resolved */ - if (!index_differs_from("HEAD", 0)) - todo_list = todo_list->next; - return pick_commits(todo_list, opts); - } + if (opts->subcommand == REPLAY_CONTINUE) + return sequencer_continue(opts); /* * Start a new cherry-pick/ revert sequence; but -- cgit v0.10.2-6-g49f6 From 093a309136c38eca0ea2dd5da3c68b483443d113 Mon Sep 17 00:00:00 2001 From: Jonathan Nieder Date: Sat, 10 Dec 2011 06:49:25 -0600 Subject: revert: allow cherry-pick --continue to commit before resuming When "git cherry-pick ..bar" encounters conflicts, permit the operator to use cherry-pick --continue after resolving them as a shortcut for "git commit && git cherry-pick --continue" to record the resolution and carry on with the rest of the sequence. This improves the analogy with "git rebase" (in olden days --continue was the way to preserve authorship when a rebase encountered conflicts) and fits well with a general UI goal of making "git cmd --continue" save humans the trouble of deciding what to do next. Example: after encountering a conflict from running "git cherry-pick foo bar baz": CONFLICT (content): Merge conflict in main.c error: could not apply f78a8d98c... bar! hint: after resolving the conflicts, mark the corrected paths hint: with 'git add ' or 'git rm ' hint: and commit the result with 'git commit' We edit main.c to resolve the conflict, mark it acceptable with "git add main.c", and can run "cherry-pick --continue" to resume the sequence. $ git cherry-pick --continue [editor opens to confirm commit message] [master 78c8a8c98] bar! 1 files changed, 1 insertions(+), 1 deletions(-) [master 87ca8798c] baz! 1 files changed, 1 insertions(+), 1 deletions(-) This is done for both codepaths to pick multiple commits and a single commit. Signed-off-by: Jonathan Nieder Signed-off-by: Junio C Hamano diff --git a/builtin/revert.c b/builtin/revert.c index 9f6c85c..a43b4d8 100644 --- a/builtin/revert.c +++ b/builtin/revert.c @@ -1038,18 +1038,35 @@ static int pick_commits(struct commit_list *todo_list, struct replay_opts *opts) return 0; } +static int continue_single_pick(void) +{ + const char *argv[] = { "commit", NULL }; + + if (!file_exists(git_path("CHERRY_PICK_HEAD")) && + !file_exists(git_path("REVERT_HEAD"))) + return error(_("no cherry-pick or revert in progress")); + return run_command_v_opt(argv, RUN_GIT_CMD); +} + static int sequencer_continue(struct replay_opts *opts) { struct commit_list *todo_list = NULL; if (!file_exists(git_path(SEQ_TODO_FILE))) - return error(_("No %s in progress"), action_name(opts)); + return continue_single_pick(); read_populate_opts(&opts); read_populate_todo(&todo_list, opts); /* Verify that the conflict has been resolved */ - if (!index_differs_from("HEAD", 0)) - todo_list = todo_list->next; + if (file_exists(git_path("CHERRY_PICK_HEAD")) || + file_exists(git_path("REVERT_HEAD"))) { + int ret = continue_single_pick(); + if (ret) + return ret; + } + if (index_differs_from("HEAD", 0)) + return error_dirty_index(opts); + todo_list = todo_list->next; return pick_commits(todo_list, opts); } diff --git a/t/t3510-cherry-pick-sequence.sh b/t/t3510-cherry-pick-sequence.sh index 2c4c1c8..4d1883b 100755 --- a/t/t3510-cherry-pick-sequence.sh +++ b/t/t3510-cherry-pick-sequence.sh @@ -2,6 +2,7 @@ test_description='Test cherry-pick continuation features + + conflicting: rewrites unrelated to conflicting + yetanotherpick: rewrites foo to e + anotherpick: rewrites foo to d + picked: rewrites foo to c @@ -27,6 +28,7 @@ test_cmp_rev () { } test_expect_success setup ' + git config advice.detachedhead false echo unrelated >unrelated && git add unrelated && test_commit initial foo a && @@ -35,8 +37,8 @@ test_expect_success setup ' test_commit picked foo c && test_commit anotherpick foo d && test_commit yetanotherpick foo e && - git config advice.detachedhead false - + pristine_detach initial && + test_commit conflicting unrelated ' test_expect_success 'cherry-pick persists data on failure' ' @@ -243,7 +245,66 @@ test_expect_success '--continue complains when there are unresolved conflicts' ' test_must_fail git cherry-pick --continue ' -test_expect_success '--continue continues after conflicts are resolved' ' +test_expect_success '--continue of single cherry-pick' ' + pristine_detach initial && + echo c >expect && + test_must_fail git cherry-pick picked && + echo c >foo && + git add foo && + git cherry-pick --continue && + + test_cmp expect foo && + test_cmp_rev initial HEAD^ && + git diff --exit-code HEAD && + test_must_fail git rev-parse --verify CHERRY_PICK_HEAD +' + +test_expect_success '--continue of single revert' ' + pristine_detach initial && + echo resolved >expect && + echo "Revert \"picked\"" >expect.msg && + test_must_fail git revert picked && + echo resolved >foo && + git add foo && + git cherry-pick --continue && + + git diff --exit-code HEAD && + test_cmp expect foo && + test_cmp_rev initial HEAD^ && + git diff-tree -s --pretty=tformat:%s HEAD >msg && + test_cmp expect.msg msg && + test_must_fail git rev-parse --verify CHERRY_PICK_HEAD && + test_must_fail git rev-parse --verify REVERT_HEAD +' + +test_expect_success '--continue after resolving conflicts' ' + pristine_detach initial && + echo d >expect && + cat >expect.log <<-\EOF && + OBJID + :100644 100644 OBJID OBJID M foo + OBJID + :100644 100644 OBJID OBJID M foo + OBJID + :100644 100644 OBJID OBJID M unrelated + OBJID + :000000 100644 OBJID OBJID A foo + :000000 100644 OBJID OBJID A unrelated + EOF + test_must_fail git cherry-pick base..anotherpick && + echo c >foo && + git add foo && + git cherry-pick --continue && + { + git rev-list HEAD | + git diff-tree --root --stdin | + sed "s/$_x40/OBJID/g" + } >actual.log && + test_cmp expect foo && + test_cmp expect.log actual.log +' + +test_expect_success '--continue after resolving conflicts and committing' ' pristine_detach initial && test_must_fail git cherry-pick base..anotherpick && echo "c" >foo && @@ -270,6 +331,29 @@ test_expect_success '--continue continues after conflicts are resolved' ' test_cmp expect actual ' +test_expect_success '--continue asks for help after resolving patch to nil' ' + pristine_detach conflicting && + test_must_fail git cherry-pick initial..picked && + + test_cmp_rev unrelatedpick CHERRY_PICK_HEAD && + git checkout HEAD -- unrelated && + test_must_fail git cherry-pick --continue 2>msg && + test_i18ngrep "The previous cherry-pick is now empty" msg +' + +test_expect_failure 'follow advice and skip nil patch' ' + pristine_detach conflicting && + test_must_fail git cherry-pick initial..picked && + + git checkout HEAD -- unrelated && + test_must_fail git cherry-pick --continue && + git reset && + git cherry-pick --continue && + + git rev-list initial..HEAD >commits && + test_line_count = 3 commits +' + test_expect_success '--continue respects opts' ' pristine_detach initial && test_must_fail git cherry-pick -x base..anotherpick && @@ -288,6 +372,29 @@ test_expect_success '--continue respects opts' ' grep "cherry picked from" anotherpick_msg ' +test_expect_success '--continue of single-pick respects -x' ' + pristine_detach initial && + test_must_fail git cherry-pick -x picked && + echo c >foo && + git add foo && + git cherry-pick --continue && + test_path_is_missing .git/sequencer && + git cat-file commit HEAD >msg && + grep "cherry picked from" msg +' + +test_expect_success '--continue respects -x in first commit in multi-pick' ' + pristine_detach initial && + test_must_fail git cherry-pick -x picked anotherpick && + echo c >foo && + git add foo && + git cherry-pick --continue && + test_path_is_missing .git/sequencer && + git cat-file commit HEAD^ >msg && + picked=$(git rev-parse --verify picked) && + grep "cherry picked from.*$picked" msg +' + test_expect_success '--signoff is not automatically propagated to resolved conflict' ' pristine_detach initial && test_must_fail git cherry-pick --signoff base..anotherpick && @@ -306,6 +413,32 @@ test_expect_success '--signoff is not automatically propagated to resolved confl grep "Signed-off-by:" anotherpick_msg ' +test_expect_success '--signoff dropped for implicit commit of resolution, multi-pick case' ' + pristine_detach initial && + test_must_fail git cherry-pick -s picked anotherpick && + echo c >foo && + git add foo && + git cherry-pick --continue && + + git diff --exit-code HEAD && + test_cmp_rev initial HEAD^^ && + git cat-file commit HEAD^ >msg && + ! grep Signed-off-by: msg +' + +test_expect_success 'sign-off needs to be reaffirmed after conflict resolution, single-pick case' ' + pristine_detach initial && + test_must_fail git cherry-pick -s picked && + echo c >foo && + git add foo && + git cherry-pick --continue && + + git diff --exit-code HEAD && + test_cmp_rev initial HEAD^ && + git cat-file commit HEAD >msg && + ! grep Signed-off-by: msg +' + test_expect_success 'malformed instruction sheet 1' ' pristine_detach initial && test_must_fail git cherry-pick base..anotherpick && -- cgit v0.10.2-6-g49f6 From 7f13334e074bb053eccd14787e416306bc4b413a Mon Sep 17 00:00:00 2001 From: Jonathan Nieder Date: Sat, 13 Aug 2011 12:06:23 -0500 Subject: revert: pass around rev-list args in already-parsed form Since 7e2bfd3f (revert: allow cherry-picking more than one commit, 2010-07-02), the pick/revert machinery has kept track of the set of commits to be cherry-picked or reverted using commit_argc and commit_argv variables, storing the corresponding command-line parameters. Future callers as other commands are built in (am, rebase, sequencer) may find it easier to pass rev-list options to this machinery in already-parsed form. Teach cmd_cherry_pick and cmd_revert to parse the rev-list arguments in advance and pass the commit set to pick_revisions() as a rev_info structure. Original patch by Jonathan, tweaks and test from Ram. Signed-off-by: Jonathan Nieder Improved-by: Ramkumar Ramachandra Signed-off-by: Junio C Hamano diff --git a/builtin/revert.c b/builtin/revert.c index a43b4d8..f7f4bb3 100644 --- a/builtin/revert.c +++ b/builtin/revert.c @@ -60,13 +60,14 @@ struct replay_opts { int allow_rerere_auto; int mainline; - int commit_argc; - const char **commit_argv; /* Merge strategy */ const char *strategy; const char **xopts; size_t xopts_nr, xopts_alloc; + + /* Only used by REPLAY_NONE */ + struct rev_info *revs; }; #define GIT_REFLOG_ACTION "GIT_REFLOG_ACTION" @@ -169,9 +170,9 @@ static void parse_args(int argc, const char **argv, struct replay_opts *opts) die(_("program error")); } - opts->commit_argc = parse_options(argc, argv, NULL, options, usage_str, - PARSE_OPT_KEEP_ARGV0 | - PARSE_OPT_KEEP_UNKNOWN); + argc = parse_options(argc, argv, NULL, options, usage_str, + PARSE_OPT_KEEP_ARGV0 | + PARSE_OPT_KEEP_UNKNOWN); /* Check for incompatible subcommands */ verify_opt_mutually_compatible(me, @@ -213,9 +214,6 @@ static void parse_args(int argc, const char **argv, struct replay_opts *opts) NULL); } - else if (opts->commit_argc < 2) - usage_with_options(usage_str, options); - if (opts->allow_ff) verify_opt_compatible(me, "--ff", "--signoff", opts->signoff, @@ -223,7 +221,20 @@ static void parse_args(int argc, const char **argv, struct replay_opts *opts) "-x", opts->record_origin, "--edit", opts->edit, NULL); - opts->commit_argv = argv; + + if (opts->subcommand != REPLAY_NONE) { + opts->revs = NULL; + } else { + opts->revs = xmalloc(sizeof(*opts->revs)); + init_revisions(opts->revs, NULL); + opts->revs->no_walk = 1; + if (argc < 2) + usage_with_options(usage_str, options); + argc = setup_revisions(argc, argv, opts->revs, NULL); + } + + if (argc > 1) + usage_with_options(usage_str, options); } struct commit_message { @@ -631,23 +642,15 @@ static int do_pick_commit(struct commit *commit, struct replay_opts *opts) return res; } -static void prepare_revs(struct rev_info *revs, struct replay_opts *opts) +static void prepare_revs(struct replay_opts *opts) { - int argc; - - init_revisions(revs, NULL); - revs->no_walk = 1; if (opts->action != REVERT) - revs->reverse = 1; + opts->revs->reverse ^= 1; - argc = setup_revisions(opts->commit_argc, opts->commit_argv, revs, NULL); - if (argc > 1) - usage(*revert_or_cherry_pick_usage(opts)); - - if (prepare_revision_walk(revs)) + if (prepare_revision_walk(opts->revs)) die(_("revision walk setup failed")); - if (!revs->commits) + if (!opts->revs->commits) die(_("empty commit set passed")); } @@ -844,14 +847,13 @@ static void read_populate_opts(struct replay_opts **opts_ptr) static void walk_revs_populate_todo(struct commit_list **todo_list, struct replay_opts *opts) { - struct rev_info revs; struct commit *commit; struct commit_list **next; - prepare_revs(&revs, opts); + prepare_revs(opts); next = todo_list; - while ((commit = get_revision(&revs))) + while ((commit = get_revision(opts->revs))) next = commit_list_append(commit, next); } @@ -1075,6 +1077,9 @@ static int pick_revisions(struct replay_opts *opts) struct commit_list *todo_list = NULL; unsigned char sha1[20]; + if (opts->subcommand == REPLAY_NONE) + assert(opts->revs); + read_and_refresh_cache(opts); /* diff --git a/t/t3510-cherry-pick-sequence.sh b/t/t3510-cherry-pick-sequence.sh index 4d1883b..56c95ec 100755 --- a/t/t3510-cherry-pick-sequence.sh +++ b/t/t3510-cherry-pick-sequence.sh @@ -461,4 +461,9 @@ test_expect_success 'malformed instruction sheet 2' ' test_must_fail git cherry-pick --continue ' +test_expect_success 'empty commit set' ' + pristine_detach initial && + test_expect_code 128 git cherry-pick base..base +' + test_done -- cgit v0.10.2-6-g49f6 From 7acaaac275a1d338f7b2540779b7ea60f3f0667c Mon Sep 17 00:00:00 2001 From: Jonathan Nieder Date: Sat, 10 Dec 2011 06:59:48 -0600 Subject: revert: allow single-pick in the middle of cherry-pick sequence After messing up a difficult conflict resolution in the middle of a cherry-pick sequence, it can be useful to be able to git checkout HEAD . && git cherry-pick that-one-commit to restart the conflict resolution. The current code however errors out saying that another cherry-pick is already in progress. Suggested-by: Johannes Sixt Signed-off-by: Jonathan Nieder Signed-off-by: Junio C Hamano diff --git a/builtin/revert.c b/builtin/revert.c index f7f4bb3..5785ff9 100644 --- a/builtin/revert.c +++ b/builtin/revert.c @@ -1072,6 +1072,12 @@ static int sequencer_continue(struct replay_opts *opts) return pick_commits(todo_list, opts); } +static int single_pick(struct commit *cmit, struct replay_opts *opts) +{ + setenv(GIT_REFLOG_ACTION, action_name(opts), 0); + return do_pick_commit(cmit, opts); +} + static int pick_revisions(struct replay_opts *opts) { struct commit_list *todo_list = NULL; @@ -1097,6 +1103,26 @@ static int pick_revisions(struct replay_opts *opts) return sequencer_continue(opts); /* + * If we were called as "git cherry-pick ", just + * cherry-pick/revert it, set CHERRY_PICK_HEAD / + * REVERT_HEAD, and don't touch the sequencer state. + * This means it is possible to cherry-pick in the middle + * of a cherry-pick sequence. + */ + if (opts->revs->cmdline.nr == 1 && + opts->revs->cmdline.rev->whence == REV_CMD_REV && + opts->revs->no_walk && + !opts->revs->cmdline.rev->flags) { + struct commit *cmit; + if (prepare_revision_walk(opts->revs)) + die(_("revision walk setup failed")); + cmit = get_revision(opts->revs); + if (!cmit || get_revision(opts->revs)) + die("BUG: expected exactly one commit from walk"); + return single_pick(cmit, opts); + } + + /* * Start a new cherry-pick/ revert sequence; but * first, make sure that an existing one isn't in * progress diff --git a/t/t3510-cherry-pick-sequence.sh b/t/t3510-cherry-pick-sequence.sh index 56c95ec..98a27a23 100755 --- a/t/t3510-cherry-pick-sequence.sh +++ b/t/t3510-cherry-pick-sequence.sh @@ -50,6 +50,18 @@ test_expect_success 'cherry-pick persists data on failure' ' test_path_is_file .git/sequencer/opts ' +test_expect_success 'cherry-pick mid-cherry-pick-sequence' ' + pristine_detach initial && + test_must_fail git cherry-pick base..anotherpick && + test_cmp_rev picked CHERRY_PICK_HEAD && + # "oops, I forgot that these patches rely on the change from base" + git checkout HEAD foo && + git cherry-pick base && + git cherry-pick picked && + git cherry-pick --continue && + git diff --exit-code anotherpick +' + test_expect_success 'cherry-pick persists opts correctly' ' pristine_detach initial && test_must_fail git cherry-pick -s -m 1 --strategy=recursive -X patience -X ours base..anotherpick && -- cgit v0.10.2-6-g49f6 From 218b65fbf9428517e739b8bc26680c29910cf1cd Mon Sep 17 00:00:00 2001 From: Jonathan Nieder Date: Sat, 10 Dec 2011 07:02:12 -0600 Subject: revert: do not remove state until sequence is finished As v1.7.8-rc0~141^2~4 (2011-08-04) explains, git cherry-pick removes the sequencer state just before applying the final patch. In the single-pick case, that was a good thing, since --abort and --continue work fine without access to such state and removing it provides a signal that git should not complain about the need to clobber it ("a cherry-pick or revert is already in progress") in sequences like the following: git cherry-pick foo git read-tree -m -u HEAD; # forget that; let's try a different one git cherry-pick bar After the recent patch "allow single-pick in the middle of cherry-pick sequence" we don't need that hack any more. In the new regime, a traditional "git cherry-pick " command never looks at .git/sequencer, so we do not need to cripple "git cherry-pick .." for it any more. So now you can run "git cherry-pick --abort" near the end of a multi-pick sequence and it will abort the entire sequence, instead of misbehaving and aborting just the final commit. Signed-off-by: Jonathan Nieder Signed-off-by: Junio C Hamano diff --git a/builtin/revert.c b/builtin/revert.c index 5785ff9..5dcfa6b 100644 --- a/builtin/revert.c +++ b/builtin/revert.c @@ -1018,18 +1018,8 @@ static int pick_commits(struct commit_list *todo_list, struct replay_opts *opts) for (cur = todo_list; cur; cur = cur->next) { save_todo(cur, opts); res = do_pick_commit(cur->item, opts); - if (res) { - if (!cur->next) - /* - * An error was encountered while - * picking the last commit; the - * sequencer state is useless now -- - * the user simply needs to resolve - * the conflict and commit - */ - remove_sequencer_state(0); + if (res) return res; - } } /* diff --git a/t/t3510-cherry-pick-sequence.sh b/t/t3510-cherry-pick-sequence.sh index 98a27a23..851b147 100755 --- a/t/t3510-cherry-pick-sequence.sh +++ b/t/t3510-cherry-pick-sequence.sh @@ -203,10 +203,10 @@ test_expect_success '--abort refuses to clobber unrelated change, harder case' ' test_cmp_rev initial HEAD ' -test_expect_success 'cherry-pick cleans up sequencer state when one commit is left' ' +test_expect_success 'cherry-pick still writes sequencer state when one commit is left' ' pristine_detach initial && test_must_fail git cherry-pick base..picked && - test_path_is_missing .git/sequencer && + test_path_is_dir .git/sequencer && echo "resolved" >foo && git add foo && git commit && @@ -227,7 +227,7 @@ test_expect_success 'cherry-pick cleans up sequencer state when one commit is le test_cmp expect actual ' -test_expect_failure '--abort after last commit in sequence' ' +test_expect_success '--abort after last commit in sequence' ' pristine_detach initial && test_must_fail git cherry-pick base..picked && git cherry-pick --abort && -- cgit v0.10.2-6-g49f6 From a7eff1e027270062c4c08f11d63b4103f3d917fe Mon Sep 17 00:00:00 2001 From: Jonathan Nieder Date: Sat, 10 Dec 2011 07:03:48 -0600 Subject: Revert "reset: Make reset remove the sequencer state" This reverts commit 95eb88d8ee588d89b4f06d2753ed4d16ab13b39f, which was a UI experiment that did not reflect how "git reset" actually gets used. The reversion also fixes a test, indicated in the patch. Encouraged-by: Johannes Sixt Signed-off-by: Jonathan Nieder Signed-off-by: Junio C Hamano diff --git a/branch.c b/branch.c index 025a97b..a6b6722 100644 --- a/branch.c +++ b/branch.c @@ -3,7 +3,6 @@ #include "refs.h" #include "remote.h" #include "commit.h" -#include "sequencer.h" struct tracking { struct refspec spec; @@ -247,5 +246,4 @@ void remove_branch_state(void) unlink(git_path("MERGE_MSG")); unlink(git_path("MERGE_MODE")); unlink(git_path("SQUASH_MSG")); - remove_sequencer_state(0); } diff --git a/t/t3510-cherry-pick-sequence.sh b/t/t3510-cherry-pick-sequence.sh index 851b147..e80050e 100755 --- a/t/t3510-cherry-pick-sequence.sh +++ b/t/t3510-cherry-pick-sequence.sh @@ -353,7 +353,7 @@ test_expect_success '--continue asks for help after resolving patch to nil' ' test_i18ngrep "The previous cherry-pick is now empty" msg ' -test_expect_failure 'follow advice and skip nil patch' ' +test_expect_success 'follow advice and skip nil patch' ' pristine_detach conflicting && test_must_fail git cherry-pick initial..picked && diff --git a/t/t7106-reset-sequence.sh b/t/t7106-reset-sequence.sh deleted file mode 100755 index 83f7ea5..0000000 --- a/t/t7106-reset-sequence.sh +++ /dev/null @@ -1,52 +0,0 @@ -#!/bin/sh - -test_description='Test interaction of reset --hard with sequencer - - + anotherpick: rewrites foo to d - + picked: rewrites foo to c - + unrelatedpick: rewrites unrelated to reallyunrelated - + base: rewrites foo to b - + initial: writes foo as a, unrelated as unrelated -' - -. ./test-lib.sh - -pristine_detach () { - git cherry-pick --quit && - git checkout -f "$1^0" && - git read-tree -u --reset HEAD && - git clean -d -f -f -q -x -} - -test_expect_success setup ' - echo unrelated >unrelated && - git add unrelated && - test_commit initial foo a && - test_commit base foo b && - test_commit unrelatedpick unrelated reallyunrelated && - test_commit picked foo c && - test_commit anotherpick foo d && - git config advice.detachedhead false - -' - -test_expect_success 'reset --hard cleans up sequencer state, providing one-level undo' ' - pristine_detach initial && - test_must_fail git cherry-pick base..anotherpick && - test_path_is_dir .git/sequencer && - git reset --hard && - test_path_is_missing .git/sequencer && - test_path_is_dir .git/sequencer-old && - git reset --hard && - test_path_is_missing .git/sequencer-old -' - -test_expect_success 'cherry-pick --abort does not leave sequencer-old dir' ' - pristine_detach initial && - test_must_fail git cherry-pick base..anotherpick && - git cherry-pick --abort && - test_path_is_missing .git/sequencer && - test_path_is_missing .git/sequencer-old -' - -test_done -- cgit v0.10.2-6-g49f6 From d596118d7a9b104db10e64b2680a30ea80f1439c Mon Sep 17 00:00:00 2001 From: Jonathan Nieder Date: Sat, 10 Dec 2011 07:06:12 -0600 Subject: revert: stop creating and removing sequencer-old directory Now that "git reset" no longer implicitly removes .git/sequencer that the operator may or may not have wanted to keep, the logic to write a backup copy of .git/sequencer and remove it when stale is not needed any more. Simplify the sequencer API and repository layout by dropping it. Signed-off-by: Jonathan Nieder Signed-off-by: Junio C Hamano diff --git a/builtin/revert.c b/builtin/revert.c index 5dcfa6b..028bcbc 100644 --- a/builtin/revert.c +++ b/builtin/revert.c @@ -944,7 +944,7 @@ static int sequencer_rollback(struct replay_opts *opts) } if (reset_for_rollback(sha1)) goto fail; - remove_sequencer_state(1); + remove_sequencer_state(); strbuf_release(&buf); return 0; fail: @@ -1026,7 +1026,7 @@ static int pick_commits(struct commit_list *todo_list, struct replay_opts *opts) * Sequence of picks finished successfully; cleanup by * removing the .git/sequencer directory */ - remove_sequencer_state(1); + remove_sequencer_state(); return 0; } @@ -1084,7 +1084,7 @@ static int pick_revisions(struct replay_opts *opts) * one that is being continued */ if (opts->subcommand == REPLAY_REMOVE_STATE) { - remove_sequencer_state(1); + remove_sequencer_state(); return 0; } if (opts->subcommand == REPLAY_ROLLBACK) diff --git a/sequencer.c b/sequencer.c index bc2c046..d1f28a6 100644 --- a/sequencer.c +++ b/sequencer.c @@ -3,17 +3,11 @@ #include "strbuf.h" #include "dir.h" -void remove_sequencer_state(int aggressive) +void remove_sequencer_state(void) { struct strbuf seq_dir = STRBUF_INIT; - struct strbuf seq_old_dir = STRBUF_INIT; strbuf_addf(&seq_dir, "%s", git_path(SEQ_DIR)); - strbuf_addf(&seq_old_dir, "%s", git_path(SEQ_OLD_DIR)); - remove_dir_recursively(&seq_old_dir, 0); - rename(git_path(SEQ_DIR), git_path(SEQ_OLD_DIR)); - if (aggressive) - remove_dir_recursively(&seq_old_dir, 0); + remove_dir_recursively(&seq_dir, 0); strbuf_release(&seq_dir); - strbuf_release(&seq_old_dir); } diff --git a/sequencer.h b/sequencer.h index f435fdb..2d4528f 100644 --- a/sequencer.h +++ b/sequencer.h @@ -2,19 +2,11 @@ #define SEQUENCER_H #define SEQ_DIR "sequencer" -#define SEQ_OLD_DIR "sequencer-old" #define SEQ_HEAD_FILE "sequencer/head" #define SEQ_TODO_FILE "sequencer/todo" #define SEQ_OPTS_FILE "sequencer/opts" -/* - * Removes SEQ_OLD_DIR and renames SEQ_DIR to SEQ_OLD_DIR, ignoring - * any errors. Intended to be used by 'git reset'. - * - * With the aggressive flag, it additionally removes SEQ_OLD_DIR, - * ignoring any errors. Inteded to be used by the sequencer's - * '--quit' subcommand. - */ -void remove_sequencer_state(int aggressive); +/* Removes SEQ_DIR. */ +extern void remove_sequencer_state(void); #endif -- cgit v0.10.2-6-g49f6