diff --git a/hgext3rd/uncommit.py b/hgext3rd/uncommit.py --- a/hgext3rd/uncommit.py +++ b/hgext3rd/uncommit.py @@ -44,8 +44,9 @@ repo._bookmarks.applychanges(repo, tr, changes) def _commitfiltered(repo, ctx, match): - """Recommit ctx with changed files not in match. Return the new - node identifier, or None if nothing changed. + """Recommit ctx with changed files not in match. Returns tuple of + (newid, isnew), where newid is the new node identifier, or None if + nothing changed, and isnew is True if the new node is a new commit. """ base = ctx.p1() # ctx @@ -54,11 +55,11 @@ # No files matched commit, so nothing excluded if not exclude: - return None + return None, False files = (initialfiles - exclude) if not files: - return ctx.parents()[0].node() + return ctx.parents()[0].node(), False # Filter copies copied = copies.pathcopies(base, ctx) @@ -83,7 +84,7 @@ date=ctx.date(), extra=ctx.extra()) newid = repo.commitctx(new) - return newid + return newid, True def _uncommitdirstate(repo, oldctx, match): """Fix the dirstate after switching the working directory from @@ -157,13 +158,16 @@ with repo.transaction('uncommit') as tr: match = scmutil.match(old, pats, opts) - newid = _commitfiltered(repo, old, match) + newid, isnew = _commitfiltered(repo, old, match) if newid is None: raise error.Abort(_('nothing to uncommit')) # Move local changes on filtered changeset - obsolete.createmarkers(repo, [(old, (repo[newid],))]) - phases.retractboundary(repo, tr, oldphase, [newid]) + if isnew: + obsolete.createmarkers(repo, [(old, (repo[newid],))]) + phases.retractboundary(repo, tr, oldphase, [newid]) + else: + obsolete.createmarkers(repo, [(old, ())]) with repo.dirstate.parentchange(): repo.dirstate.setparents(newid, node.nullid) diff --git a/tests/test-uncommit.t b/tests/test-uncommit.t --- a/tests/test-uncommit.t +++ b/tests/test-uncommit.t @@ -174,4 +174,29 @@ |/ o 0:3004d2d9b50883c1538fc754a3aeb55f1b4084f6 added file-a +Uncommit with draft parent + $ hg uncommit + $ hg phase -r . + 10: draft + $ hg commit -m 'update ab again' + +Uncommit with public parent + + $ hg phase -p "::.^" + $ hg uncommit + $ hg phase -r . + 10: public + +Partial uncommit with public parent + + $ echo xyz > xyz + $ hg add xyz + $ hg commit -m "update ab and add xyz" + $ hg uncommit xyz + $ hg status + A xyz + $ hg phase -r . + 14: draft + $ hg phase -r ".^" + 10: public