diff --git a/hgext3rd/fbamend/movement.py b/hgext3rd/fbamend/movement.py --- a/hgext3rd/fbamend/movement.py +++ b/hgext3rd/fbamend/movement.py @@ -33,7 +33,9 @@ @command( '^previous', - [('', 'newest', False, + [('', 'clean', False, + _('discard uncommitted changes (no backup)')), + ('', 'newest', False, _('always pick the newest parent when a changeset has multiple parents')), ('', 'bottom', False, _('update to the lowest non-public ancestor of the current changeset')), @@ -48,7 +50,9 @@ @command( '^next', - [('', 'newest', False, + [('', 'clean', False, + _('discard uncommitted changes (no backup)')), + ('', 'newest', False, _('always pick the newest child when a changeset has multiple children')), ('', 'rebase', False, _('rebase each changeset if necessary')), ('', 'top', False, _('update to the head of the current stack')), @@ -99,17 +103,23 @@ raise error.Abort(_("cannot use both --bottom and --bookmark")) if opts.get('towards', False) and opts.get('top', False): raise error.Abort(_("cannot use both --top and --towards")) + if opts.get('merge', False) and opts.get('rebase', False): + raise error.Abort(_("cannot use both --merge and --rebase")) # Check if there is an outstanding operation or uncommited changes. cmdutil.checkunfinished(repo) - if not opts.get('merge', False): + if not opts.get('clean', False) and not opts.get('merge', False): try: cmdutil.bailifchanged(repo) except error.Abort as e: - e.hint = _("use --merge to merge uncommitted changes") + e.hint = _("use --clean to discard uncommitted changes " + "or --merge to bring them along") raise - elif opts.get('rebase', False): - raise error.Abort(_("cannot use both --merge and --rebase")) + + # If we have both --clean and --rebase, we need to discard any outstanding + # changes now before we attempt to perform any rebases. + if opts.get('clean') and opts.get('rebase'): + commands.update(ui, repo, rev=repo['.'].rev(), clean=True) with repo.wlock(), repo.lock(): # Record the active bookmark, if any. @@ -133,7 +143,8 @@ _setbookmark(repo, tr, bookmark, target) # Update to the target changeset. - commands.update(ui, repo, rev=target) + commands.update(ui, repo, rev=target, + clean=opts.get('clean', False)) # Print out the changeset we landed on. _showchangesets(ui, repo, revs=[target]) diff --git a/tests/test-fbamend-next.t b/tests/test-fbamend-next.t --- a/tests/test-fbamend-next.t +++ b/tests/test-fbamend-next.t @@ -20,6 +20,7 @@ options: + --clean discard uncommitted changes (no backup) --newest always pick the newest child when a changeset has multiple children --rebase rebase each changeset if necessary @@ -134,6 +135,26 @@ (leaving bookmark bookmark) [c8d03c] (top) r5 +Test dirty working copy and --clean. + $ hg up bottom + 0 files updated, 0 files merged, 0 files removed, 0 files unresolved + (activating bookmark bottom) + $ touch test + $ hg add test + $ hg st + A test + $ hg next + abort: uncommitted changes + (use --clean to discard uncommitted changes or --merge to bring them along) + [255] + $ hg next --clean + 0 files updated, 0 files merged, 0 files removed, 0 files unresolved + (leaving bookmark bottom) + [66f7d4] r1 + $ hg st + ? test + $ rm test + Test dirty working copy and --merge. $ hg up bottom 0 files updated, 0 files merged, 0 files removed, 0 files unresolved @@ -144,7 +165,7 @@ A test $ hg next abort: uncommitted changes - (use --merge to merge uncommitted changes) + (use --clean to discard uncommitted changes or --merge to bring them along) [255] $ hg next --merge 0 files updated, 0 files merged, 0 files removed, 0 files unresolved @@ -193,7 +214,6 @@ date: Thu Jan 01 00:00:00 1970 +0000 summary: r0 - $ hg next --top --newest 1 files updated, 0 files merged, 0 files removed, 0 files unresolved (leaving bookmark bottom) diff --git a/tests/test-fbamend-nextrebase.t b/tests/test-fbamend-nextrebase.t --- a/tests/test-fbamend-nextrebase.t +++ b/tests/test-fbamend-nextrebase.t @@ -58,6 +58,31 @@ |/ o 0 r0 +Test --clean flag. + $ touch foo + $ hg add foo + $ hg status + A foo + $ hg next --rebase + abort: uncommitted changes + (use --clean to discard uncommitted changes or --merge to bring them along) + [255] + $ hg next --rebase --clean + 0 files updated, 0 files merged, 0 files removed, 0 files unresolved + rebasing 3:137d867d71d5 "r3" + 1 files updated, 0 files merged, 0 files removed, 0 files unresolved + [7d603c] r3 + $ hg status + ? foo + $ showgraph + @ 6 r3 + | + o 5 r2 + | + o 4 amended + | + o 0 r0 + Rebasing multiple changesets at once. $ reset diff --git a/tests/test-fbamend-previous.t b/tests/test-fbamend-previous.t --- a/tests/test-fbamend-previous.t +++ b/tests/test-fbamend-previous.t @@ -17,6 +17,7 @@ options: + --clean discard uncommitted changes (no backup) --newest always pick the newest parent when a changeset has multiple parents --bottom update to the lowest non-public ancestor of the @@ -109,7 +110,7 @@ A test $ hg previous abort: uncommitted changes - (use --merge to merge uncommitted changes) + (use --clean to discard uncommitted changes or --merge to bring them along) [255] $ hg previous --merge 0 files updated, 0 files merged, 0 files removed, 0 files unresolved @@ -117,3 +118,14 @@ [bebd16] r4 $ hg st A test + +Test dirty working copy and --clean. + $ hg previous + abort: uncommitted changes + (use --clean to discard uncommitted changes or --merge to bring them along) + [255] + $ hg previous --clean + 0 files updated, 0 files merged, 0 files removed, 0 files unresolved + [2dc09a] r3 + $ hg st + ? test