[PATCH V10] update: fix bare --clean to work on new branch (issue5003) (BC)

liscju piotr.listkiewicz at gmail.com
Wed Apr 20 07:53:20 UTC 2016


# HG changeset patch
# User liscju <piotr.listkiewicz at gmail.com>
# Date 1459834201 -7200
#      Tue Apr 05 07:30:01 2016 +0200
# Branch stable
# Node ID fed812b73ca807061f484aa16eb5ca5383ad9b85
# Parent  97811ff7964710d32cae951df1da8019b46151a2
update: fix bare --clean to work on new branch (issue5003) (BC)

Before this commit bare update --clean on newly created branch
updates to the parent commit, even if there are later commits
on the parent commit's branch. Update to the latest head on the
parent commit's branch instead.

This seems reasonable as clean should discard uncommited changes,
branch is one of them.

diff -r 97811ff79647 -r fed812b73ca8 mercurial/destutil.py
--- a/mercurial/destutil.py	Sat Mar 26 18:50:56 2016 +0900
+++ b/mercurial/destutil.py	Tue Apr 05 07:30:01 2016 +0200
@@ -95,7 +95,16 @@ def _destupdatebranch(repo, clean, check
     wc = repo[None]
     movemark = node = None
     currentbranch = wc.branch()
-    if currentbranch in repo.branchmap():
+
+    if clean:
+        parentbranch = repo['.'].branch()
+        heads = repo.branchheads(parentbranch)
+        if heads:
+            node = repo.revs('max(.::(%ln))', heads).first()
+            if currentbranch not in repo.branchmap():
+                repo.ui.warn(_('updating to the head of parent branch %s\n')
+                             % parentbranch)
+    elif currentbranch in repo.branchmap():
         heads = repo.branchheads(currentbranch)
         if heads:
             node = repo.revs('max(.::(%ln))', heads).first()
diff -r 97811ff79647 -r fed812b73ca8 tests/test-newbranch.t
--- a/tests/test-newbranch.t	Sat Mar 26 18:50:56 2016 +0900
+++ b/tests/test-newbranch.t	Tue Apr 05 07:30:01 2016 +0200
@@ -463,3 +463,57 @@ We need special handling for repositorie
   -1 new
 
   $ cd ..
+
+We expect that update --clean discard changes in working directory,
+and updates to the head of parent branch.
+
+  $ hg init updatebareclean
+  $ cd updatebareclean
+  $ hg update --clean
+  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ touch a
+  $ hg commit -A -m "a"
+  adding a
+  $ touch b
+  $ hg commit -A -m "b"
+  adding b
+  $ touch c
+  $ hg commit -A -m "c"
+  adding c
+  $ hg log
+  changeset:   2:991a3460af53
+  tag:         tip
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     c
+  
+  changeset:   1:0e067c57feba
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     b
+  
+  changeset:   0:3903775176ed
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     a
+  
+  $ hg update -r 1
+  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  $ hg branch new-branch
+  marked working directory as branch new-branch
+  (branches are permanent and global, did you want a bookmark?)
+  $ echo "aa" >> a
+  $ hg update --clean
+  updating to the head of parent branch default
+  2 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ hg status
+  $ hg branch
+  default
+  $ hg parent
+  changeset:   2:991a3460af53
+  tag:         tip
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     c
+  
+


More information about the Mercurial-devel mailing list