зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1361972 - [mozlint] Add ability to only lint staged changes to --workdir with git r=standard8
MozReview-Commit-ID: DUxCKN2fiag --HG-- extra : rebase_source : 11bb7808c7d0f1c02eaea93dc61723d17e921eeb
This commit is contained in:
Родитель
7c75a303b6
Коммит
6e2032d8c4
|
@ -49,10 +49,13 @@ class MozlintParser(ArgumentParser):
|
|||
"mercurial or git."
|
||||
}],
|
||||
[['-w', '--workdir'],
|
||||
{'default': False,
|
||||
'action': 'store_true',
|
||||
{'const': 'all',
|
||||
'nargs': '?',
|
||||
'choices': ['staged', 'all'],
|
||||
'help': "Lint files touched by changes in the working directory "
|
||||
"(i.e haven't been committed yet). Works with mercurial or git.",
|
||||
"(i.e haven't been committed yet). On git, --workdir=staged "
|
||||
"can be used to only consider staged files. Works with "
|
||||
"mercurial or git.",
|
||||
}],
|
||||
[['extra_args'],
|
||||
{'nargs': REMAINDER,
|
||||
|
@ -67,6 +70,13 @@ class MozlintParser(ArgumentParser):
|
|||
self.add_argument(*cli, **args)
|
||||
|
||||
def parse_known_args(self, *args, **kwargs):
|
||||
# Allow '-wo' or '-ow' as shorthand for both --workdir and --outgoing.
|
||||
for token in ('-wo', '-ow'):
|
||||
if token in args[0]:
|
||||
i = args[0].index(token)
|
||||
args[0].pop(i)
|
||||
args[0][i:i] = [token[:2], '-' + token[2]]
|
||||
|
||||
# This is here so the eslint mach command doesn't lose 'extra_args'
|
||||
# when using mach's dispatch functionality.
|
||||
args, extra = ArgumentParser.parse_known_args(self, *args, **kwargs)
|
||||
|
|
|
@ -111,7 +111,7 @@ class LintRoller(object):
|
|||
|
||||
# Calculate files from VCS
|
||||
if workdir:
|
||||
paths.update(self.vcs.by_workdir())
|
||||
paths.update(self.vcs.by_workdir(workdir))
|
||||
if outgoing:
|
||||
paths.update(self.vcs.by_outgoing(outgoing))
|
||||
|
||||
|
|
|
@ -44,7 +44,7 @@ class VCSHelper(object):
|
|||
return []
|
||||
return [os.path.join(self.root, f) for f in files if f]
|
||||
|
||||
def by_workdir(self, workdir):
|
||||
def by_workdir(self, mode):
|
||||
return []
|
||||
|
||||
def by_outgoing(self, dest='default'):
|
||||
|
@ -58,7 +58,7 @@ class HgHelper(VCSHelper):
|
|||
return self.run(['hg', 'outgoing', '--quiet', '--template',
|
||||
"{file_mods % '\\n{file}'}{file_adds % '\\n{file}'}", '-r', '.', dest])
|
||||
|
||||
def by_workdir(self):
|
||||
def by_workdir(self, mode):
|
||||
return self.run(['hg', 'status', '-amn'])
|
||||
|
||||
|
||||
|
@ -95,8 +95,13 @@ class GitHelper(VCSHelper):
|
|||
return self.run(['git', 'log', '--name-only', '--diff-filter=AM',
|
||||
'--oneline', '--pretty=format:', comparing])
|
||||
|
||||
def by_workdir(self):
|
||||
return self.run(['git', 'diff', '--name-only', '--diff-filter=AM', 'HEAD'])
|
||||
def by_workdir(self, mode):
|
||||
cmd = ['git', 'diff', '--name-only', '--diff-filter=AM']
|
||||
if mode == 'staged':
|
||||
cmd.append('--cached')
|
||||
else:
|
||||
cmd.append('HEAD')
|
||||
return self.run(cmd)
|
||||
|
||||
|
||||
vcs_class = {
|
||||
|
|
|
@ -102,13 +102,18 @@ def test_vcs_helper(repo):
|
|||
|
||||
next(repo.setup)
|
||||
|
||||
assert_files(vcs.by_workdir(), ['bar', 'baz'])
|
||||
assert_files(vcs.by_workdir('all'), ['bar', 'baz'])
|
||||
if repo.vcs == 'git':
|
||||
assert_files(vcs.by_workdir('staged'), ['baz'])
|
||||
elif repo.vcs == 'hg':
|
||||
assert_files(vcs.by_workdir('staged'), ['bar', 'baz'])
|
||||
assert_files(vcs.by_outgoing(), [])
|
||||
assert_files(vcs.by_outgoing(remotepath), [])
|
||||
|
||||
next(repo.setup)
|
||||
|
||||
assert_files(vcs.by_workdir(), [])
|
||||
assert_files(vcs.by_workdir('all'), [])
|
||||
assert_files(vcs.by_workdir('staged'), [])
|
||||
assert_files(vcs.by_outgoing(), ['bar', 'baz'])
|
||||
assert_files(vcs.by_outgoing(remotepath), ['bar', 'baz'])
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче