Patchwork Make next/prev only move bookmarks optionally

login
register
mail settings
Submitter Ryan McElroy
Date Nov. 17, 2014, 9:06 p.m.
Message ID <e29a813f6af527d783bd.1416258394@devbig105.prn2.facebook.com>
Download mbox | patch
Permalink /patch/6770/
State Accepted
Headers show

Comments

Ryan McElroy - Nov. 17, 2014, 9:06 p.m.
# HG changeset patch
# User Ryan McElroy <rmcelroy@fb.com>
# Date 1414604048 25200
#      Wed Oct 29 10:34:08 2014 -0700
# Branch stable
# Node ID e29a813f6af527d783bdd8d8adf2214146340be3
# Parent  5951969400cec1a513cb07ea4a10cd356ea769ea
Make next/prev only move bookmarks optionally

Patch

diff --git a/hgext/evolve.py b/hgext/evolve.py
--- a/hgext/evolve.py
+++ b/hgext/evolve.py
@@ -1584,9 +1584,10 @@ 
 shorttemplate = '[{rev}] {desc|firstline}\n'
 
 @command('^previous',
-         [],
-         '')
-def cmdprevious(ui, repo):
+         [('B', 'move-bookmark', False,
+             _('Move current active bookmark after update'))],
+         '[-B]')
+def cmdprevious(ui, repo, **opts):
     """update to parent and display summary lines"""
     wkctx = repo[None]
     wparents = wkctx.parents()
@@ -1598,11 +1599,14 @@ 
     if len(parents) == 1:
         p = parents[0]
         bm = bookmarks.readcurrent(repo)
-        shouldmove = bm is not None and bookmarks.iscurrent(repo, bm)
+        shouldmove = opts.get('move_bookmark') and bm is not None
         ret = hg.update(repo, p.rev())
-        if not ret and shouldmove:
-            repo._bookmarks[bm] = p.node()
-            repo._bookmarks.write()
+        if not ret:
+            if shouldmove:
+                repo._bookmarks[bm] = p.node()
+                repo._bookmarks.write()
+            else:
+                bookmarks.unsetcurrent(repo)
         displayer.show(p)
         return 0
     else:
@@ -1612,9 +1616,10 @@ 
         return 1
 
 @command('^next',
-         [],
-         '')
-def cmdnext(ui, repo):
+         [('B', 'move-bookmark', False,
+             _('Move current active bookmark after update'))],
+         '[-B]')
+def cmdnext(ui, repo, **opts):
     """update to child and display summary lines"""
     wkctx = repo[None]
     wparents = wkctx.parents()
@@ -1629,11 +1634,14 @@ 
     if len(children) == 1:
         c = children[0]
         bm = bookmarks.readcurrent(repo)
-        shouldmove = bm is not None and bookmarks.iscurrent(repo, bm)
+        shouldmove = opts.get('move_bookmark') and bm is not None
         ret = hg.update(repo, c.rev())
-        if not ret and shouldmove:
-            repo._bookmarks[bm] = c.node()
-            repo._bookmarks.write()
+        if not ret:
+            if shouldmove:
+                repo._bookmarks[bm] = c.node()
+                repo._bookmarks.write()
+            else:
+                bookmarks.unsetcurrent(repo)
         displayer.show(c)
         return 0
     else:
diff --git a/tests/test-prev-next.t b/tests/test-prev-next.t
--- a/tests/test-prev-next.t
+++ b/tests/test-prev-next.t
@@ -5,7 +5,7 @@ 
   > EOF
   $ echo "evolve=$(echo $(dirname $TESTDIR))/hgext/evolve.py" >> $HGRCPATH
 
-hg prev should move active bookmark
+hg prev -B should move active bookmark
   $ hg init
   $ touch a
   $ hg add a
@@ -16,31 +16,53 @@ 
   $ hg bookmark mark
   $ hg bookmarks
    * mark                      1:6e742c9127b3
-  $ hg prev
+  $ hg prev -B
   0 files updated, 0 files merged, 1 files removed, 0 files unresolved
   [0] added a
   $ hg bookmarks
    * mark                      0:a154386e50d1
 
+hg next -B should move active bookmark
+  $ hg next -B
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  [1] added b
+  $ hg bookmarks
+   * mark                      1:6e742c9127b3
+
+hg prev should unset active bookmark
+  $ hg prev
+  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  [0] added a
+  $ hg bookmarks
+     mark                      1:6e742c9127b3
+
 hg next should move active bookmark
+  $ hg bookmark mark2
+  $ hg bookmarks
+     mark                      1:6e742c9127b3
+   * mark2                     0:a154386e50d1
   $ hg next
   1 files updated, 0 files merged, 0 files removed, 0 files unresolved
   [1] added b
   $ hg bookmarks
-   * mark                      1:6e742c9127b3
+     mark                      1:6e742c9127b3
+     mark2                     0:a154386e50d1
+
+  $ hg bookmark -d mark2
+  $ hg bookmark mark
 
 hg next/prev should not interfere with inactive bookmarks
   $ touch c
   $ hg add c
   $ hg commit -m 'added c'
   $ hg bookmark -r2 no-move
-  $ hg prev
+  $ hg prev -B
   0 files updated, 0 files merged, 1 files removed, 0 files unresolved
   [1] added b
   $ hg bookmarks
    * mark                      1:6e742c9127b3
      no-move                   2:4e26ef31f919
-  $ hg next
+  $ hg next -B
   1 files updated, 0 files merged, 0 files removed, 0 files unresolved
   [2] added c
   $ hg bookmarks
@@ -49,13 +71,13 @@ 
   $ hg up 1
   0 files updated, 0 files merged, 1 files removed, 0 files unresolved
   (leaving bookmark mark)
-  $ hg next
+  $ hg next -B
   1 files updated, 0 files merged, 0 files removed, 0 files unresolved
   [2] added c
   $ hg bookmarks
      mark                      2:4e26ef31f919
      no-move                   2:4e26ef31f919
-  $ hg prev
+  $ hg prev -B
   0 files updated, 0 files merged, 1 files removed, 0 files unresolved
   [1] added b
   $ hg bookmarks