Show More
@@ -88,30 +88,55 def _destupdatebook(repo, clean, check): | |||||
88 | return node, movemark, activemark |
|
88 | return node, movemark, activemark | |
89 |
|
89 | |||
90 | def _destupdatebranch(repo, clean, check): |
|
90 | def _destupdatebranch(repo, clean, check): | |
91 |
"""decide on an update destination from current branch |
|
91 | """decide on an update destination from current branch | |
|
92 | ||||
|
93 | This ignores closed branch heads. | |||
|
94 | """ | |||
92 | wc = repo[None] |
|
95 | wc = repo[None] | |
93 | movemark = node = None |
|
96 | movemark = node = None | |
94 | currentbranch = wc.branch() |
|
97 | currentbranch = wc.branch() | |
95 | if currentbranch in repo.branchmap(): |
|
98 | if currentbranch in repo.branchmap(): | |
96 |
heads = repo.branchheads(currentbranch |
|
99 | heads = repo.branchheads(currentbranch) | |
97 | if heads: |
|
100 | if heads: | |
98 | node = repo.revs('max(.::(%ln))', heads).first() |
|
101 | node = repo.revs('max(.::(%ln))', heads).first() | |
99 | if bookmarks.isactivewdirparent(repo): |
|
102 | if bookmarks.isactivewdirparent(repo): | |
100 | movemark = repo['.'].node() |
|
103 | movemark = repo['.'].node() | |
101 | else: |
|
104 | else: | |
102 | if currentbranch == 'default': # no default branch! |
|
105 | if currentbranch == 'default': # no default branch! | |
103 | node = repo.lookup('tip') # update to tip |
|
106 | # update to the tipmost non-closed branch head | |
|
107 | node = repo.revs('max(head() and not closed())').first() | |||
104 | else: |
|
108 | else: | |
105 | raise error.Abort(_("branch %s not found") % currentbranch) |
|
109 | raise error.Abort(_("branch %s not found") % currentbranch) | |
106 | return node, movemark, None |
|
110 | return node, movemark, None | |
107 |
|
111 | |||
|
112 | def _destupdatebranchfallback(repo, clean, check): | |||
|
113 | """decide on an update destination from closed heads in current branch""" | |||
|
114 | wc = repo[None] | |||
|
115 | currentbranch = wc.branch() | |||
|
116 | movemark = None | |||
|
117 | if currentbranch in repo.branchmap(): | |||
|
118 | # here, all descendant branch heads are closed | |||
|
119 | heads = repo.branchheads(currentbranch, closed=True) | |||
|
120 | assert heads, "any branch has at least one head" | |||
|
121 | node = repo.revs('max(.::(%ln))', heads).first() | |||
|
122 | assert node is not None, ("any revision has at least " | |||
|
123 | "one descendant branch head") | |||
|
124 | if bookmarks.isactivewdirparent(repo): | |||
|
125 | movemark = repo['.'].node() | |||
|
126 | else: | |||
|
127 | # here, no "default" branch, and all branches are closed | |||
|
128 | node = repo.lookup('tip') | |||
|
129 | assert node is not None, "'tip' exists even in empty repository" | |||
|
130 | return node, movemark, None | |||
|
131 | ||||
108 | # order in which each step should be evalutated |
|
132 | # order in which each step should be evalutated | |
109 | # steps are run until one finds a destination |
|
133 | # steps are run until one finds a destination | |
110 | destupdatesteps = ['evolution', 'bookmark', 'branch'] |
|
134 | destupdatesteps = ['evolution', 'bookmark', 'branch', 'branchfallback'] | |
111 | # mapping to ease extension overriding steps. |
|
135 | # mapping to ease extension overriding steps. | |
112 | destupdatestepmap = {'evolution': _destupdateobs, |
|
136 | destupdatestepmap = {'evolution': _destupdateobs, | |
113 | 'bookmark': _destupdatebook, |
|
137 | 'bookmark': _destupdatebook, | |
114 | 'branch': _destupdatebranch, |
|
138 | 'branch': _destupdatebranch, | |
|
139 | 'branchfallback': _destupdatebranchfallback, | |||
115 | } |
|
140 | } | |
116 |
|
141 | |||
117 | def destupdate(repo, clean=False, check=False): |
|
142 | def destupdate(repo, clean=False, check=False): | |
@@ -362,10 +387,29 def _statusotherbranchheads(ui, repo): | |||||
362 | heads = repo.branchheads(currentbranch) |
|
387 | heads = repo.branchheads(currentbranch) | |
363 | if repo.revs('%ln and parents()', allheads): |
|
388 | if repo.revs('%ln and parents()', allheads): | |
364 | # we are on a head, even though it might be closed |
|
389 | # we are on a head, even though it might be closed | |
|
390 | # | |||
|
391 | # on closed otherheads | |||
|
392 | # ========= ========== | |||
|
393 | # o 0 all heads for current branch are closed | |||
|
394 | # N only descendant branch heads are closed | |||
|
395 | # x 0 there is only one non-closed branch head | |||
|
396 | # N there are some non-closed branch heads | |||
|
397 | # ========= ========== | |||
365 | otherheads = repo.revs('%ln - parents()', heads) |
|
398 | otherheads = repo.revs('%ln - parents()', heads) | |
|
399 | if repo['.'].closesbranch(): | |||
|
400 | ui.status(_('updated to a closed branch head, ' | |||
|
401 | 'because all descendant heads are closed.\n' | |||
|
402 | 'beware of re-opening closed head ' | |||
|
403 | 'by subsequent commit here.\n')) | |||
366 | if otherheads: |
|
404 | if otherheads: | |
367 | ui.status(_('%i other heads for branch "%s"\n') % |
|
405 | ui.status(_('%i other heads for branch "%s"\n') % | |
368 | (len(otherheads), currentbranch)) |
|
406 | (len(otherheads), currentbranch)) | |
|
407 | else: | |||
|
408 | ui.status(_('all heads for branch "%s" are closed.\n') % | |||
|
409 | currentbranch) | |||
|
410 | elif otherheads: | |||
|
411 | ui.status(_('%i other heads for branch "%s"\n') % | |||
|
412 | (len(otherheads), currentbranch)) | |||
369 |
|
413 | |||
370 | def statusotherdests(ui, repo): |
|
414 | def statusotherdests(ui, repo): | |
371 | """Print message about other head""" |
|
415 | """Print message about other head""" |
@@ -202,3 +202,22 issue 4552 -- simulate a pull moving the | |||||
202 | Z |
|
202 | Z | |
203 | $ hg log -T '{bookmarks % "{active}\n"}' -r Z |
|
203 | $ hg log -T '{bookmarks % "{active}\n"}' -r Z | |
204 | Z |
|
204 | Z | |
|
205 | ||||
|
206 | test that updating to closed branch head also advances active bookmark | |||
|
207 | ||||
|
208 | $ hg commit --close-branch -m "closed" | |||
|
209 | $ hg update -q ".^1" | |||
|
210 | $ hg bookmark Y | |||
|
211 | $ hg bookmarks | |||
|
212 | X 3:4d6bd4bfb1ae | |||
|
213 | * Y 3:4d6bd4bfb1ae | |||
|
214 | Z 0:719295282060 | |||
|
215 | $ hg update | |||
|
216 | 0 files updated, 0 files merged, 0 files removed, 0 files unresolved | |||
|
217 | updating bookmark Y | |||
|
218 | $ hg bookmarks | |||
|
219 | X 3:4d6bd4bfb1ae | |||
|
220 | * Y 4:8fa964221e8e | |||
|
221 | Z 0:719295282060 | |||
|
222 | $ hg parents -q | |||
|
223 | 4:8fa964221e8e |
@@ -186,28 +186,111 Test updating with closed head | |||||
186 | Test updating if at least one non-closed branch head exists |
|
186 | Test updating if at least one non-closed branch head exists | |
187 |
|
187 | |||
188 | if on the closed branch head: |
|
188 | if on the closed branch head: | |
189 | - updating is no-op |
|
189 | - update to "." | |
|
190 | - "updated to a closed branch head ...." message is displayed | |||
190 | - "N other heads for ...." message is displayed |
|
191 | - "N other heads for ...." message is displayed | |
191 |
|
192 | |||
192 | $ hg update -q -C 3 |
|
193 | $ hg update -q -C 3 | |
193 | $ hg commit --close-branch -m 6 |
|
194 | $ hg commit --close-branch -m 6 | |
194 | $ norevtest "on closed branch head" clean 6 |
|
195 | $ norevtest "on closed branch head" clean 6 | |
195 | 0 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
196 | 0 files updated, 0 files merged, 0 files removed, 0 files unresolved | |
|
197 | updated to a closed branch head, because all descendant heads are closed. | |||
|
198 | beware of re-opening closed head by subsequent commit here. | |||
|
199 | 1 other heads for branch "default" | |||
|
200 | parent=6 | |||
|
201 | ||||
|
202 | if descendant non-closed branch head exists, and it is only one branch head: | |||
|
203 | - update to it, even if its revision is less than closed one | |||
|
204 | - "N other heads for ...." message isn't displayed | |||
|
205 | ||||
|
206 | $ norevtest "non-closed 2 should be chosen" clean 1 | |||
|
207 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved | |||
|
208 | parent=2 | |||
|
209 | ||||
|
210 | if all descendant branch heads are closed, but there is another branch head: | |||
|
211 | - update to the tipmost descendant head | |||
|
212 | - "updated to a closed branch head ...." message is displayed | |||
|
213 | - "N other heads for ...." message is displayed | |||
|
214 | ||||
|
215 | $ norevtest "all descendant branch heads are closed" clean 3 | |||
|
216 | 0 files updated, 0 files merged, 0 files removed, 0 files unresolved | |||
|
217 | updated to a closed branch head, because all descendant heads are closed. | |||
|
218 | beware of re-opening closed head by subsequent commit here. | |||
196 | 1 other heads for branch "default" |
|
219 | 1 other heads for branch "default" | |
197 | parent=6 |
|
220 | parent=6 | |
198 |
|
221 | |||
199 | Test updating if all branch heads are closed |
|
222 | Test updating if all branch heads are closed | |
200 |
|
223 | |||
201 | if on the closed branch head: |
|
224 | if on the closed branch head: | |
202 | - updating is no-op |
|
225 | - update to "." | |
203 |
- " |
|
226 | - "updated to a closed branch head ...." message is displayed | |
|
227 | - "all heads of branch ...." message is displayed | |||
204 |
|
228 | |||
205 | $ hg update -q -C 2 |
|
229 | $ hg update -q -C 2 | |
206 | $ hg commit --close-branch -m 7 |
|
230 | $ hg commit --close-branch -m 7 | |
207 | $ norevtest "all heads of branch default are closed" clean 6 |
|
231 | $ norevtest "all heads of branch default are closed" clean 6 | |
208 | 0 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
232 | 0 files updated, 0 files merged, 0 files removed, 0 files unresolved | |
|
233 | updated to a closed branch head, because all descendant heads are closed. | |||
|
234 | beware of re-opening closed head by subsequent commit here. | |||
|
235 | all heads for branch "default" are closed. | |||
209 | parent=6 |
|
236 | parent=6 | |
210 |
|
237 | |||
|
238 | if not on the closed branch head: | |||
|
239 | - update to the tipmost descendant (closed) head | |||
|
240 | - "updated to a closed branch head ...." message is displayed | |||
|
241 | - "all heads of branch ...." message is displayed | |||
|
242 | ||||
|
243 | $ norevtest "all heads of branch default are closed" clean 1 | |||
|
244 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved | |||
|
245 | updated to a closed branch head, because all descendant heads are closed. | |||
|
246 | beware of re-opening closed head by subsequent commit here. | |||
|
247 | all heads for branch "default" are closed. | |||
|
248 | parent=7 | |||
|
249 | ||||
|
250 | $ cd .. | |||
|
251 | ||||
|
252 | Test updating if "default" branch doesn't exist and no revision is | |||
|
253 | checked out (= "default" is used as current branch) | |||
|
254 | ||||
|
255 | $ hg init no-default-branch | |||
|
256 | $ cd no-default-branch | |||
|
257 | ||||
|
258 | $ hg branch foobar | |||
|
259 | marked working directory as branch foobar | |||
|
260 | (branches are permanent and global, did you want a bookmark?) | |||
|
261 | $ echo a > a | |||
|
262 | $ hg commit -m "#0" -A | |||
|
263 | adding a | |||
|
264 | $ echo 1 >> a | |||
|
265 | $ hg commit -m "#1" | |||
|
266 | $ hg update -q 0 | |||
|
267 | $ echo 3 >> a | |||
|
268 | $ hg commit -m "#2" | |||
|
269 | created new head | |||
|
270 | $ hg commit --close-branch -m "#3" | |||
|
271 | ||||
|
272 | if there is at least one non-closed branch head: | |||
|
273 | - update to the tipmost branch head | |||
|
274 | ||||
|
275 | $ norevtest "non-closed 1 should be chosen" clean null | |||
|
276 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved | |||
|
277 | parent=1 | |||
|
278 | ||||
|
279 | if all branch heads are closed | |||
|
280 | - update to "tip" | |||
|
281 | - "updated to a closed branch head ...." message is displayed | |||
|
282 | - "all heads for branch "XXXX" are closed" message is displayed | |||
|
283 | ||||
|
284 | $ hg update -q -C 1 | |||
|
285 | $ hg commit --close-branch -m "#4" | |||
|
286 | ||||
|
287 | $ norevtest "all branches are closed" clean null | |||
|
288 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved | |||
|
289 | updated to a closed branch head, because all descendant heads are closed. | |||
|
290 | beware of re-opening closed head by subsequent commit here. | |||
|
291 | all heads for branch "foobar" are closed. | |||
|
292 | parent=4 | |||
|
293 | ||||
211 | $ cd ../b1 |
|
294 | $ cd ../b1 | |
212 |
|
295 | |||
213 | Test obsolescence behavior |
|
296 | Test obsolescence behavior |
General Comments 0
You need to be logged in to leave comments.
Login now