Show More
@@ -1,470 +1,469 b'' | |||
|
1 | 1 | # rebase.py - rebasing feature for mercurial |
|
2 | 2 | # |
|
3 | 3 | # Copyright 2008 Stefano Tortarolo <stefano.tortarolo at gmail dot com> |
|
4 | 4 | # |
|
5 | 5 | # This software may be used and distributed according to the terms of the |
|
6 | 6 | # GNU General Public License version 2, incorporated herein by reference. |
|
7 | 7 | |
|
8 | 8 | '''command to move sets of revisions to a different ancestor |
|
9 | 9 | |
|
10 | This extension lets you rebase changesets in an existing Mercurial | |
|
11 | repository. | |
|
10 | This extension lets you rebase changesets in an existing Mercurial repository. | |
|
12 | 11 | |
|
13 | 12 | For more information: |
|
14 | 13 | http://mercurial.selenic.com/wiki/RebaseProject |
|
15 | 14 | ''' |
|
16 | 15 | |
|
17 | 16 | from mercurial import util, repair, merge, cmdutil, commands, error |
|
18 | 17 | from mercurial import extensions, ancestor, copies, patch |
|
19 | 18 | from mercurial.commands import templateopts |
|
20 | 19 | from mercurial.node import nullrev |
|
21 | 20 | from mercurial.lock import release |
|
22 | 21 | from mercurial.i18n import _ |
|
23 | 22 | import os, errno |
|
24 | 23 | |
|
25 | 24 | def rebasemerge(repo, rev, first=False): |
|
26 | 25 | 'return the correct ancestor' |
|
27 | 26 | oldancestor = ancestor.ancestor |
|
28 | 27 | |
|
29 | 28 | def newancestor(a, b, pfunc): |
|
30 | 29 | ancestor.ancestor = oldancestor |
|
31 | 30 | if b == rev: |
|
32 | 31 | return repo[rev].parents()[0].rev() |
|
33 | 32 | return ancestor.ancestor(a, b, pfunc) |
|
34 | 33 | |
|
35 | 34 | if not first: |
|
36 | 35 | ancestor.ancestor = newancestor |
|
37 | 36 | else: |
|
38 | 37 | repo.ui.debug(_("first revision, do not change ancestor\n")) |
|
39 | 38 | stats = merge.update(repo, rev, True, True, False) |
|
40 | 39 | return stats |
|
41 | 40 | |
|
42 | 41 | def rebase(ui, repo, **opts): |
|
43 | 42 | """move changeset (and descendants) to a different branch |
|
44 | 43 | |
|
45 | Rebase uses repeated merging to graft changesets from one part of | |
|
46 |
|
|
|
47 |
|
|
|
44 | Rebase uses repeated merging to graft changesets from one part of history | |
|
45 | onto another. This can be useful for linearizing local changes relative to | |
|
46 | a master development tree. | |
|
48 | 47 | |
|
49 | 48 | If a rebase is interrupted to manually resolve a merge, it can be |
|
50 | 49 | continued with --continue/-c or aborted with --abort/-a. |
|
51 | 50 | """ |
|
52 | 51 | originalwd = target = None |
|
53 | 52 | external = nullrev |
|
54 | 53 | state = {} |
|
55 | 54 | skipped = set() |
|
56 | 55 | |
|
57 | 56 | lock = wlock = None |
|
58 | 57 | try: |
|
59 | 58 | lock = repo.lock() |
|
60 | 59 | wlock = repo.wlock() |
|
61 | 60 | |
|
62 | 61 | # Validate input and define rebasing points |
|
63 | 62 | destf = opts.get('dest', None) |
|
64 | 63 | srcf = opts.get('source', None) |
|
65 | 64 | basef = opts.get('base', None) |
|
66 | 65 | contf = opts.get('continue') |
|
67 | 66 | abortf = opts.get('abort') |
|
68 | 67 | collapsef = opts.get('collapse', False) |
|
69 | 68 | extrafn = opts.get('extrafn') |
|
70 | 69 | keepf = opts.get('keep', False) |
|
71 | 70 | keepbranchesf = opts.get('keepbranches', False) |
|
72 | 71 | |
|
73 | 72 | if contf or abortf: |
|
74 | 73 | if contf and abortf: |
|
75 | 74 | raise error.ParseError('rebase', |
|
76 | 75 | _('cannot use both abort and continue')) |
|
77 | 76 | if collapsef: |
|
78 | 77 | raise error.ParseError( |
|
79 | 78 | 'rebase', _('cannot use collapse with continue or abort')) |
|
80 | 79 | |
|
81 | 80 | if srcf or basef or destf: |
|
82 | 81 | raise error.ParseError('rebase', |
|
83 | 82 | _('abort and continue do not allow specifying revisions')) |
|
84 | 83 | |
|
85 | 84 | (originalwd, target, state, collapsef, keepf, |
|
86 | 85 | keepbranchesf, external) = restorestatus(repo) |
|
87 | 86 | if abortf: |
|
88 | 87 | abort(repo, originalwd, target, state) |
|
89 | 88 | return |
|
90 | 89 | else: |
|
91 | 90 | if srcf and basef: |
|
92 | 91 | raise error.ParseError('rebase', _('cannot specify both a ' |
|
93 | 92 | 'revision and a base')) |
|
94 | 93 | cmdutil.bail_if_changed(repo) |
|
95 | 94 | result = buildstate(repo, destf, srcf, basef, collapsef) |
|
96 | 95 | if result: |
|
97 | 96 | originalwd, target, state, external = result |
|
98 | 97 | else: # Empty state built, nothing to rebase |
|
99 | 98 | ui.status(_('nothing to rebase\n')) |
|
100 | 99 | return |
|
101 | 100 | |
|
102 | 101 | if keepbranchesf: |
|
103 | 102 | if extrafn: |
|
104 | 103 | raise error.ParseError( |
|
105 | 104 | 'rebase', _('cannot use both keepbranches and extrafn')) |
|
106 | 105 | def extrafn(ctx, extra): |
|
107 | 106 | extra['branch'] = ctx.branch() |
|
108 | 107 | |
|
109 | 108 | # Rebase |
|
110 | 109 | targetancestors = list(repo.changelog.ancestors(target)) |
|
111 | 110 | targetancestors.append(target) |
|
112 | 111 | |
|
113 | 112 | for rev in sorted(state): |
|
114 | 113 | if state[rev] == -1: |
|
115 | 114 | storestatus(repo, originalwd, target, state, collapsef, keepf, |
|
116 | 115 | keepbranchesf, external) |
|
117 | 116 | rebasenode(repo, rev, target, state, skipped, targetancestors, |
|
118 | 117 | collapsef, extrafn) |
|
119 | 118 | ui.note(_('rebase merging completed\n')) |
|
120 | 119 | |
|
121 | 120 | if collapsef: |
|
122 | 121 | p1, p2 = defineparents(repo, min(state), target, |
|
123 | 122 | state, targetancestors) |
|
124 | 123 | concludenode(repo, rev, p1, external, state, collapsef, |
|
125 | 124 | last=True, skipped=skipped, extrafn=extrafn) |
|
126 | 125 | |
|
127 | 126 | if 'qtip' in repo.tags(): |
|
128 | 127 | updatemq(repo, state, skipped, **opts) |
|
129 | 128 | |
|
130 | 129 | if not keepf: |
|
131 | 130 | # Remove no more useful revisions |
|
132 | 131 | if set(repo.changelog.descendants(min(state))) - set(state): |
|
133 | 132 | ui.warn(_("warning: new changesets detected on source branch, " |
|
134 | 133 | "not stripping\n")) |
|
135 | 134 | else: |
|
136 | 135 | repair.strip(ui, repo, repo[min(state)].node(), "strip") |
|
137 | 136 | |
|
138 | 137 | clearstatus(repo) |
|
139 | 138 | ui.status(_("rebase completed\n")) |
|
140 | 139 | if os.path.exists(repo.sjoin('undo')): |
|
141 | 140 | util.unlink(repo.sjoin('undo')) |
|
142 | 141 | if skipped: |
|
143 | 142 | ui.note(_("%d revisions have been skipped\n") % len(skipped)) |
|
144 | 143 | finally: |
|
145 | 144 | release(lock, wlock) |
|
146 | 145 | |
|
147 | 146 | def concludenode(repo, rev, p1, p2, state, collapse, last=False, skipped=None, |
|
148 | 147 | extrafn=None): |
|
149 | 148 | """Skip commit if collapsing has been required and rev is not the last |
|
150 | 149 | revision, commit otherwise |
|
151 | 150 | """ |
|
152 | 151 | repo.ui.debug(_(" set parents\n")) |
|
153 | 152 | if collapse and not last: |
|
154 | 153 | repo.dirstate.setparents(repo[p1].node()) |
|
155 | 154 | return None |
|
156 | 155 | |
|
157 | 156 | repo.dirstate.setparents(repo[p1].node(), repo[p2].node()) |
|
158 | 157 | |
|
159 | 158 | if skipped is None: |
|
160 | 159 | skipped = set() |
|
161 | 160 | |
|
162 | 161 | # Commit, record the old nodeid |
|
163 | 162 | newrev = nullrev |
|
164 | 163 | try: |
|
165 | 164 | if last: |
|
166 | 165 | commitmsg = 'Collapsed revision' |
|
167 | 166 | for rebased in state: |
|
168 | 167 | if rebased not in skipped: |
|
169 | 168 | commitmsg += '\n* %s' % repo[rebased].description() |
|
170 | 169 | commitmsg = repo.ui.edit(commitmsg, repo.ui.username()) |
|
171 | 170 | else: |
|
172 | 171 | commitmsg = repo[rev].description() |
|
173 | 172 | # Commit might fail if unresolved files exist |
|
174 | 173 | extra = {'rebase_source': repo[rev].hex()} |
|
175 | 174 | if extrafn: |
|
176 | 175 | extrafn(repo[rev], extra) |
|
177 | 176 | newrev = repo.commit(text=commitmsg, user=repo[rev].user(), |
|
178 | 177 | date=repo[rev].date(), extra=extra) |
|
179 | 178 | repo.dirstate.setbranch(repo[newrev].branch()) |
|
180 | 179 | return newrev |
|
181 | 180 | except util.Abort: |
|
182 | 181 | # Invalidate the previous setparents |
|
183 | 182 | repo.dirstate.invalidate() |
|
184 | 183 | raise |
|
185 | 184 | |
|
186 | 185 | def rebasenode(repo, rev, target, state, skipped, targetancestors, collapse, |
|
187 | 186 | extrafn): |
|
188 | 187 | 'Rebase a single revision' |
|
189 | 188 | repo.ui.debug(_("rebasing %d:%s\n") % (rev, repo[rev])) |
|
190 | 189 | |
|
191 | 190 | p1, p2 = defineparents(repo, rev, target, state, targetancestors) |
|
192 | 191 | |
|
193 | 192 | repo.ui.debug(_(" future parents are %d and %d\n") % (repo[p1].rev(), |
|
194 | 193 | repo[p2].rev())) |
|
195 | 194 | |
|
196 | 195 | # Merge phase |
|
197 | 196 | if len(repo.parents()) != 2: |
|
198 | 197 | # Update to target and merge it with local |
|
199 | 198 | if repo['.'].rev() != repo[p1].rev(): |
|
200 | 199 | repo.ui.debug(_(" update to %d:%s\n") % (repo[p1].rev(), repo[p1])) |
|
201 | 200 | merge.update(repo, p1, False, True, False) |
|
202 | 201 | else: |
|
203 | 202 | repo.ui.debug(_(" already in target\n")) |
|
204 | 203 | repo.dirstate.write() |
|
205 | 204 | repo.ui.debug(_(" merge against %d:%s\n") % (repo[rev].rev(), repo[rev])) |
|
206 | 205 | first = repo[rev].rev() == repo[min(state)].rev() |
|
207 | 206 | stats = rebasemerge(repo, rev, first) |
|
208 | 207 | |
|
209 | 208 | if stats[3] > 0: |
|
210 | 209 | raise util.Abort(_('fix unresolved conflicts with hg resolve then ' |
|
211 | 210 | 'run hg rebase --continue')) |
|
212 | 211 | else: # we have an interrupted rebase |
|
213 | 212 | repo.ui.debug(_('resuming interrupted rebase\n')) |
|
214 | 213 | |
|
215 | 214 | # Keep track of renamed files in the revision that is going to be rebased |
|
216 | 215 | # Here we simulate the copies and renames in the source changeset |
|
217 | 216 | cop, diver = copies.copies(repo, repo[rev], repo[target], repo[p2], True) |
|
218 | 217 | m1 = repo[rev].manifest() |
|
219 | 218 | m2 = repo[target].manifest() |
|
220 | 219 | for k, v in cop.iteritems(): |
|
221 | 220 | if k in m1: |
|
222 | 221 | if v in m1 or v in m2: |
|
223 | 222 | repo.dirstate.copy(v, k) |
|
224 | 223 | if v in m2 and v not in m1: |
|
225 | 224 | repo.dirstate.remove(v) |
|
226 | 225 | |
|
227 | 226 | newrev = concludenode(repo, rev, p1, p2, state, collapse, |
|
228 | 227 | extrafn=extrafn) |
|
229 | 228 | |
|
230 | 229 | # Update the state |
|
231 | 230 | if newrev is not None: |
|
232 | 231 | state[rev] = repo[newrev].rev() |
|
233 | 232 | else: |
|
234 | 233 | if not collapse: |
|
235 | 234 | repo.ui.note(_('no changes, revision %d skipped\n') % rev) |
|
236 | 235 | repo.ui.debug(_('next revision set to %s\n') % p1) |
|
237 | 236 | skipped.add(rev) |
|
238 | 237 | state[rev] = p1 |
|
239 | 238 | |
|
240 | 239 | def defineparents(repo, rev, target, state, targetancestors): |
|
241 | 240 | 'Return the new parent relationship of the revision that will be rebased' |
|
242 | 241 | parents = repo[rev].parents() |
|
243 | 242 | p1 = p2 = nullrev |
|
244 | 243 | |
|
245 | 244 | P1n = parents[0].rev() |
|
246 | 245 | if P1n in targetancestors: |
|
247 | 246 | p1 = target |
|
248 | 247 | elif P1n in state: |
|
249 | 248 | p1 = state[P1n] |
|
250 | 249 | else: # P1n external |
|
251 | 250 | p1 = target |
|
252 | 251 | p2 = P1n |
|
253 | 252 | |
|
254 | 253 | if len(parents) == 2 and parents[1].rev() not in targetancestors: |
|
255 | 254 | P2n = parents[1].rev() |
|
256 | 255 | # interesting second parent |
|
257 | 256 | if P2n in state: |
|
258 | 257 | if p1 == target: # P1n in targetancestors or external |
|
259 | 258 | p1 = state[P2n] |
|
260 | 259 | else: |
|
261 | 260 | p2 = state[P2n] |
|
262 | 261 | else: # P2n external |
|
263 | 262 | if p2 != nullrev: # P1n external too => rev is a merged revision |
|
264 | 263 | raise util.Abort(_('cannot use revision %d as base, result ' |
|
265 | 264 | 'would have 3 parents') % rev) |
|
266 | 265 | p2 = P2n |
|
267 | 266 | return p1, p2 |
|
268 | 267 | |
|
269 | 268 | def isagitpatch(repo, patchname): |
|
270 | 269 | 'Return true if the given patch is in git format' |
|
271 | 270 | mqpatch = os.path.join(repo.mq.path, patchname) |
|
272 | 271 | for line in patch.linereader(file(mqpatch, 'rb')): |
|
273 | 272 | if line.startswith('diff --git'): |
|
274 | 273 | return True |
|
275 | 274 | return False |
|
276 | 275 | |
|
277 | 276 | def updatemq(repo, state, skipped, **opts): |
|
278 | 277 | 'Update rebased mq patches - finalize and then import them' |
|
279 | 278 | mqrebase = {} |
|
280 | 279 | for p in repo.mq.applied: |
|
281 | 280 | if repo[p.rev].rev() in state: |
|
282 | 281 | repo.ui.debug(_('revision %d is an mq patch (%s), finalize it.\n') % |
|
283 | 282 | (repo[p.rev].rev(), p.name)) |
|
284 | 283 | mqrebase[repo[p.rev].rev()] = (p.name, isagitpatch(repo, p.name)) |
|
285 | 284 | |
|
286 | 285 | if mqrebase: |
|
287 | 286 | repo.mq.finish(repo, mqrebase.keys()) |
|
288 | 287 | |
|
289 | 288 | # We must start import from the newest revision |
|
290 | 289 | for rev in sorted(mqrebase, reverse=True): |
|
291 | 290 | if rev not in skipped: |
|
292 | 291 | repo.ui.debug(_('import mq patch %d (%s)\n') |
|
293 | 292 | % (state[rev], mqrebase[rev][0])) |
|
294 | 293 | repo.mq.qimport(repo, (), patchname=mqrebase[rev][0], |
|
295 | 294 | git=mqrebase[rev][1],rev=[str(state[rev])]) |
|
296 | 295 | repo.mq.save_dirty() |
|
297 | 296 | |
|
298 | 297 | def storestatus(repo, originalwd, target, state, collapse, keep, keepbranches, |
|
299 | 298 | external): |
|
300 | 299 | 'Store the current status to allow recovery' |
|
301 | 300 | f = repo.opener("rebasestate", "w") |
|
302 | 301 | f.write(repo[originalwd].hex() + '\n') |
|
303 | 302 | f.write(repo[target].hex() + '\n') |
|
304 | 303 | f.write(repo[external].hex() + '\n') |
|
305 | 304 | f.write('%d\n' % int(collapse)) |
|
306 | 305 | f.write('%d\n' % int(keep)) |
|
307 | 306 | f.write('%d\n' % int(keepbranches)) |
|
308 | 307 | for d, v in state.iteritems(): |
|
309 | 308 | oldrev = repo[d].hex() |
|
310 | 309 | newrev = repo[v].hex() |
|
311 | 310 | f.write("%s:%s\n" % (oldrev, newrev)) |
|
312 | 311 | f.close() |
|
313 | 312 | repo.ui.debug(_('rebase status stored\n')) |
|
314 | 313 | |
|
315 | 314 | def clearstatus(repo): |
|
316 | 315 | 'Remove the status files' |
|
317 | 316 | if os.path.exists(repo.join("rebasestate")): |
|
318 | 317 | util.unlink(repo.join("rebasestate")) |
|
319 | 318 | |
|
320 | 319 | def restorestatus(repo): |
|
321 | 320 | 'Restore a previously stored status' |
|
322 | 321 | try: |
|
323 | 322 | target = None |
|
324 | 323 | collapse = False |
|
325 | 324 | external = nullrev |
|
326 | 325 | state = {} |
|
327 | 326 | f = repo.opener("rebasestate") |
|
328 | 327 | for i, l in enumerate(f.read().splitlines()): |
|
329 | 328 | if i == 0: |
|
330 | 329 | originalwd = repo[l].rev() |
|
331 | 330 | elif i == 1: |
|
332 | 331 | target = repo[l].rev() |
|
333 | 332 | elif i == 2: |
|
334 | 333 | external = repo[l].rev() |
|
335 | 334 | elif i == 3: |
|
336 | 335 | collapse = bool(int(l)) |
|
337 | 336 | elif i == 4: |
|
338 | 337 | keep = bool(int(l)) |
|
339 | 338 | elif i == 5: |
|
340 | 339 | keepbranches = bool(int(l)) |
|
341 | 340 | else: |
|
342 | 341 | oldrev, newrev = l.split(':') |
|
343 | 342 | state[repo[oldrev].rev()] = repo[newrev].rev() |
|
344 | 343 | repo.ui.debug(_('rebase status resumed\n')) |
|
345 | 344 | return originalwd, target, state, collapse, keep, keepbranches, external |
|
346 | 345 | except IOError, err: |
|
347 | 346 | if err.errno != errno.ENOENT: |
|
348 | 347 | raise |
|
349 | 348 | raise util.Abort(_('no rebase in progress')) |
|
350 | 349 | |
|
351 | 350 | def abort(repo, originalwd, target, state): |
|
352 | 351 | 'Restore the repository to its original state' |
|
353 | 352 | if set(repo.changelog.descendants(target)) - set(state.values()): |
|
354 | 353 | repo.ui.warn(_("warning: new changesets detected on target branch, " |
|
355 | 354 | "not stripping\n")) |
|
356 | 355 | else: |
|
357 | 356 | # Strip from the first rebased revision |
|
358 | 357 | merge.update(repo, repo[originalwd].rev(), False, True, False) |
|
359 | 358 | rebased = filter(lambda x: x > -1, state.values()) |
|
360 | 359 | if rebased: |
|
361 | 360 | strippoint = min(rebased) |
|
362 | 361 | repair.strip(repo.ui, repo, repo[strippoint].node(), "strip") |
|
363 | 362 | clearstatus(repo) |
|
364 | 363 | repo.ui.status(_('rebase aborted\n')) |
|
365 | 364 | |
|
366 | 365 | def buildstate(repo, dest, src, base, collapse): |
|
367 | 366 | 'Define which revisions are going to be rebased and where' |
|
368 | 367 | targetancestors = set() |
|
369 | 368 | |
|
370 | 369 | if not dest: |
|
371 | 370 | # Destination defaults to the latest revision in the current branch |
|
372 | 371 | branch = repo[None].branch() |
|
373 | 372 | dest = repo[branch].rev() |
|
374 | 373 | else: |
|
375 | 374 | if 'qtip' in repo.tags() and (repo[dest].hex() in |
|
376 | 375 | [s.rev for s in repo.mq.applied]): |
|
377 | 376 | raise util.Abort(_('cannot rebase onto an applied mq patch')) |
|
378 | 377 | dest = repo[dest].rev() |
|
379 | 378 | |
|
380 | 379 | if src: |
|
381 | 380 | commonbase = repo[src].ancestor(repo[dest]) |
|
382 | 381 | if commonbase == repo[src]: |
|
383 | 382 | raise util.Abort(_('cannot rebase an ancestor')) |
|
384 | 383 | if commonbase == repo[dest]: |
|
385 | 384 | raise util.Abort(_('cannot rebase a descendant')) |
|
386 | 385 | source = repo[src].rev() |
|
387 | 386 | else: |
|
388 | 387 | if base: |
|
389 | 388 | cwd = repo[base].rev() |
|
390 | 389 | else: |
|
391 | 390 | cwd = repo['.'].rev() |
|
392 | 391 | |
|
393 | 392 | if cwd == dest: |
|
394 | 393 | repo.ui.debug(_('already working on current\n')) |
|
395 | 394 | return None |
|
396 | 395 | |
|
397 | 396 | targetancestors = set(repo.changelog.ancestors(dest)) |
|
398 | 397 | if cwd in targetancestors: |
|
399 | 398 | repo.ui.debug(_('already working on the current branch\n')) |
|
400 | 399 | return None |
|
401 | 400 | |
|
402 | 401 | cwdancestors = set(repo.changelog.ancestors(cwd)) |
|
403 | 402 | cwdancestors.add(cwd) |
|
404 | 403 | rebasingbranch = cwdancestors - targetancestors |
|
405 | 404 | source = min(rebasingbranch) |
|
406 | 405 | |
|
407 | 406 | repo.ui.debug(_('rebase onto %d starting from %d\n') % (dest, source)) |
|
408 | 407 | state = dict.fromkeys(repo.changelog.descendants(source), nullrev) |
|
409 | 408 | external = nullrev |
|
410 | 409 | if collapse: |
|
411 | 410 | if not targetancestors: |
|
412 | 411 | targetancestors = set(repo.changelog.ancestors(dest)) |
|
413 | 412 | for rev in state: |
|
414 | 413 | # Check externals and fail if there are more than one |
|
415 | 414 | for p in repo[rev].parents(): |
|
416 | 415 | if (p.rev() not in state and p.rev() != source |
|
417 | 416 | and p.rev() not in targetancestors): |
|
418 | 417 | if external != nullrev: |
|
419 | 418 | raise util.Abort(_('unable to collapse, there is more ' |
|
420 | 419 | 'than one external parent')) |
|
421 | 420 | external = p.rev() |
|
422 | 421 | |
|
423 | 422 | state[source] = nullrev |
|
424 | 423 | return repo['.'].rev(), repo[dest].rev(), state, external |
|
425 | 424 | |
|
426 | 425 | def pullrebase(orig, ui, repo, *args, **opts): |
|
427 | 426 | 'Call rebase after pull if the latter has been invoked with --rebase' |
|
428 | 427 | if opts.get('rebase'): |
|
429 | 428 | if opts.get('update'): |
|
430 | 429 | del opts['update'] |
|
431 | 430 | ui.debug(_('--update and --rebase are not compatible, ignoring ' |
|
432 | 431 | 'the update flag\n')) |
|
433 | 432 | |
|
434 | 433 | cmdutil.bail_if_changed(repo) |
|
435 | 434 | revsprepull = len(repo) |
|
436 | 435 | orig(ui, repo, *args, **opts) |
|
437 | 436 | revspostpull = len(repo) |
|
438 | 437 | if revspostpull > revsprepull: |
|
439 | 438 | rebase(ui, repo, **opts) |
|
440 | 439 | branch = repo[None].branch() |
|
441 | 440 | dest = repo[branch].rev() |
|
442 | 441 | if dest != repo['.'].rev(): |
|
443 | 442 | # there was nothing to rebase we force an update |
|
444 | 443 | merge.update(repo, dest, False, False, False) |
|
445 | 444 | else: |
|
446 | 445 | orig(ui, repo, *args, **opts) |
|
447 | 446 | |
|
448 | 447 | def uisetup(ui): |
|
449 | 448 | 'Replace pull with a decorator to provide --rebase option' |
|
450 | 449 | entry = extensions.wrapcommand(commands.table, 'pull', pullrebase) |
|
451 | 450 | entry[1].append(('', 'rebase', None, |
|
452 | 451 | _("rebase working directory to branch head")) |
|
453 | 452 | ) |
|
454 | 453 | |
|
455 | 454 | cmdtable = { |
|
456 | 455 | "rebase": |
|
457 | 456 | (rebase, |
|
458 | 457 | [ |
|
459 | 458 | ('s', 'source', '', _('rebase from a given revision')), |
|
460 | 459 | ('b', 'base', '', _('rebase from the base of a given revision')), |
|
461 | 460 | ('d', 'dest', '', _('rebase onto a given revision')), |
|
462 | 461 | ('', 'collapse', False, _('collapse the rebased revisions')), |
|
463 | 462 | ('', 'keep', False, _('keep original revisions')), |
|
464 | 463 | ('', 'keepbranches', False, _('keep original branches')), |
|
465 | 464 | ('c', 'continue', False, _('continue an interrupted rebase')), |
|
466 | 465 | ('a', 'abort', False, _('abort an interrupted rebase')),] + |
|
467 | 466 | templateopts, |
|
468 | 467 | _('hg rebase [-s REV | -b REV] [-d REV] [--collapse] [--keep] ' |
|
469 | 468 | '[--keepbranches] | [-c] | [-a]')), |
|
470 | 469 | } |
@@ -1,200 +1,200 b'' | |||
|
1 | 1 | % These fail |
|
2 | 2 | |
|
3 | 3 | % Use continue and abort |
|
4 | 4 | hg rebase: cannot use both abort and continue |
|
5 | 5 | hg rebase [-s REV | -b REV] [-d REV] [--collapse] [--keep] [--keepbranches] | [-c] | [-a] |
|
6 | 6 | |
|
7 | 7 | move changeset (and descendants) to a different branch |
|
8 | 8 | |
|
9 | Rebase uses repeated merging to graft changesets from one part of | |
|
10 |
|
|
|
11 |
|
|
|
9 | Rebase uses repeated merging to graft changesets from one part of history | |
|
10 | onto another. This can be useful for linearizing local changes relative to | |
|
11 | a master development tree. | |
|
12 | 12 | |
|
13 | 13 | If a rebase is interrupted to manually resolve a merge, it can be |
|
14 | 14 | continued with --continue/-c or aborted with --abort/-a. |
|
15 | 15 | |
|
16 | 16 | options: |
|
17 | 17 | |
|
18 | 18 | -s --source rebase from a given revision |
|
19 | 19 | -b --base rebase from the base of a given revision |
|
20 | 20 | -d --dest rebase onto a given revision |
|
21 | 21 | --collapse collapse the rebased revisions |
|
22 | 22 | --keep keep original revisions |
|
23 | 23 | --keepbranches keep original branches |
|
24 | 24 | -c --continue continue an interrupted rebase |
|
25 | 25 | -a --abort abort an interrupted rebase |
|
26 | 26 | --style display using template map file |
|
27 | 27 | --template display with template |
|
28 | 28 | |
|
29 | 29 | use "hg -v help rebase" to show global options |
|
30 | 30 | |
|
31 | 31 | % Use continue and collapse |
|
32 | 32 | hg rebase: cannot use collapse with continue or abort |
|
33 | 33 | hg rebase [-s REV | -b REV] [-d REV] [--collapse] [--keep] [--keepbranches] | [-c] | [-a] |
|
34 | 34 | |
|
35 | 35 | move changeset (and descendants) to a different branch |
|
36 | 36 | |
|
37 | Rebase uses repeated merging to graft changesets from one part of | |
|
38 |
|
|
|
39 |
|
|
|
37 | Rebase uses repeated merging to graft changesets from one part of history | |
|
38 | onto another. This can be useful for linearizing local changes relative to | |
|
39 | a master development tree. | |
|
40 | 40 | |
|
41 | 41 | If a rebase is interrupted to manually resolve a merge, it can be |
|
42 | 42 | continued with --continue/-c or aborted with --abort/-a. |
|
43 | 43 | |
|
44 | 44 | options: |
|
45 | 45 | |
|
46 | 46 | -s --source rebase from a given revision |
|
47 | 47 | -b --base rebase from the base of a given revision |
|
48 | 48 | -d --dest rebase onto a given revision |
|
49 | 49 | --collapse collapse the rebased revisions |
|
50 | 50 | --keep keep original revisions |
|
51 | 51 | --keepbranches keep original branches |
|
52 | 52 | -c --continue continue an interrupted rebase |
|
53 | 53 | -a --abort abort an interrupted rebase |
|
54 | 54 | --style display using template map file |
|
55 | 55 | --template display with template |
|
56 | 56 | |
|
57 | 57 | use "hg -v help rebase" to show global options |
|
58 | 58 | |
|
59 | 59 | % Use continue/abort and dest/source |
|
60 | 60 | hg rebase: abort and continue do not allow specifying revisions |
|
61 | 61 | hg rebase [-s REV | -b REV] [-d REV] [--collapse] [--keep] [--keepbranches] | [-c] | [-a] |
|
62 | 62 | |
|
63 | 63 | move changeset (and descendants) to a different branch |
|
64 | 64 | |
|
65 | Rebase uses repeated merging to graft changesets from one part of | |
|
66 |
|
|
|
67 |
|
|
|
65 | Rebase uses repeated merging to graft changesets from one part of history | |
|
66 | onto another. This can be useful for linearizing local changes relative to | |
|
67 | a master development tree. | |
|
68 | 68 | |
|
69 | 69 | If a rebase is interrupted to manually resolve a merge, it can be |
|
70 | 70 | continued with --continue/-c or aborted with --abort/-a. |
|
71 | 71 | |
|
72 | 72 | options: |
|
73 | 73 | |
|
74 | 74 | -s --source rebase from a given revision |
|
75 | 75 | -b --base rebase from the base of a given revision |
|
76 | 76 | -d --dest rebase onto a given revision |
|
77 | 77 | --collapse collapse the rebased revisions |
|
78 | 78 | --keep keep original revisions |
|
79 | 79 | --keepbranches keep original branches |
|
80 | 80 | -c --continue continue an interrupted rebase |
|
81 | 81 | -a --abort abort an interrupted rebase |
|
82 | 82 | --style display using template map file |
|
83 | 83 | --template display with template |
|
84 | 84 | |
|
85 | 85 | use "hg -v help rebase" to show global options |
|
86 | 86 | |
|
87 | 87 | % Use source and base |
|
88 | 88 | hg rebase: cannot specify both a revision and a base |
|
89 | 89 | hg rebase [-s REV | -b REV] [-d REV] [--collapse] [--keep] [--keepbranches] | [-c] | [-a] |
|
90 | 90 | |
|
91 | 91 | move changeset (and descendants) to a different branch |
|
92 | 92 | |
|
93 | Rebase uses repeated merging to graft changesets from one part of | |
|
94 |
|
|
|
95 |
|
|
|
93 | Rebase uses repeated merging to graft changesets from one part of history | |
|
94 | onto another. This can be useful for linearizing local changes relative to | |
|
95 | a master development tree. | |
|
96 | 96 | |
|
97 | 97 | If a rebase is interrupted to manually resolve a merge, it can be |
|
98 | 98 | continued with --continue/-c or aborted with --abort/-a. |
|
99 | 99 | |
|
100 | 100 | options: |
|
101 | 101 | |
|
102 | 102 | -s --source rebase from a given revision |
|
103 | 103 | -b --base rebase from the base of a given revision |
|
104 | 104 | -d --dest rebase onto a given revision |
|
105 | 105 | --collapse collapse the rebased revisions |
|
106 | 106 | --keep keep original revisions |
|
107 | 107 | --keepbranches keep original branches |
|
108 | 108 | -c --continue continue an interrupted rebase |
|
109 | 109 | -a --abort abort an interrupted rebase |
|
110 | 110 | --style display using template map file |
|
111 | 111 | --template display with template |
|
112 | 112 | |
|
113 | 113 | use "hg -v help rebase" to show global options |
|
114 | 114 | |
|
115 | 115 | % Rebase with no arguments - from current |
|
116 | 116 | nothing to rebase |
|
117 | 117 | |
|
118 | 118 | % Rebase with no arguments - from the current branch |
|
119 | 119 | 0 files updated, 0 files merged, 1 files removed, 0 files unresolved |
|
120 | 120 | nothing to rebase |
|
121 | 121 | % ---------- |
|
122 | 122 | % These work |
|
123 | 123 | |
|
124 | 124 | % Rebase with no arguments (from 3 onto 7) |
|
125 | 125 | 3 files updated, 0 files merged, 2 files removed, 0 files unresolved |
|
126 | 126 | saving bundle to |
|
127 | 127 | adding branch |
|
128 | 128 | adding changesets |
|
129 | 129 | adding manifests |
|
130 | 130 | adding file changes |
|
131 | 131 | added 5 changesets with 5 changes to 5 files |
|
132 | 132 | rebase completed |
|
133 | 133 | % Try to rollback after a rebase (fail) |
|
134 | 134 | no rollback information available |
|
135 | 135 | |
|
136 | 136 | % Rebase with base == '.' => same as no arguments (from 3 onto 7) |
|
137 | 137 | 3 files updated, 0 files merged, 3 files removed, 0 files unresolved |
|
138 | 138 | saving bundle to |
|
139 | 139 | adding branch |
|
140 | 140 | adding changesets |
|
141 | 141 | adding manifests |
|
142 | 142 | adding file changes |
|
143 | 143 | added 5 changesets with 5 changes to 5 files |
|
144 | 144 | rebase completed |
|
145 | 145 | |
|
146 | 146 | % Rebase with dest == default => same as no arguments (from 3 onto 7) |
|
147 | 147 | 3 files updated, 0 files merged, 3 files removed, 0 files unresolved |
|
148 | 148 | saving bundle to |
|
149 | 149 | adding branch |
|
150 | 150 | adding changesets |
|
151 | 151 | adding manifests |
|
152 | 152 | adding file changes |
|
153 | 153 | added 5 changesets with 5 changes to 5 files |
|
154 | 154 | rebase completed |
|
155 | 155 | |
|
156 | 156 | % Specify only source (from 4 onto 7) |
|
157 | 157 | saving bundle to |
|
158 | 158 | adding branch |
|
159 | 159 | adding changesets |
|
160 | 160 | adding manifests |
|
161 | 161 | adding file changes |
|
162 | 162 | added 4 changesets with 4 changes to 4 files (-1 heads) |
|
163 | 163 | rebase completed |
|
164 | 164 | |
|
165 | 165 | % Specify only dest (from 3 onto 6) |
|
166 | 166 | 3 files updated, 0 files merged, 3 files removed, 0 files unresolved |
|
167 | 167 | saving bundle to |
|
168 | 168 | adding branch |
|
169 | 169 | adding changesets |
|
170 | 170 | adding manifests |
|
171 | 171 | adding file changes |
|
172 | 172 | added 5 changesets with 5 changes to 5 files (+1 heads) |
|
173 | 173 | rebase completed |
|
174 | 174 | |
|
175 | 175 | % Specify only base (from 3 onto 7) |
|
176 | 176 | saving bundle to |
|
177 | 177 | adding branch |
|
178 | 178 | adding changesets |
|
179 | 179 | adding manifests |
|
180 | 180 | adding file changes |
|
181 | 181 | added 5 changesets with 5 changes to 5 files |
|
182 | 182 | rebase completed |
|
183 | 183 | |
|
184 | 184 | % Specify source and dest (from 4 onto 6) |
|
185 | 185 | saving bundle to |
|
186 | 186 | adding branch |
|
187 | 187 | adding changesets |
|
188 | 188 | adding manifests |
|
189 | 189 | adding file changes |
|
190 | 190 | added 4 changesets with 4 changes to 4 files |
|
191 | 191 | rebase completed |
|
192 | 192 | |
|
193 | 193 | % Specify base and dest (from 3 onto 6) |
|
194 | 194 | saving bundle to |
|
195 | 195 | adding branch |
|
196 | 196 | adding changesets |
|
197 | 197 | adding manifests |
|
198 | 198 | adding file changes |
|
199 | 199 | added 5 changesets with 5 changes to 5 files (+1 heads) |
|
200 | 200 | rebase completed |
General Comments 0
You need to be logged in to leave comments.
Login now