Commit 259e4689 authored by ukai@chromium.org's avatar ukai@chromium.org

git-cl: show dirty files if any

R=chase@chromium.org,szager@chromium.org,maruel@chromium.org
BUG=157398
Review URL: https://codereview.chromium.org/11262004

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@164026 0039d316-1c4b-4281-b951-d872f2087c98
parent 91668b70
...@@ -150,6 +150,19 @@ def add_git_similarity(parser): ...@@ -150,6 +150,19 @@ def add_git_similarity(parser):
parser.parse_args = Parse parser.parse_args = Parse
def is_dirty_git_tree(cmd):
# Make sure index is up-to-date before running diff-index.
RunGit(['update-index', '--refresh', '-q'], error_ok=True)
dirty = RunGit(['diff-index', '--name-status', 'HEAD'])
if dirty:
print 'Cannot %s with a dirty tree. You must commit locally first.' % cmd
print 'Uncommitted files: (git diff-index --name-status HEAD)'
print dirty[:4096]
if len(dirty) > 4096:
print '... (run "git diff-index --name-status HEAD" to see full output).'
return True
return False
def MatchSvnGlob(url, base_url, glob_spec, allow_wildcards): def MatchSvnGlob(url, base_url, glob_spec, allow_wildcards):
"""Return the corresponding git ref if |base_url| together with |glob_spec| """Return the corresponding git ref if |base_url| together with |glob_spec|
matches the full |url|. matches the full |url|.
...@@ -997,12 +1010,8 @@ def CMDpresubmit(parser, args): ...@@ -997,12 +1010,8 @@ def CMDpresubmit(parser, args):
help='Run checks even if tree is dirty') help='Run checks even if tree is dirty')
(options, args) = parser.parse_args(args) (options, args) = parser.parse_args(args)
# Make sure index is up-to-date before running diff-index. if not options.force and is_dirty_git_tree('presubmit'):
RunGit(['update-index', '--refresh', '-q'], error_ok=True) print 'use --force to check even if tree is dirty.'
if not options.force and RunGit(['diff-index', 'HEAD']):
# TODO(maruel): Is this really necessary?
print ('Cannot presubmit with a dirty tree.\n'
'You must commit locally first (or use --force).')
return 1 return 1
cl = Changelist() cl = Changelist()
...@@ -1199,10 +1208,7 @@ def CMDupload(parser, args): ...@@ -1199,10 +1208,7 @@ def CMDupload(parser, args):
'In the near future, -m or --message will send a message instead.\n' 'In the near future, -m or --message will send a message instead.\n'
'See http://goo.gl/JGg0Z for details.\n') 'See http://goo.gl/JGg0Z for details.\n')
# Make sure index is up-to-date before running diff-index. if is_dirty_git_tree('upload'):
RunGit(['update-index', '--refresh', '-q'], error_ok=True)
if RunGit(['diff-index', 'HEAD']):
print 'Cannot upload with a dirty tree. You must commit locally first.'
return 1 return 1
cl = Changelist() cl = Changelist()
...@@ -1272,10 +1278,7 @@ def SendUpstream(parser, args, cmd): ...@@ -1272,10 +1278,7 @@ def SendUpstream(parser, args, cmd):
base_branch = args[0] base_branch = args[0]
base_has_submodules = IsSubmoduleMergeCommit(base_branch) base_has_submodules = IsSubmoduleMergeCommit(base_branch)
# Make sure index is up-to-date before running diff-index. if is_dirty_git_tree(cmd):
RunGit(['update-index', '--refresh', '-q'], error_ok=True)
if RunGit(['diff-index', 'HEAD']):
print 'Cannot %s with a dirty tree. You must commit locally first.' % cmd
return 1 return 1
# This rev-list syntax means "show all commits not in my branch that # This rev-list syntax means "show all commits not in my branch that
......
...@@ -132,7 +132,7 @@ class TestGitCl(TestCase): ...@@ -132,7 +132,7 @@ class TestGitCl(TestCase):
((['git', 'symbolic-ref', 'HEAD'],), 'master'), ((['git', 'symbolic-ref', 'HEAD'],), 'master'),
find_copies_call, find_copies_call,
((['git', 'update-index', '--refresh', '-q'],), ''), ((['git', 'update-index', '--refresh', '-q'],), ''),
((['git', 'diff-index', 'HEAD'],), ''), ((['git', 'diff-index', '--name-status', 'HEAD'],), ''),
((['git', 'symbolic-ref', 'HEAD'],), 'master'), ((['git', 'symbolic-ref', 'HEAD'],), 'master'),
((['git', 'config', 'branch.master.merge'],), 'master'), ((['git', 'config', 'branch.master.merge'],), 'master'),
((['git', 'config', 'branch.master.remote'],), 'origin'), ((['git', 'config', 'branch.master.remote'],), 'origin'),
...@@ -185,7 +185,7 @@ class TestGitCl(TestCase): ...@@ -185,7 +185,7 @@ class TestGitCl(TestCase):
'--grep=^SVN changes up to revision [0-9]*$', '--grep=^SVN changes up to revision [0-9]*$',
'refs/remotes/origin/master^!'],), ''), 'refs/remotes/origin/master^!'],), ''),
((['git', 'update-index', '--refresh', '-q'],), ''), ((['git', 'update-index', '--refresh', '-q'],), ''),
((['git', 'diff-index', 'HEAD'],), ''), ((['git', 'diff-index', '--name-status', 'HEAD'],), ''),
((['git', 'rev-list', '^refs/heads/working', ((['git', 'rev-list', '^refs/heads/working',
'refs/remotes/origin/master'],), 'refs/remotes/origin/master'],),
''), ''),
...@@ -415,7 +415,7 @@ class TestGitCl(TestCase): ...@@ -415,7 +415,7 @@ class TestGitCl(TestCase):
((['git', 'config', '--int', '--get', ((['git', 'config', '--int', '--get',
'branch.master.git-find-copies'],), ''), 'branch.master.git-find-copies'],), ''),
((['git', 'update-index', '--refresh', '-q'],), ''), ((['git', 'update-index', '--refresh', '-q'],), ''),
((['git', 'diff-index', 'HEAD'],), ''), ((['git', 'diff-index', '--name-status', 'HEAD'],), ''),
((['git', 'symbolic-ref', 'HEAD'],), 'master'), ((['git', 'symbolic-ref', 'HEAD'],), 'master'),
((['git', 'config', 'branch.master.merge'],), 'master'), ((['git', 'config', 'branch.master.merge'],), 'master'),
((['git', 'config', 'branch.master.remote'],), 'origin'), ((['git', 'config', 'branch.master.remote'],), 'origin'),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment