fix evolve test
authorPierre-Yves David <pierre-yves.david@logilab.fr>
Fri, 17 Feb 2012 19:01:25 +0100
changeset 137 bbc653876876
parent 136 915728be8afd
child 138 605ed785268a
fix evolve test
hgext/evolve.py
tests/test-evolution.t
tests/test-evolve.t
--- a/hgext/evolve.py	Fri Feb 17 17:55:12 2012 +0100
+++ b/hgext/evolve.py	Fri Feb 17 19:01:25 2012 +0100
@@ -156,20 +156,34 @@
 cmdtable = {}
 command = cmdutil.command(cmdtable)
 
-@command('^evolve',
+@command('^stabilize',
     [],
     '')
-def evolve(ui, repo):
+def stabilize(ui, repo):
     """suggest the next evolution step"""
     obsolete = extensions.find('obsolete')
-    next = min(obsolete.unstables(repo))
+    unstable = repo.revs('unstable()')
+    if not unstable:
+        ui.write_err(_('no unstable changeset\n'))
+        return 1
+    next = unstable[0]
     obs = repo[next].parents()[0]
     if not obs.obsolete():
         obs = next.parents()[1]
     assert obs.obsolete()
     newer = obsolete.newerversion(repo, obs.node())
-    target = newer[-1]
-    repo.ui.status('hg relocate --rev %s %s\n' % (repo[next], repo[target]))
+    if len(newer) > 1:
+        ui.write_err(_("conflict rewriting. can't choose destination\n"))
+        return 2
+    targets = newer[0]
+    if not targets:
+        ui.write_err(_("does not handle kill parent yet\n"))
+        return 2
+    if len(targets) > 1:
+        ui.write_err(_("does not handle splitted parent yet\n"))
+        return 2
+    target = targets[0]
+    repo.ui.status('hg rebase -Dr %s -d %s\n' % (repo[next], repo[target]))
 
 shorttemplate = '[{rev}] {desc|firstline}\n'
 
@@ -355,15 +369,25 @@
         lock.release()
 
 def commitwrapper(orig, ui, repo, *arg, **kwargs):
-    obsoleted = kwargs.get('obsolete', [])
-    if obsoleted:
-        obsoleted = repo.set('%lr', obsoleted)
-    result = orig(ui, repo, *arg, **kwargs)
-    if not result: # commit successed
-        new = repo['-1']
-        for old in obsoleted:
-            repo.addobsolete(new.node(), old.node())
-    return result
+    lock = repo.lock()
+    try:
+        obsoleted = kwargs.get('obsolete', [])
+        if obsoleted:
+            obsoleted = repo.set('%lr', obsoleted)
+        result = orig(ui, repo, *arg, **kwargs)
+        if not result: # commit successed
+            new = repo['-1']
+            oldbookmarks = []
+            for old in obsoleted:
+                oldbookmarks.extend(repo.nodebookmarks(old.node()))
+                repo.addobsolete(new.node(), old.node())
+            for book in oldbookmarks:
+                repo._bookmarks[book] = new.node()
+            if oldbookmarks:
+                bookmarks.write(repo)
+        return result
+    finally:
+        lock.release()
 
 def graftwrapper(orig, ui, repo, *revs, **kwargs):
     lock = repo.lock()
--- a/tests/test-evolution.t	Fri Feb 17 17:55:12 2012 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,229 +0,0 @@
-  $ cat >> $HGRCPATH <<EOF
-  > [defaults]
-  > amend=-d "0 0"
-  > [web]
-  > push_ssl = false
-  > allow_push = *
-  > [phases]
-  > publish = False
-  > [alias]
-  > qlog = log --template='{rev} - {node|short} {desc} ({phase})\n'
-  > [diff]
-  > git = 1
-  > unified = 0
-  > [extensions]
-  > hgext.rebase=
-  > hgext.graphlog=
-  > EOF
-  $ echo "obsolete=$(echo $(dirname $TESTDIR))/hgext/obsolete.py" >> $HGRCPATH
-  $ echo "evolution=$(echo $(dirname $TESTDIR))/hgext/evolution.py" >> $HGRCPATH
-  $ mkcommit() {
-  >    echo "$1" > "$1"
-  >    hg add "$1"
-  >    hg ci -m "add $1"
-  > }
-
-various init
-
-  $ hg init local
-  $ cd local
-  $ mkcommit a
-  $ mkcommit b
-  $ cat >> .hg/hgrc << EOF
-  > [phases]
-  > publish = True
-  > EOF
-  $ hg pull -q . # make 1 public
-  $ rm .hg/hgrc
-  $ mkcommit c
-  $ mkcommit d
-  $ hg up 1
-  0 files updated, 0 files merged, 2 files removed, 0 files unresolved
-  $ mkcommit e -q
-  created new head
-  $ mkcommit f
-  $ hg qlog
-  5 - e44648563c73 add f (1)
-  4 - fbb94e3a0ecf add e (1)
-  3 - 47d2a3944de8 add d (1)
-  2 - 4538525df7e2 add c (1)
-  1 - 7c3bad9141dc add b (0)
-  0 - 1f0dee641bb7 add a (0)
-
-test simple kill
-
-  $ hg kill 5
-  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
-  working directory now at fbb94e3a0ecf
-  $ hg qlog
-  4 - fbb94e3a0ecf add e (1)
-  3 - 47d2a3944de8 add d (1)
-  2 - 4538525df7e2 add c (1)
-  1 - 7c3bad9141dc add b (0)
-  0 - 1f0dee641bb7 add a (0)
-
-test multiple kill
-
-  $ hg kill 4 3
-  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
-  working directory now at 7c3bad9141dc
-  $ hg qlog
-  2 - 4538525df7e2 add c (1)
-  1 - 7c3bad9141dc add b (0)
-  0 - 1f0dee641bb7 add a (0)
-  $ cd ..
-
-##########################
-importing Parren test
-##########################
-
-  $ cat << EOF >> $HGRCPATH
-  > [ui]
-  > logtemplate = "{rev}\t{bookmarks}: {desc|firstline} - {author|user}\n"
-  > EOF
-
-Creating And Updating Changeset
-===============================
-
-Setup the Base Repo
--------------------
-
-We start with a plain base repo::
-
-  $ hg init main; cd main
-  $ cat >main-file-1 <<-EOF
-  > One
-  > 
-  > Two
-  > 
-  > Three
-  > EOF
-  $ echo Two >main-file-2
-  $ hg add
-  adding main-file-1
-  adding main-file-2
-  $ hg commit --message base
-  $ cd ..
-
-and clone this into a new repo where we do our work::
-
-  $ hg clone main work
-  updating to branch default
-  2 files updated, 0 files merged, 0 files removed, 0 files unresolved
-  $ cd work
-
-
-Create First Patch
-------------------
-
-To begin with, we just do the changes that will be the initial version of the changeset::
-
-  $ echo One >file-from-A
-  $ sed -i'' -e s/One/Eins/ main-file-1
-  $ hg add file-from-A
-
-So this is what we would like our changeset to be::
-
-  $ hg diff
-  diff --git a/file-from-A b/file-from-A
-  new file mode 100644
-  --- /dev/null
-  +++ b/file-from-A
-  @@ -0,0 +1,1 @@
-  +One
-  diff --git a/main-file-1 b/main-file-1
-  --- a/main-file-1
-  +++ b/main-file-1
-  @@ -1,1 +1,1 @@
-  -One
-  +Eins
-
-To commit it we just - commit it::
-
-  $ hg commit --message "a nifty feature"
-
-and place a bookmark so we can easily refer to it again (which we could have done before the commit)::
-
-  $ hg book feature-A
-
-
-Create Second Patch
--------------------
-
-Let's do this again for the second changeset::
-
-  $ echo Two >file-from-B
-  $ sed -i'' -e s/Two/Zwie/ main-file-1
-  $ hg add file-from-B
-
-Before committing, however, we need to switch to a new bookmark for the second
-changeset. Otherwise we would inadvertently move the bookmark for our first changeset.
-It is therefore advisable to always set the bookmark before committing::
-
-  $ hg book feature-B
-  $ hg commit --message "another feature"
-
-So here we are::
-
-  $ hg book
-     feature-A                 1:568a468b60fc
-   * feature-B                 2:7b36850622b2
-
-
-Fix The Second Patch
---------------------
-
-There's a typo in feature-B. We spelled *Zwie* instead of *Zwei*::
-
-  $ hg diff --change tip | grep -F Zwie
-  +Zwie
-
-Fixing this is very easy. Just change::
-
-  $ sed -i'' -e s/Zwie/Zwei/ main-file-1
-
-and **amend**::
-
-  $ hg amend --note "fix spelling of Zwei"
-
-The `--note` is our commit message for the *update* only. So its only purpose
-is to document the evolution of the changeset. If we use `--message` with
-`amend`, it replaces the commit message of the changeset itself.
-
-This results in a new single changeset for our amended changeset, and the old
-changeset plus the updating changeset are hidden from view by default::
-
-  $ hg log
-  4	feature-B: another feature - test
-  1	feature-A: a nifty feature - test
-  0	: base - test
-
-  $ hg up feature-A -q
-  $ sed -i'' -e s/Eins/Un/ main-file-1
-
-  $ hg amend --note 'french looks better'
-  $ hg log
-  6	feature-A: a nifty feature - test
-  4	feature-B: another feature - test
-  1	: a nifty feature - test
-  0	: base - test
-  $ hg evolve
-  hg relocate --rev f8111a076f09 23409eba69a0
-  $ hg up feature-B -q #prevent feature-A bookmark to move grml
-  $ hg relocate -r 4 6 --traceback
-  merging main-file-1
-  $ hg log
-  7	feature-B: another feature - test
-  6	feature-A: a nifty feature - test
-  0	: base - test
-
-Test commit -o options
-
-  $ hg up 6
-  $ hg revert -r 7 --all
-  $ sed -i'' -e s/Zwei/deux/ main-file-1
-  $ hg commit -m 'Feature B' -o 7
-  $ hg log
-  8	feature-B: another feature - test
-  6	feature-A: a nifty feature - test
-  0	: base - test
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-evolve.t	Fri Feb 17 19:01:25 2012 +0100
@@ -0,0 +1,244 @@
+  $ cat >> $HGRCPATH <<EOF
+  > [defaults]
+  > amend=-d "0 0"
+  > [web]
+  > push_ssl = false
+  > allow_push = *
+  > [phases]
+  > publish = False
+  > [alias]
+  > qlog = log --template='{rev} - {node|short} {desc} ({phase})\n'
+  > [diff]
+  > git = 1
+  > unified = 0
+  > [extensions]
+  > hgext.rebase=
+  > hgext.graphlog=
+  > EOF
+  $ echo "obsolete=$(echo $(dirname $TESTDIR))/hgext/obsolete.py" >> $HGRCPATH
+  $ echo "evolve=$(echo $(dirname $TESTDIR))/hgext/evolve.py" >> $HGRCPATH
+  $ mkcommit() {
+  >    echo "$1" > "$1"
+  >    hg add "$1"
+  >    hg ci -m "add $1"
+  > }
+
+various init
+
+  $ hg init local
+  $ cd local
+  $ mkcommit a
+  $ mkcommit b
+  $ cat >> .hg/hgrc << EOF
+  > [phases]
+  > publish = True
+  > EOF
+  $ hg pull -q . # make 1 public
+  $ rm .hg/hgrc
+  $ mkcommit c
+  $ mkcommit d
+  $ hg up 1
+  0 files updated, 0 files merged, 2 files removed, 0 files unresolved
+  $ mkcommit e -q
+  created new head
+  $ mkcommit f
+  $ hg qlog
+  5 - e44648563c73 add f (draft)
+  4 - fbb94e3a0ecf add e (draft)
+  3 - 47d2a3944de8 add d (draft)
+  2 - 4538525df7e2 add c (draft)
+  1 - 7c3bad9141dc add b (public)
+  0 - 1f0dee641bb7 add a (public)
+
+test simple kill
+
+  $ hg kill 5
+  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  working directory now at fbb94e3a0ecf
+  $ hg qlog
+  4 - fbb94e3a0ecf add e (draft)
+  3 - 47d2a3944de8 add d (draft)
+  2 - 4538525df7e2 add c (draft)
+  1 - 7c3bad9141dc add b (public)
+  0 - 1f0dee641bb7 add a (public)
+
+test multiple kill
+
+  $ hg kill 4 3
+  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  working directory now at 7c3bad9141dc
+  $ hg qlog
+  2 - 4538525df7e2 add c (draft)
+  1 - 7c3bad9141dc add b (public)
+  0 - 1f0dee641bb7 add a (public)
+  $ cd ..
+
+##########################
+importing Parren test
+##########################
+
+  $ cat << EOF >> $HGRCPATH
+  > [ui]
+  > logtemplate = "{rev}\t{bookmarks}: {desc|firstline} - {author|user}\n"
+  > EOF
+
+Creating And Updating Changeset
+===============================
+
+Setup the Base Repo
+-------------------
+
+We start with a plain base repo::
+
+  $ hg init main; cd main
+  $ cat >main-file-1 <<-EOF
+  > One
+  > 
+  > Two
+  > 
+  > Three
+  > EOF
+  $ echo Two >main-file-2
+  $ hg add
+  adding main-file-1
+  adding main-file-2
+  $ hg commit --message base
+  $ cd ..
+
+and clone this into a new repo where we do our work::
+
+  $ hg clone main work
+  updating to branch default
+  2 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ cd work
+
+
+Create First Patch
+------------------
+
+To begin with, we just do the changes that will be the initial version of the changeset::
+
+  $ echo One >file-from-A
+  $ sed -i'' -e s/One/Eins/ main-file-1
+  $ hg add file-from-A
+
+So this is what we would like our changeset to be::
+
+  $ hg diff
+  diff --git a/file-from-A b/file-from-A
+  new file mode 100644
+  --- /dev/null
+  +++ b/file-from-A
+  @@ -0,0 +1,1 @@
+  +One
+  diff --git a/main-file-1 b/main-file-1
+  --- a/main-file-1
+  +++ b/main-file-1
+  @@ -1,1 +1,1 @@
+  -One
+  +Eins
+
+To commit it we just - commit it::
+
+  $ hg commit --message "a nifty feature"
+
+and place a bookmark so we can easily refer to it again (which we could have done before the commit)::
+
+  $ hg book feature-A
+
+
+Create Second Patch
+-------------------
+
+Let's do this again for the second changeset::
+
+  $ echo Two >file-from-B
+  $ sed -i'' -e s/Two/Zwie/ main-file-1
+  $ hg add file-from-B
+
+Before committing, however, we need to switch to a new bookmark for the second
+changeset. Otherwise we would inadvertently move the bookmark for our first changeset.
+It is therefore advisable to always set the bookmark before committing::
+
+  $ hg book feature-B
+  $ hg commit --message "another feature"
+
+So here we are::
+
+  $ hg book
+     feature-A                 1:568a468b60fc
+   * feature-B                 2:7b36850622b2
+
+
+Fix The Second Patch
+--------------------
+
+There's a typo in feature-B. We spelled *Zwie* instead of *Zwei*::
+
+  $ hg diff --change tip | grep -F Zwie
+  +Zwie
+
+Fixing this is very easy. Just change::
+
+  $ sed -i'' -e s/Zwie/Zwei/ main-file-1
+
+and **amend**::
+
+  $ hg amend --note "fix spelling of Zwei"
+
+The `--note` is our commit message for the *update* only. So its only purpose
+is to document the evolution of the changeset. If we use `--message` with
+`amend`, it replaces the commit message of the changeset itself.
+
+This results in a new single changeset for our amended changeset, and the old
+changeset plus the updating changeset are hidden from view by default::
+
+  $ hg log
+  4	feature-B: another feature - test
+  1	feature-A: a nifty feature - test
+  0	: base - test
+
+  $ hg up feature-A -q
+  $ sed -i'' -e s/Eins/Un/ main-file-1
+
+  $ hg amend --note 'french looks better'
+  $ hg log
+  6	feature-A: a nifty feature - test
+  4	feature-B: another feature - test
+  1	: a nifty feature - test
+  0	: base - test
+  $ hg stabilize
+  hg rebase -Dr f8111a076f09 -d 23409eba69a0
+  $ hg up null -q #prevent feature-A bookmark to move # XXX grml
+  $ hg bookmark
+     feature-A                 6:23409eba69a0
+     feature-B                 4:f8111a076f09
+  $ hg up 6
+  3 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ hg bookmark
+     feature-A                 6:23409eba69a0
+     feature-B                 4:f8111a076f09
+  $ hg bookmark -if feature-A
+  $ hg graft -O 4
+  grafting revision 4
+  merging main-file-1
+  $ hg bookmark -ifr 7 feature-B # XXX not bookmark support in rebase --keep :-/
+  $ hg log
+  7	feature-B: another feature - test
+  6	feature-A: a nifty feature - test
+  0	: base - test
+
+Test commit -o options
+
+  $ hg up 6
+  1 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  $ hg revert -r 7 --all
+  adding file-from-B
+  reverting main-file-1
+  $ sed -i'' -e s/Zwei/deux/ main-file-1
+  $ hg commit -m 'another feature that rox' -o 7
+  created new head
+  $ hg log
+  8	feature-B: another feature that rox - test
+  6	feature-A: a nifty feature - test
+  0	: base - test