upload: add ‘--ignore-untracked-files’ option

This option will suppress the

    Uncommitted changes in ... (did you forget to amend?)

prompt when there are untracked (unknown) files in the working copy.
The prompt is still shown if tracked files are modified.

Change-Id: Ia3fcc82989b7fad09b69214eda31e2d0dfc14600
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/340456
Tested-by: Martin Geisler <mgeisler@google.com>
Reviewed-by: Mike Frysinger <vapier@google.com>
This commit is contained in:
Martin Geisler 2022-07-08 10:50:10 +02:00
parent d47d9ff1cb
commit 9fb64ae29c
2 changed files with 16 additions and 2 deletions

View File

@ -650,7 +650,7 @@ class Project(object):
return True return True
if self.work_git.DiffZ('diff-files'): if self.work_git.DiffZ('diff-files'):
return True return True
if consider_untracked and self.work_git.LsOthers(): if consider_untracked and self.UntrackedFiles():
return True return True
return False return False
@ -779,12 +779,16 @@ class Project(object):
if not get_all: if not get_all:
return details return details
changes = self.work_git.LsOthers() changes = self.UntrackedFiles()
if changes: if changes:
details.extend(changes) details.extend(changes)
return details return details
def UntrackedFiles(self):
"""Returns a list of strings, untracked files in the git tree."""
return self.work_git.LsOthers()
def HasChanges(self): def HasChanges(self):
"""Returns true if there are uncommitted changes. """Returns true if there are uncommitted changes.
""" """

View File

@ -204,6 +204,12 @@ Gerrit Code Review: https://www.gerritcodereview.com/
p.add_option('-y', '--yes', p.add_option('-y', '--yes',
default=False, action='store_true', default=False, action='store_true',
help='answer yes to all safe prompts') help='answer yes to all safe prompts')
p.add_option('--ignore-untracked-files',
action='store_true', default=False,
help='ignore untracked files in the working copy')
p.add_option('--no-ignore-untracked-files',
dest='ignore_untracked_files', action='store_false',
help='always ask about untracked files in the working copy')
p.add_option('--no-cert-checks', p.add_option('--no-cert-checks',
dest='validate_certs', action='store_false', default=True, dest='validate_certs', action='store_false', default=True,
help='disable verifying ssl certs (unsafe)') help='disable verifying ssl certs (unsafe)')
@ -370,6 +376,10 @@ Gerrit Code Review: https://www.gerritcodereview.com/
# Check if there are local changes that may have been forgotten # Check if there are local changes that may have been forgotten
changes = branch.project.UncommitedFiles() changes = branch.project.UncommitedFiles()
if opt.ignore_untracked_files:
untracked = set(branch.project.UntrackedFiles())
changes = [x for x in changes if x not in untracked]
if changes: if changes:
key = 'review.%s.autoupload' % branch.project.remote.review key = 'review.%s.autoupload' % branch.project.remote.review
answer = branch.project.config.GetBoolean(key) answer = branch.project.config.GetBoolean(key)