[PATCH 1 of 2 V5] update: fix bare --clean to work on new branch (issue5003) (BC)

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

[PATCH 1 of 2 V5] update: fix bare --clean to work on new branch (issue5003) (BC)

liscju
# HG changeset patch
# User liscju <[hidden email]>
# Date 1456249877 -3600
#      Tue Feb 23 18:51:17 2016 +0100
# Node ID 5ebf0a38f789a35d9bd1dcfd39008b365ec75477
# Parent  70c2f8a982766b512e9d7f41f2d93fdb92f5481f
update: fix bare --clean to work on new branch (issue5003) (BC)

So far 'hg update --clean' on newly created branch results in abort
with branch not found error. After applying this commit bare --clean
update results in updating to the max head of the parents branch.

This seems reasonable as clean should discard uncommited changes,
branch is one of changes, and it would be unreasonable to stay on
the head of the branch we want to discard.

diff -r 70c2f8a98276 -r 5ebf0a38f789 mercurial/destutil.py
--- a/mercurial/destutil.py Sun Mar 06 15:40:20 2016 -0800
+++ b/mercurial/destutil.py Tue Feb 23 18:51:17 2016 +0100
@@ -102,11 +102,19 @@ def _destupdatebranch(repo, clean, check
         if bookmarks.isactivewdirparent(repo):
             movemark = repo['.'].node()
     else:
-        if currentbranch == 'default': # no default branch!
-            # update to the tipmost non-closed branch head
-            node = repo.revs('max(head() and not closed())').first()
+        if clean:
+            heads = repo.branchheads(repo['.'].branch())
+            if heads:
+                node = repo.revs('max(.::(%ln))', heads).first()
+                repo.ui.warn(_('uncommited branch %s does not exist, '
+                               'updating to the head of parent branch\n')
+                             % currentbranch)
         else:
-            raise error.Abort(_("branch %s not found") % currentbranch)
+            if currentbranch == 'default': # no default branch!
+                # update to the tipmost non-closed branch head
+                node = repo.revs('max(head() and not closed())').first()
+            else:
+                raise error.Abort(_("branch %s not found") % currentbranch)
     return node, movemark, None
 
 def _destupdatebranchfallback(repo, clean, check):
diff -r 70c2f8a98276 -r 5ebf0a38f789 tests/test-newbranch.t
--- a/tests/test-newbranch.t Sun Mar 06 15:40:20 2016 -0800
+++ b/tests/test-newbranch.t Tue Feb 23 18:51:17 2016 +0100
@@ -345,3 +345,54 @@ 2 branch heads, implicit merge works:
   (branch merge, don't forget to commit)
 
   $ cd ..
+
+We expects that update --clean discard changes in working directory,
+and updates to the head of parent branch.
+
+  $ hg init update_bare_clean
+  $ cd update_bare_clean
+  $ 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
+  uncommited branch new-branch does not exist, updating to the head of parent branch
+  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
+  
_______________________________________________
Mercurial-devel mailing list
[hidden email]
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Reply | Threaded
Open this post in threaded view
|

[PATCH 2 of 2 V5] update: fix bare update to work on new branch (BC)

liscju
# HG changeset patch
# User liscju <[hidden email]>
# Date 1457876685 -3600
#      Sun Mar 13 14:44:45 2016 +0100
# Node ID a8f1f4cf1450a6fff66d64540b0923ff6b10949a
# Parent  5ebf0a38f789a35d9bd1dcfd39008b365ec75477
update: fix bare update to work on new branch (BC)

So far bare update on new branch results in
'abort: branch new-branch not found'. This commit fixes
this by updating to the parent of wctx.

diff -r 5ebf0a38f789 -r a8f1f4cf1450 mercurial/destutil.py
--- a/mercurial/destutil.py Tue Feb 23 18:51:17 2016 +0100
+++ b/mercurial/destutil.py Sun Mar 13 14:44:45 2016 +0100
@@ -109,12 +109,11 @@ def _destupdatebranch(repo, clean, check
                 repo.ui.warn(_('uncommited branch %s does not exist, '
                                'updating to the head of parent branch\n')
                              % currentbranch)
-        else:
-            if currentbranch == 'default': # no default branch!
-                # update to the tipmost non-closed branch head
-                node = repo.revs('max(head() and not closed())').first()
-            else:
-                raise error.Abort(_("branch %s not found") % currentbranch)
+        elif repo['.']:
+            node = repo['.'].node()
+            repo.ui.warn(_('uncommited branch %s does not exist, '
+                           'updating to parent\n')
+                         % currentbranch)
     return node, movemark, None
 
 def _destupdatebranchfallback(repo, clean, check):
diff -r 5ebf0a38f789 -r a8f1f4cf1450 tests/test-newbranch.t
--- a/tests/test-newbranch.t Tue Feb 23 18:51:17 2016 +0100
+++ b/tests/test-newbranch.t Sun Mar 13 14:44:45 2016 +0100
@@ -211,8 +211,8 @@ Update with no arguments: tipmost revisi
   marked working directory as branch foobar
 
   $ hg up
-  abort: branch foobar not found
-  [255]
+  uncommited branch foobar does not exist, updating to parent
+  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
 
 Fast-forward merge:
 
@@ -396,3 +396,40 @@ and updates to the head of parent branch
   date:        Thu Jan 01 00:00:00 1970 +0000
   summary:     c
   
+
+We expect that bare update on new branch, updates to parent
+
+  $ 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?)
+  $ hg update
+  uncommited branch new-branch does not exist, updating to parent
+  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ hg branch
+  new-branch
+  $ hg parent
+  changeset:   1:0e067c57feba
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     b
+  
+  $ cd ..
+
+We expect that bare update on non existing parent doesnt go anywhere
+  $ hg init newbranch-nonexisting-parent
+  $ cd newbranch-nonexisting-parent
+  $ hg branch new-branch
+  marked working directory as branch new-branch
+  (branches are permanent and global, did you want a bookmark?)
+  $ touch a
+  $ hg add a
+  $ hg status
+  A a
+  $ hg update
+  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ hg branch
+  new-branch
+  $ hg status
+  A a
_______________________________________________
Mercurial-devel mailing list
[hidden email]
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 1 of 2 V5] update: fix bare --clean to work on new branch (issue5003) (BC)

Pierre-Yves David-2
In reply to this post by liscju


On 03/13/2016 01:58 PM, liscju wrote:

> # HG changeset patch
> # User liscju <[hidden email]>
> # Date 1456249877 -3600
> #      Tue Feb 23 18:51:17 2016 +0100
> # Node ID 5ebf0a38f789a35d9bd1dcfd39008b365ec75477
> # Parent  70c2f8a982766b512e9d7f41f2d93fdb92f5481f
> update: fix bare --clean to work on new branch (issue5003) (BC)
>
> So far 'hg update --clean' on newly created branch results in abort
> with branch not found error. After applying this commit bare --clean
> update results in updating to the max head of the parents branch.
>
> This seems reasonable as clean should discard uncommited changes,
> branch is one of changes, and it would be unreasonable to stay on
> the head of the branch we want to discard.

We should stick to a consistent behavior. This current patch does not

1) if the uncommited branch exists it will update to the head of wc.branch()
2) if the uncommited branch does not exists it will update to the head
of p1.branch(),

