Skip to content
This repository has been archived by the owner on Jan 30, 2022. It is now read-only.

Commit

Permalink
Merge pull request #6 from sbuss/ignore_untracked
Browse files Browse the repository at this point in the history
Add --ignore-untracked flag
  • Loading branch information
jenanwise committed Jan 30, 2014
2 parents 4fc0b5c + 42df991 commit 490e9ba
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
8 changes: 7 additions & 1 deletion codequality/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ def codequality(self, paths):

checker_to_loc_to_filename = {}
for filename, location in scmhandler.srcs_to_check(
paths, rev=self.options.rev):
paths, rev=self.options.rev,
ignore_untracked=self.options.ignore_untracked):

if self._should_ignore(filename):
continue
Expand Down Expand Up @@ -240,6 +241,11 @@ def main():
action='store_true', default=False,
help='Prints extra information to stderr.',
)
parser.add_option(
'--ignore-untracked', dest='ignore_untracked',
action='store_true', default=False,
help='Ignore untracked files (only applicable if using scm).',
)

options, paths = parser.parse_args()

Expand Down
14 changes: 10 additions & 4 deletions codequality/scmhandlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,12 @@ class GitHandler(SCMHandler):
"""
# Begin public API

def srcs_to_check(self, limit_paths, rev=None):
def srcs_to_check(self, limit_paths, rev=None, ignore_untracked=False):
rev = self._resolve_rev(rev)

relative_paths = self._add_and_modified_in_rev(rev) \
if rev else self._add_and_modified_in_working_copy()
if rev else self._add_and_modified_in_working_copy(
ignore_untracked)

if limit_paths:
relative_paths = set(relative_paths).intersection(limit_paths)
Expand All @@ -92,7 +93,7 @@ def srcs_to_check(self, limit_paths, rev=None):
r'^ (?P<type>\w+) mode (?P<mode>\w+) (?P<path>.+)')
GIT_SUBMODULE_MODE = 160000

def _add_and_modified_in_working_copy(self):
def _add_and_modified_in_working_copy(self, ignore_untracked=False):
inside_work_tree = \
self._git_cmd('rev-parse --is-inside-work-tree') == 'true'
if not inside_work_tree:
Expand All @@ -112,7 +113,12 @@ def _add_and_modified_in_working_copy(self):
#
# Note that we use "." at the end of the status command to limit
# paths to those under the current working directory.
cmd = 'status --porcelain --untracked-files=all .'
if ignore_untracked:
untracked = "no"
else:
untracked = "all"
cmd = 'status --porcelain --untracked-files={untracked} .'.format(
untracked=untracked)
status_output = self._git_cmd(cmd)

for line in status_output.splitlines():
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

setup(
name='codequality',
version='0.2-dev',
version='0.2.1-dev',
url='http://github.com/jenanwise/codequality',
description='Simple code checking metatool',
long_description=''.join(open('README.rst')),
Expand Down

0 comments on commit 490e9ba

Please sign in to comment.