strip: remove bookmarks after strip succeed (issue4295)
In case we have revs to strip, delete the bookmark after the strip succeeds, not
beforehand as we might still abort due to dirty working directory, etc.
--- a/hgext/strip.py Thu Jun 12 18:02:23 2014 -0700
+++ b/hgext/strip.py Tue Jul 08 16:24:23 2014 -0700
@@ -42,7 +42,7 @@
raise util.Abort(_("local changed subrepos found" + excsuffix))
return m, a, r, d
-def strip(ui, repo, revs, update=True, backup="all", force=None):
+def strip(ui, repo, revs, update=True, backup="all", force=None, bookmark=None):
wlock = lock = None
try:
wlock = repo.wlock()
@@ -59,6 +59,14 @@
repo.dirstate.write()
repair.strip(ui, repo, revs, backup)
+
+ marks = repo._bookmarks
+ if bookmark:
+ if bookmark == repo._bookmarkcurrent:
+ bookmarks.unsetcurrent(repo)
+ del marks[bookmark]
+ marks.write()
+ ui.write(_("bookmark '%s' deleted\n") % bookmark)
finally:
release(lock, wlock)
@@ -205,15 +213,9 @@
repo.dirstate.write()
update = False
- if opts.get('bookmark'):
- if mark == repo._bookmarkcurrent:
- bookmarks.unsetcurrent(repo)
- del marks[mark]
- marks.write()
- ui.write(_("bookmark '%s' deleted\n") % mark)
strip(ui, repo, revs, backup=backup, update=update,
- force=opts.get('force'))
+ force=opts.get('force'), bookmark=opts.get('bookmark'))
finally:
wlock.release()
--- a/tests/test-strip.t Thu Jun 12 18:02:23 2014 -0700
+++ b/tests/test-strip.t Tue Jul 08 16:24:23 2014 -0700
@@ -496,9 +496,9 @@
abort: empty revision set
[255]
$ hg strip -B todelete
- bookmark 'todelete' deleted
0 files updated, 0 files merged, 0 files removed, 0 files unresolved
saved backup bundle to $TESTTMP/bookmarks/.hg/strip-backup/*-backup.hg (glob)
+ bookmark 'todelete' deleted
$ hg id -ir dcbb326fdec2
abort: unknown revision 'dcbb326fdec2'!
[255]
@@ -508,10 +508,20 @@
B 9:ff43616e5d0f
delete 6:2702dd0c91e7
$ hg strip -B delete
+ saved backup bundle to $TESTTMP/bookmarks/.hg/strip-backup/*-backup.hg (glob)
bookmark 'delete' deleted
- saved backup bundle to $TESTTMP/bookmarks/.hg/strip-backup/*-backup.hg (glob)
$ hg id -ir 6:2702dd0c91e7
abort: unknown revision '2702dd0c91e7'!
[255]
+ $ hg update B
+ 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+ (activating bookmark B)
+ $ echo a > a
+ $ hg add a
+ $ hg strip -B B
+ abort: local changes found
+ [255]
+ $ hg bookmarks
+ * B 6:ff43616e5d0f
$ cd ..