From: Ramkumar Ramachandra Date: Wed, 06 Jul 2011 14:32:29 GMT Subject: Re: [PATCH 12/14] revert: Introduce --reset to cleanup sequencer data Message-ID: In-Reply-To: <1309938868-2028-13-git-send-email-artagnon@gmail.com> Hi, Ramkumar Ramachandra writes: >  builtin/revert.c                   |   54 ++++++++++++++++++++++++++++++----- >  git-rebase--interactive.sh         |   25 +++++++++++++--- >  t/t3032-merge-recursive-options.sh |    2 + >  t/t3501-revert-cherry-pick.sh      |    1 + >  t/t3502-cherry-pick-merge.sh       |    9 ++++- >  t/t3504-cherry-pick-rerere.sh      |    2 + >  t/t3505-cherry-pick-empty.sh       |   14 ++++----- >  t/t3506-cherry-pick-ff.sh          |    3 ++ >  t/t3507-cherry-pick-conflict.sh    |   24 ++++++++++++--- >  t/t3510-cherry-pick-sequence.sh    |   14 +++++++++ >  t/t7502-commit.sh                  |    1 + >  11 files changed, 121 insertions(+), 28 deletions(-) By making `reset --hard` blow away the sequencer state, and trying hard not to modify existing scripts, the diffstat still contains these files: builtin/revert.c git-rebase--interactive.sh t/t3032-merge-recursive-options.sh r/t3505-cherry-pick-empty.sh r/t3507-cherry-pick-conflict.sh r/t3501-cherry-pick-sequence.sh > diff --git a/t/t3032-merge-recursive-options.sh b/t/t3032-merge-recursive-options.sh > index 2b17311..81191ae 100755 > --- a/t/t3032-merge-recursive-options.sh > +++ b/t/t3032-merge-recursive-options.sh > @@ -113,8 +113,10 @@ test_expect_success '--ignore-space-change makes merge succeed' ' >  test_expect_success 'naive cherry-pick fails' ' >        git read-tree --reset -u HEAD && >        test_must_fail git cherry-pick --no-commit remote && > +       git cherry-pick --reset && >        git read-tree --reset -u HEAD && >        test_must_fail git cherry-pick remote && > +       git cherry-pick --reset && >        test_must_fail git update-index --refresh && >        grep "<<<<<<" text.txt >  ' > diff --git a/t/t3501-revert-cherry-pick.sh b/t/t3501-revert-cherry-pick.sh > index 595d2ff..e0c805d 100755 > --- a/t/t3501-revert-cherry-pick.sh > +++ b/t/t3501-revert-cherry-pick.sh > @@ -96,6 +96,7 @@ test_expect_success 'revert forbidden on dirty working tree' ' >        echo content >extra_file && >        git add extra_file && >        test_must_fail git revert HEAD 2>errors && > +       git revert --reset && >        test_i18ngrep "Your local changes would be overwritten by " errors > >  ' > diff --git a/t/t3505-cherry-pick-empty.sh b/t/t3505-cherry-pick-empty.sh > index c10b28c..dc02227 100755 > --- a/t/t3505-cherry-pick-empty.sh > +++ b/t/t3505-cherry-pick-empty.sh > @@ -23,10 +23,9 @@ test_expect_success setup ' >  ' > >  test_expect_success 'cherry-pick an empty commit' ' > -       git checkout master && { > -               git cherry-pick empty-branch^ > -               test "$?" = 1 > -       } > +       git checkout master && > +       test_expect_code 1 git cherry-pick empty-branch^ > +       git cherry-pick --reset >  ' > >  test_expect_success 'index lockfile was removed' ' > @@ -36,10 +35,9 @@ test_expect_success 'index lockfile was removed' ' >  ' > >  test_expect_success 'cherry-pick a commit with an empty message' ' > -       git checkout master && { > -               git cherry-pick empty-branch > -               test "$?" = 1 > -       } > +       git checkout master && > +       test_expect_code 1 git cherry-pick empty-branch && > +       git cherry-pick --reset >  ' > >  test_expect_success 'index lockfile was removed' ' > diff --git a/t/t3507-cherry-pick-conflict.sh b/t/t3507-cherry-pick-conflict.sh > index 212ec54..86f8626 100755 > --- a/t/t3507-cherry-pick-conflict.sh > +++ b/t/t3507-cherry-pick-conflict.sh > @@ -39,6 +39,7 @@ test_expect_success 'failed cherry-pick does not advance HEAD' ' > >        head=$(git rev-parse HEAD) && >        test_must_fail git cherry-pick picked && > +       git cherry-pick --reset && >        newhead=$(git rev-parse HEAD) && > >        test "$head" = "$newhead" > @@ -55,6 +56,7 @@ test_expect_success 'advice from failed cherry-pick' " >        hint: and commit the result with 'git commit' >        EOF >        test_must_fail git cherry-pick picked 2>actual && > +       git cherry-pick --reset && > >        test_i18ncmp expected actual >  " > @@ -62,7 +64,8 @@ test_expect_success 'advice from failed cherry-pick' " >  test_expect_success 'failed cherry-pick sets CHERRY_PICK_HEAD' ' >        pristine_detach initial && >        test_must_fail git cherry-pick picked && > -       test_cmp_rev picked CHERRY_PICK_HEAD > +       test_cmp_rev picked CHERRY_PICK_HEAD && > +       git cherry-pick --reset >  ' > >  test_expect_success 'successful cherry-pick does not set CHERRY_PICK_HEAD' ' > @@ -84,13 +87,15 @@ test_expect_success 'GIT_CHERRY_PICK_HELP suppresses CHERRY_PICK_HEAD' ' >                export GIT_CHERRY_PICK_HELP && >                test_must_fail git cherry-pick picked >        ) && > -       test_must_fail git rev-parse --verify CHERRY_PICK_HEAD > +       test_must_fail git rev-parse --verify CHERRY_PICK_HEAD && > +       git cherry-pick --reset >  ' > >  test_expect_success 'git reset clears CHERRY_PICK_HEAD' ' >        pristine_detach initial && > >        test_must_fail git cherry-pick picked && > +       git cherry-pick --reset && >        git reset && > >        test_must_fail git rev-parse --verify CHERRY_PICK_HEAD > @@ -102,7 +107,8 @@ test_expect_success 'failed commit does not clear CHERRY_PICK_HEAD' ' >        test_must_fail git cherry-pick picked && >        test_must_fail git commit && > > -       test_cmp_rev picked CHERRY_PICK_HEAD > +       test_cmp_rev picked CHERRY_PICK_HEAD && > +       git cherry-pick --reset >  ' > >  test_expect_success 'cancelled commit does not clear CHERRY_PICK_HEAD' ' > @@ -119,7 +125,8 @@ test_expect_success 'cancelled commit does not clear CHERRY_PICK_HEAD' ' >                test_must_fail git commit >        ) && > > -       test_cmp_rev picked CHERRY_PICK_HEAD > +       test_cmp_rev picked CHERRY_PICK_HEAD && > +       git cherry-pick --reset >  ' > >  test_expect_success 'successful commit clears CHERRY_PICK_HEAD' ' > @@ -130,13 +137,15 @@ test_expect_success 'successful commit clears CHERRY_PICK_HEAD' ' >        git add foo && >        git commit && > > -       test_must_fail git rev-parse --verify CHERRY_PICK_HEAD > +       test_must_fail git rev-parse --verify CHERRY_PICK_HEAD && > +       git cherry-pick --reset >  ' > >  test_expect_success 'failed cherry-pick produces dirty index' ' >        pristine_detach initial && > >        test_must_fail git cherry-pick picked && > +       git cherry-pick --reset && > >        test_must_fail git update-index --refresh -q && >        test_must_fail git diff-index --exit-code HEAD > @@ -160,6 +169,7 @@ test_expect_success 'failed cherry-pick registers participants in index' ' >        git read-tree -u --reset HEAD && > >        test_must_fail git cherry-pick picked && > +       git cherry-pick --reset && >        git ls-files --stage --unmerged > actual && > >        test_cmp expected actual > @@ -176,6 +186,7 @@ test_expect_success 'failed cherry-pick describes conflict in work tree' ' >        EOF > >        test_must_fail git cherry-pick picked && > +       git cherry-pick --reset && > >        sed "s/[a-f0-9]*\.\.\./objid/" foo > actual && >        test_cmp expected actual > @@ -195,6 +206,7 @@ test_expect_success 'diff3 -m style' ' >        EOF > >        test_must_fail git cherry-pick picked && > +       git cherry-pick --reset && > >        sed "s/[a-f0-9]*\.\.\./objid/" foo > actual && >        test_cmp expected actual > @@ -227,6 +239,7 @@ test_expect_success 'revert also handles conflicts sanely' ' > >        head=$(git rev-parse HEAD) && >        test_must_fail git revert picked && > +       git revert --reset && >        newhead=$(git rev-parse HEAD) && >        git ls-files --stage --unmerged > actual-stages && > > @@ -252,6 +265,7 @@ test_expect_success 'revert conflict, diff3 -m style' ' >        EOF > >        test_must_fail git revert picked && > +       git revert --reset && > >        sed "s/[a-f0-9]*\.\.\./objid/" foo > actual && >        test_cmp expected actual As you can see, there is no "reset --hard" in these, and I don't see what other command I can piggy-bank on to blow away the sequencer state. There is however, one other thing I can do: if there is nothing left to cherry-pick after a successful conflict resolution + git commit, I can modify commit.c to blow away the sequencer state after checking appropriately. This will also have a nice end-user experience side-effect: $ git cherry-pick moo fatal: Conflict in foo! $ echo "Resolved" > foo $ git add moo $ git commit $ git cherry-pick --continue # This no-op will be unnecessary Then again, teaching commit about the sequencer is inelegant, and it's possible to achieve this effect in another way: when a conflict is encountered in the sequencer && length(todo_file) == 1, throw away the sequencer state. When I say "throw away", I really mean "move .git/sequencer to .git/sequencer-old". Does this seem reasonable? -- Ram