Mercurial > evolve
view tests/test-topic-mode.t @ 4687:313565dd75e3 stable
pick: remove transaction on the whole command (issue6037)
At its core, pick is a pretty straightforward and well-behaving command, it
uses functions already in core hg, it checks that wdir is clean and that
changeset to pick is not public, it checks if there happen to be merge
conflicts and can be --continue'd later, etc.
It is very similar to graft in core (it also uses mergemod.graft function), but
it obsoletes the original changeset. However, graft does not experience this
incorrect behavior from issue 6037.
What happens in the test case for this issue when we pick a revision that
touches both "a" and "b": mergemod.graft() takes the original changeset and
tries to apply it to the wdir, which results in "b" being marked as newly added
and ready to be committed, "a" updated with the new content and being marked as
modified, but "a" also has conflicts. Pick correctly notices this and saves its
state before asking for user intervention. So far so good. However, when the
command raises InterventionRequired to print a user-facing message and exit
while being wrapped in repo.transaction() context manager, the latter partially
undoes what mergemod.graft() did: it unmarks "b" as added. And when user
continues pick, "b" is therefore not tracked and is not included in the
resulting commit.
The transaction is not useful here, because it doesn't touch wdir (it's still
dirty), it doesn't remove pickstate (and other commands will refuse to work
until pick --abort or --continue), it just makes "b" untracked.
The solution is to use repo.transaction() only to wrap code that writes data to
hg store in the final stages of the command after all checks have passed and is
not expected to fail on trivial cases like merge conflicts. For example,
committing the picked changeset. But since pick uses repo.commit() for that,
and because that function already uses a transaction, wrapping it in another
transaction doesn't make sense.
author | Anton Shestakov <av6@dwimlabs.net> |
---|---|
date | Fri, 07 Jun 2019 18:14:48 +0800 |
parents | eb928f5728c4 |
children | f3713d41b85b dd68ce259708 |
line wrap: on
line source
$ . "$TESTDIR/testlib/topic_setup.sh" Testing the config knob to forbid untopiced commit ====================================================== $ hg init $TESTTMP/untopic-commit $ cd $TESTTMP/untopic-commit $ cat <<EOF >> .hg/hgrc > [phases] > publish=false > EOF $ cat <<EOF >> $HGRCPATH > [experimental] > topic-mode = enforce > EOF $ touch a b c d $ hg add a $ hg ci -m "Added a" abort: no active topic (see 'hg help -e topic.topic-mode' for details) [255] (same test, checking we abort before the editor) $ EDITOR=cat hg ci -m "Added a" --edit abort: no active topic (see 'hg help -e topic.topic-mode' for details) [255] $ hg ci -m "added a" --config experimental.topic-mode=ignore $ hg log changeset: 0:a154386e50d1 tag: tip user: test date: Thu Jan 01 00:00:00 1970 +0000 summary: added a Testing the config knob to warn about untopiced commit ========================================================== $ hg init $TESTTMP/untopic-warn-commit $ cd $TESTTMP/untopic-warn-commit $ cat <<EOF >> .hg/hgrc > [phases] > publish=false > EOF $ cat <<EOF >> $HGRCPATH > [experimental] > topic-mode = warning > EOF $ touch a b c d $ hg add a (same test, checking we abort before the editor) $ HGEDITOR=cat hg ci -m "Added a" --edit warning: new draft commit without topic (see 'hg help -e topic.topic-mode' for details) Added a HG: Enter commit message. Lines beginning with 'HG:' are removed. HG: Leave message empty to abort commit. HG: -- HG: user: test HG: branch 'default' HG: added a $ HGEDITOR=cat hg ci --amend -m "Added a" --edit Added a HG: Enter commit message. Lines beginning with 'HG:' are removed. HG: Leave message empty to abort commit. HG: -- HG: user: test HG: branch 'default' HG: added a $ hg ci --amend -m "added a'" --config experimental.topic-mode=ignore $ hg log changeset: 2:2e862d8b5eff tag: tip parent: -1:000000000000 user: test date: Thu Jan 01 00:00:00 1970 +0000 summary: added a' Testing the config knob to warn about untopiced merge commit ================================================================ $ hg init $TESTTMP/test-untopic-merge-commit $ cd $TESTTMP/test-untopic-merge-commit $ cat <<EOF >> .hg/hgrc > [phases] > publish=false > EOF $ cat <<EOF >> $HGRCPATH > [experimental] > topic-mode = enforce > EOF $ touch ROOT $ hg commit -A -m "ROOT" --config experimental.topic-mode=ignore adding ROOT $ touch a $ hg add a $ hg topic mytopic marked working directory as topic: mytopic $ hg ci -m "Added a" active topic 'mytopic' grew its first changeset (see 'hg help topics' for more information) $ hg up -r "desc('ROOT')" 0 files updated, 0 files merged, 1 files removed, 0 files unresolved $ touch default $ hg add default $ hg commit -m "default" --config experimental.topic-mode=ignore $ hg merge mytopic 1 files updated, 0 files merged, 0 files removed, 0 files unresolved (branch merge, don't forget to commit) $ hg commit -m "merge mytopic" warning: new draft commit without topic (see 'hg help -e topic.topic-mode' for details) $ hg log -G @ changeset: 3:676a445d1c09 |\ tag: tip | | parent: 2:a4da109ee59f | | parent: 1:e5b6c632bd8e | | user: test | | date: Thu Jan 01 00:00:00 1970 +0000 | | summary: merge mytopic | | | o changeset: 2:a4da109ee59f | | parent: 0:ec1d2790416d | | user: test | | date: Thu Jan 01 00:00:00 1970 +0000 | | summary: default | | o | changeset: 1:e5b6c632bd8e |/ topic: mytopic | user: test | date: Thu Jan 01 00:00:00 1970 +0000 | summary: Added a | o changeset: 0:ec1d2790416d user: test date: Thu Jan 01 00:00:00 1970 +0000 summary: ROOT Testing the config knob to about on untopiced merge commit ================================================================ $ hg init $TESTTMP/test-untopic-merge-commit-abort $ cd $TESTTMP/test-untopic-merge-commit-abort $ cat <<EOF >> .hg/hgrc > [phases] > publish=false > EOF $ cat <<EOF >> $HGRCPATH > [experimental] > topic-mode = enforce-all > EOF $ touch ROOT $ hg commit -A -m "ROOT" --config experimental.topic-mode=ignore adding ROOT $ touch a $ hg add a $ hg topic mytopic marked working directory as topic: mytopic $ hg ci -m "Added a" active topic 'mytopic' grew its first changeset (see 'hg help topics' for more information) $ hg up -r "desc('ROOT')" 0 files updated, 0 files merged, 1 files removed, 0 files unresolved $ touch default $ hg add default $ hg commit -m "default" --config experimental.topic-mode=ignore $ hg merge mytopic 1 files updated, 0 files merged, 0 files removed, 0 files unresolved (branch merge, don't forget to commit) $ hg commit -m "merge mytopic" abort: no active topic (see 'hg help -e topic.topic-mode' for details) [255] $ hg log -G @ changeset: 2:a4da109ee59f | tag: tip | parent: 0:ec1d2790416d | user: test | date: Thu Jan 01 00:00:00 1970 +0000 | summary: default | | @ changeset: 1:e5b6c632bd8e |/ topic: mytopic | user: test | date: Thu Jan 01 00:00:00 1970 +0000 | summary: Added a | o changeset: 0:ec1d2790416d user: test date: Thu Jan 01 00:00:00 1970 +0000 summary: ROOT Testing the config knob to use a random topic for untopic commit ==================================================================== $ hg init $TESTTMP/test-untopic-random $ cd $TESTTMP/test-untopic-random $ cat <<EOF >> .hg/hgrc > [phases] > publish=false > EOF $ cat <<EOF >> $HGRCPATH > [experimental] > topic-mode = random > EOF $ touch ROOT $ hg commit -A -m "ROOT" --config experimental.topic-mode=ignore adding ROOT $ touch A $ hg add A $ hg commit -m "Add A" --config devel.randomseed=42 active topic 'panoramic-antelope' grew its first changeset (see 'hg help topics' for more information) $ hg up -r "desc(ROOT)" 0 files updated, 0 files merged, 1 files removed, 0 files unresolved $ touch B $ hg add B $ hg commit -m "Add B" --config devel.randomseed=128 active topic 'various-dove' grew its first changeset (see 'hg help topics' for more information) Test a merge too $ hg phase --public -r . active topic 'various-dove' is now empty (use 'hg topic --clear' to clear it if needed) $ hg up default clearing empty topic "various-dove" 0 files updated, 0 files merged, 0 files removed, 0 files unresolved $ hg log -G @ changeset: 2:2d2acb6efad5 | tag: tip | parent: 0:ec1d2790416d | user: test | date: Thu Jan 01 00:00:00 1970 +0000 | summary: Add B | | o changeset: 1:d4b548f35972 |/ topic: panoramic-antelope | user: test | date: Thu Jan 01 00:00:00 1970 +0000 | summary: Add A | o changeset: 0:ec1d2790416d user: test date: Thu Jan 01 00:00:00 1970 +0000 summary: ROOT $ hg merge panoramic-antelope 1 files updated, 0 files merged, 0 files removed, 0 files unresolved (branch merge, don't forget to commit) $ hg ci -m 'merge' Testing the config knob to use a random topic for untopic commit (even for merge) ================================================================================= $ hg init $TESTTMP/test-untopic-random-all $ cd $TESTTMP/test-untopic-random-all $ cat <<EOF >> .hg/hgrc > [phases] > publish=false > EOF $ cat <<EOF >> $HGRCPATH > [experimental] > topic-mode = random-all > EOF $ touch ROOT $ hg commit -A -m "ROOT" --config experimental.topic-mode=ignore adding ROOT $ touch A $ hg add A $ hg commit -m "Add A" --config devel.randomseed=42 active topic 'panoramic-antelope' grew its first changeset (see 'hg help topics' for more information) $ hg up -r "desc(ROOT)" 0 files updated, 0 files merged, 1 files removed, 0 files unresolved $ touch B $ hg add B $ hg commit -m "Add B" --config devel.randomseed=128 active topic 'various-dove' grew its first changeset (see 'hg help topics' for more information) Test a merge too $ hg phase --public -r . active topic 'various-dove' is now empty (use 'hg topic --clear' to clear it if needed) $ hg up default clearing empty topic "various-dove" 0 files updated, 0 files merged, 0 files removed, 0 files unresolved $ hg log -G @ changeset: 2:2d2acb6efad5 | tag: tip | parent: 0:ec1d2790416d | user: test | date: Thu Jan 01 00:00:00 1970 +0000 | summary: Add B | | o changeset: 1:d4b548f35972 |/ topic: panoramic-antelope | user: test | date: Thu Jan 01 00:00:00 1970 +0000 | summary: Add A | o changeset: 0:ec1d2790416d user: test date: Thu Jan 01 00:00:00 1970 +0000 summary: ROOT $ hg merge panoramic-antelope 1 files updated, 0 files merged, 0 files removed, 0 files unresolved (branch merge, don't forget to commit) $ hg ci -m 'merge' --config devel.randomseed=1337 active topic 'omniscient-locust' grew its first changeset (see 'hg help topics' for more information)