[gclient_scm] Update _CheckClean() to use `git status`

This change updates the `_CheckClean()` fn to use `git status` instead
of `git update-index` and `git diff-index`. The `_CheckClean()` fn is
run during every update and this change reduces the subprocess calls
made by it by half.

Change-Id: Ie9a23b0bce748bec4cac88df09655569e88e4841
Bug: 1501984
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5076224
Reviewed-by: Josip Sokcevic <sokcevic@chromium.org>
Commit-Queue: Josip Sokcevic <sokcevic@chromium.org>
Reviewed-by: Gavin Mak <gavinmak@google.com>
changes/24/5076224/2
Aravind Vasudevan 2 years ago committed by LUCI CQ
parent 29672fbb92
commit 259774c3ac

@ -1422,28 +1422,15 @@ class GitWrapper(SCMWrapper):
'\tIf no git executable is running, then clean up %r and try again.\n'
% (self.relpath, revision, lockfile))
# Make sure the tree is clean; see git-rebase.sh for reference
try:
scm.GIT.Capture(
['update-index', '--ignore-submodules', '--refresh'],
cwd=self.checkout_path)
except subprocess2.CalledProcessError:
raise gclient_utils.Error(
'\n____ %s at %s\n'
'\tYou have unstaged changes.\n'
'\tcd into %s, run git status to see changes,\n'
'\tand commit, stash, or reset.\n' %
(self.relpath, revision, self.relpath))
try:
scm.GIT.Capture([
'diff-index', '--cached', '--name-status', '-r',
'--ignore-submodules', 'HEAD', '--'
# Ensure that the tree is clean.
if scm.GIT.Capture([
'status', '--porcelain', '--untracked-files=no',
'--ignore-submodules'
],
cwd=self.checkout_path)
except subprocess2.CalledProcessError:
cwd=self.checkout_path):
raise gclient_utils.Error(
'\n____ %s at %s\n'
'\tYour index contains uncommitted changes\n'
'\tYou have uncommitted changes.\n'
'\tcd into %s, run git status to see changes,\n'
'\tand commit, stash, or reset.\n' %
(self.relpath, revision, self.relpath))

@ -584,7 +584,7 @@ class ManagedGitWrapperTestCase(BaseGitWrapperTestCase):
scm.update(options, (), [])
self.assertEqual(
e.exception.args[0], '\n____ . at refs/remotes/origin/main\n'
'\tYou have unstaged changes.\n'
'\tYou have uncommitted changes.\n'
'\tcd into ., run git status to see changes,\n'
'\tand commit, stash, or reset.\n')

Loading…
Cancel
Save