Merge "upload: report names of uncommitted files"

This commit is contained in:
Conley Owens 2014-10-21 18:03:53 +00:00 committed by Gerrit Code Review
commit b4e50e67e8
2 changed files with 38 additions and 12 deletions

View File

@ -736,26 +736,48 @@ class Project(object):
return matched return matched
## Status Display ## ## Status Display ##
def UncommitedFiles(self, get_all=True):
"""Returns a list of strings, uncommitted files in the git tree.
def HasChanges(self): Args:
"""Returns true if there are uncommitted changes. get_all: a boolean, if True - get information about all different
uncommitted files. If False - return as soon as any kind of
uncommitted files is detected.
""" """
details = []
self.work_git.update_index('-q', self.work_git.update_index('-q',
'--unmerged', '--unmerged',
'--ignore-missing', '--ignore-missing',
'--refresh') '--refresh')
if self.IsRebaseInProgress(): if self.IsRebaseInProgress():
return True details.append("rebase in progress")
if not get_all:
return details
if self.work_git.DiffZ('diff-index', '--cached', HEAD): changes = self.work_git.DiffZ('diff-index', '--cached', HEAD).keys()
return True if changes:
details.extend(changes)
if not get_all:
return details
if self.work_git.DiffZ('diff-files'): changes = self.work_git.DiffZ('diff-files').keys()
return True if changes:
details.extend(changes)
if not get_all:
return details
if self.work_git.LsOthers(): changes = self.work_git.LsOthers()
return True if changes:
details.extend(changes)
return details
def HasChanges(self):
"""Returns true if there are uncommitted changes.
"""
if self.UncommitedFiles(get_all=False):
return True
else:
return False return False
def PrintWorkTreeStatus(self, output_redir=None): def PrintWorkTreeStatus(self, output_redir=None):

View File

@ -339,13 +339,17 @@ Gerrit Code Review: http://code.google.com/p/gerrit/
self._AppendAutoList(branch, people) self._AppendAutoList(branch, people)
# Check if there are local changes that may have been forgotten # Check if there are local changes that may have been forgotten
if branch.project.HasChanges(): changes = branch.project.UncommitedFiles()
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)
# if they want to auto upload, let's not ask because it could be automated # if they want to auto upload, let's not ask because it could be automated
if answer is None: if answer is None:
sys.stdout.write('Uncommitted changes in ' + branch.project.name + ' (did you forget to amend?). Continue uploading? (y/N) ') sys.stdout.write('Uncommitted changes in ' + branch.project.name)
sys.stdout.write(' (did you forget to amend?):\n')
sys.stdout.write('\n'.join(changes) + '\n')
sys.stdout.write('Continue uploading? (y/N) ')
a = sys.stdin.readline().strip().lower() a = sys.stdin.readline().strip().lower()
if a not in ('y', 'yes', 't', 'true', 'on'): if a not in ('y', 'yes', 't', 'true', 'on'):
print("skipping upload", file=sys.stderr) print("skipping upload", file=sys.stderr)