Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --git-ignore-pattern option. #66

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 9 additions & 2 deletions gbp/git/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,7 @@ def force_head(self, commit, hard=False):
args.add(commit, '--')
self._git_command("reset", args.args)

def _status(self, porcelain, ignore_untracked, paths):
def _status(self, porcelain, ignore_untracked, ignore_pattern, paths):
args = GitArgs()
args.add_true(ignore_untracked, '-uno')
args.add_true(porcelain, '--porcelain')
Expand All @@ -842,11 +842,15 @@ def _status(self, porcelain, ignore_untracked, paths):
out, ret = self._git_getoutput('status',
args.args + paths,
extra_env={'LC_ALL': 'C'})
if ignore_pattern:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be skipped when ignore_untracked is true

regex = re.compile(ignore_pattern.encode('utf-8'))
out = [i for i in out if not regex.search(i)]

if ret:
raise GitRepositoryError("Can't get repository status")
return out

def is_clean(self, ignore_untracked=False, paths=None):
def is_clean(self, ignore_untracked=False, paths=None, ignore_pattern=None):
"""
Does the repository contain any uncommitted modifications?

Expand All @@ -859,16 +863,19 @@ def is_clean(self, ignore_untracked=False, paths=None):
and Git's status message
@rtype: C{tuple}
"""

if self.bare:
return (True, '')

out = self._status(porcelain=True,
ignore_untracked=ignore_untracked,
ignore_pattern=ignore_pattern,
paths=paths)
if out:
# Get a more helpful error message.
out = self._status(porcelain=False,
ignore_untracked=ignore_untracked,
ignore_pattern=ignore_pattern,
paths=paths)
return (False, "".join([e.decode() for e in out]))
else:
Expand Down
6 changes: 4 additions & 2 deletions gbp/scripts/buildpackage.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,11 @@ def clean_working_tree(options, repo):
"""
Command(options.cleaner, shell=True)()
if not options.ignore_new:
(ret, out) = repo.is_clean()
(ret, out) = repo.is_clean(ignore_pattern=options.ignore_pattern)
if not ret:
gbp.log.err("You have uncommitted changes in your source tree:")
gbp.log.err(out)
raise GbpError("Use --git-ignore-new to ignore.")
raise GbpError("Use --git-ignore-new or --git-ignore-pattern to ignore.")


def check_tag(options, repo, source):
Expand Down Expand Up @@ -361,6 +361,8 @@ def build_parser(name, prefix=None):
parser.add_option_group(group)

parser.add_boolean_config_file_option(option_name="ignore-new", dest="ignore_new")
parser.add_option("--git-ignore-pattern", dest="ignore_pattern", default=None,
help="regex to ignore new or dirty files")
parser.add_option("--git-verbose", action="store_true", dest="verbose", default=False,
help="verbose command execution")
parser.add_config_file_option(option_name="color", dest="color", type='tristate')
Expand Down