We should also pick either p1.branch() (discard before update) or
wc.branch(discard after update)

 From our last discussion, it seems like we had a consensus on "picking
p1.branch()" as your did in V1 on this series.

Cheers,

--
Pierre-Yves David

PS: I would also fix the general case first (patch 2 before patch 1)
_______________________________________________
Mercurial-devel mailing list
[hidden email]
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Reply | Threaded
Open this post in threaded view
|

Fwd: [PATCH 1 of 2 V5] update: fix bare --clean to work on new branch (issue5003) (BC)

liscju
Im resending last message cause there was no answer to it:

We should stick to a consistent behavior. This current patch does not
1) if the uncommited branch exists it will update to the head of wc.branch()
2) if the uncommited branch does not exists it will update to the head of p1.branch(),
We should also pick either p1.branch() (discard before update) or wc.branch(discard after update)

Ok, this is dealing issue dealing with 'fix `hg update` with uncommited new branch change'(without --clean option). So from what i understand if current branch(working directory branch) exists we should update to the head of p1.branch(). What about this situation:

o  changeset:   4:8bfba5c70947
|  tag:         tip
|  parent:      2:5b1d7f055b16
|  user:        liscju <[hidden email]>
|  date:        Fri Mar 18 12:06:09 2016 +0100
|  summary:     f
|
|    o  changeset:   3:16fedbfebd5c
|    |  branch:      dev
|    |  parent:      0:c4d0e2f61fe9
|    |  user:        liscju <[hidden email]>
|    |  date:        Fri Mar 18 12:01:37 2016 +0100
|    |  summary:     e
|    |
@  |  changeset:   2:5b1d7f055b16
|    |  user:        liscju <[hidden email]>
|    |  date:        Fri Mar 18 12:00:46 2016 +0100
|    |  summary:     c
|    |
o   |  changeset:   1:e3773bd721b2
|   /   user:        liscju <[hidden email]>
| /     date:        Fri Mar 18 12:00:32 2016 +0100
|       summary:     b
|
o  changeset:   0:c4d0e2f61fe9
   user:        liscju <[hidden email]>
   date:        Fri Mar 18 12:00:25 2016 +0100
   summary:     a


We are on the changeset 2 right now, we change branch of working directory to dev. We run bare 'hg update', current branch exists(dev have head on revision 3), and 'hg update' will jump to the head of parent branch, so to the revision 4(on branch default as parent branch) - is this expected behaviour?


_______________________________________________
Mercurial-devel mailing list
[hidden email]
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel