view tests/autodiff.py @ 34192:da2f5f19312c

uncommit: move fb-extension to core which uncommits a changeset uncommit extension in fb-hgext adds a uncommit command which by default uncommits a changeset and move all the changes to the working directory. If file names are passed, uncommit moves the changes from those files to the working directory and left the changeset with remaining committed files. The uncommit extension in fb-hgext does not creates an empty commit like the one in evolve extension unless user has specified ui.alllowemptycommit to True. The test file added is a combination of tests from test-uncommit.t, test-uncommit-merge.t and test-uncommit-bookmark.t from fb-hgext. .. feature:: A new uncommit extension which provides `hg uncommit` using which one can uncommit part or all of the changeset. This command undoes the effect of a local commit, returning the affected files to their uncommitted state. Differential Revision: https://phab.mercurial-scm.org/D529
author Pulkit Goyal <7895pulkit@gmail.com>
date Thu, 24 Aug 2017 22:55:56 +0530
parents 46ba2cdda476
children 154754d1f137
line wrap: on
line source

# Extension dedicated to test patch.diff() upgrade modes

from __future__ import absolute_import

from mercurial import (
    error,
    patch,
    registrar,
    scmutil,
)

cmdtable = {}
command = registrar.command(cmdtable)

@command('autodiff',
    [('', 'git', '', 'git upgrade mode (yes/no/auto/warn/abort)')],
    '[OPTION]... [FILE]...')
def autodiff(ui, repo, *pats, **opts):
    diffopts = patch.difffeatureopts(ui, opts)
    git = opts.get('git', 'no')
    brokenfiles = set()
    losedatafn = None
    if git in ('yes', 'no'):
        diffopts.git = git == 'yes'
        diffopts.upgrade = False
    elif git == 'auto':
        diffopts.git = False
        diffopts.upgrade = True
    elif git == 'warn':
        diffopts.git = False
        diffopts.upgrade = True
        def losedatafn(fn=None, **kwargs):
            brokenfiles.add(fn)
            return True
    elif git == 'abort':
        diffopts.git = False
        diffopts.upgrade = True
        def losedatafn(fn=None, **kwargs):
            raise error.Abort('losing data for %s' % fn)
    else:
        raise error.Abort('--git must be yes, no or auto')

    node1, node2 = scmutil.revpair(repo, [])
    m = scmutil.match(repo[node2], pats, opts)
    it = patch.diff(repo, node1, node2, match=m, opts=diffopts,
                    losedatafn=losedatafn)
    for chunk in it:
        ui.write(chunk)
    for fn in sorted(brokenfiles):
        ui.write(('data lost for: %s\n' % fn))