Mercurial > hg
comparison mercurial/destutil.py @ 26628:45b86dbabbda
destupdate: move the check related to the "clean" logic in the function
We want this function to exactly predict the behavior for update. Moreover, we
would like to remove all high level behavior logic out of the merge module so
this is a step forward.
Now that the 'destupdate' function both compute and validate the destination, we
can directly use it at the command level, ensuring that the 'hg update' command
never call 'merge.update' without a defined destination. This is a first (but
significant) step toward having 'merge.update' always feed with a properly
validated destination and free of high level logic.
author | Pierre-Yves David <pierre-yves.david@fb.com> |
---|---|
date | Mon, 05 Oct 2015 03:50:47 -0700 |
parents | 56b2bcea2529 |
children | ae5f7be2b4ab |
comparison
equal
deleted
inserted
replaced
26627:832c98d79587 | 26628:45b86dbabbda |
---|---|
9 from . import ( | 9 from . import ( |
10 error, | 10 error, |
11 obsolete, | 11 obsolete, |
12 ) | 12 ) |
13 | 13 |
14 def destupdate(repo): | 14 def destupdate(repo, clean=False): |
15 """destination for bare update operation | 15 """destination for bare update operation |
16 """ | 16 """ |
17 # Here is where we should consider bookmarks, divergent bookmarks, and tip | 17 # Here is where we should consider bookmarks, divergent bookmarks, and tip |
18 # of current branch; but currently we are only checking the branch tips. | 18 # of current branch; but currently we are only checking the branch tips. |
19 node = None | 19 node = None |
50 successors = [n for sub in successors for n in sub] | 50 successors = [n for sub in successors for n in sub] |
51 | 51 |
52 # get the max revision for the given successors set, | 52 # get the max revision for the given successors set, |
53 # i.e. the 'tip' of a set | 53 # i.e. the 'tip' of a set |
54 node = repo.revs('max(%ln)', successors).first() | 54 node = repo.revs('max(%ln)', successors).first() |
55 return repo[node].rev() | 55 rev = repo[node].rev() |
56 | |
57 if not clean: | |
58 # Check that the update is linear. | |
59 # | |
60 # Mercurial do not allow update-merge for non linear pattern | |
61 # (that would be technically possible but was considered too confusing | |
62 # for user a long time ago) | |
63 # | |
64 # See mercurial.merge.update for details | |
65 if p1.rev() not in repo.changelog.ancestors([rev], inclusive=True): | |
66 dirty = wc.dirty(missing=True) | |
67 foreground = obsolete.foreground(repo, [p1.node()]) | |
68 if not repo[rev].node() in foreground: | |
69 if dirty: | |
70 msg = _("uncommitted changes") | |
71 hint = _("commit and merge, or update --clean to" | |
72 " discard changes") | |
73 raise error.Abort(msg, hint=hint) | |
74 else: # destination is not a descendant. | |
75 msg = _("not a linear update") | |
76 hint = _("merge or update --check to force update") | |
77 raise error.Abort(msg, hint=hint) | |
78 | |
79 return rev |