Revert "Set --git-dir for git commands that may be executed in bare gits."

This reverts commit d9011c559b.

Reason for revert: Breaks ChromeOS staging builders: b/296139378

Original change's description:
> Set --git-dir for git commands that may be executed in bare gits.
>
> Bug:b/294415576
> Change-Id: I18ca8ebebf95e1c31e30aa1f5d62da3467df940f
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/4778199
> Auto-Submit: Joanna Wang <jojwang@chromium.org>
> Reviewed-by: Gavin Mak <gavinmak@google.com>
> Commit-Queue: Joanna Wang <jojwang@chromium.org>

Bug: b/294415576
Change-Id: Ie16f16a405fbdea4d925e03a0cfd1ac0260bb2d8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/4784102
Commit-Queue: Jack Neus <jackneus@google.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Reviewed-by: Joanna Wang <jojwang@chromium.org>
changes/02/4784102/2
Jack Neus 2 years ago committed by LUCI CQ
parent 7d26320c4d
commit 1c4052d88a

@ -234,8 +234,6 @@ class Mirror(object):
def RunGit(self, cmd, print_stdout=True, **kwargs):
"""Run git in a subprocess."""
cwd = kwargs.setdefault('cwd', self.mirror_path)
if "--git-dir" not in cmd:
cmd = ['--git-dir', cwd] + cmd
kwargs.setdefault('print_stdout', False)
if print_stdout:
kwargs.setdefault('filter_fn', self.print)
@ -448,12 +446,11 @@ class Mirror(object):
# Start with a bare git dir.
self.RunGit(['init', '--bare'], cwd=self.mirror_path)
# Set appropriate symbolic-ref
remote_info = exponential_backoff_retry(lambda: subprocess.check_output(
[
self.git_exe, '--git-dir', self.mirror_path, 'remote', 'show',
self.url
],
cwd=self.mirror_path).decode('utf-8', 'ignore').strip())
remote_info = exponential_backoff_retry(
lambda: subprocess.check_output(
[self.git_exe, 'remote', 'show', self.url],
cwd=self.mirror_path).decode('utf-8', 'ignore').strip()
)
default_branch_regexp = re.compile(r'HEAD branch: (.*)$')
m = default_branch_regexp.search(remote_info, re.MULTILINE)
if m:
@ -467,12 +464,13 @@ class Mirror(object):
len(pack_files))
def _fetch(self,
rundir,
verbose,
depth,
no_fetch_tags,
reset_fetch_config,
prune=True):
self.config(self.mirror_path, reset_fetch_config)
self.config(rundir, reset_fetch_config)
fetch_cmd = ['fetch']
if verbose:
@ -485,18 +483,14 @@ class Mirror(object):
fetch_cmd.append('--prune')
fetch_cmd.append('origin')
fetch_specs = subprocess.check_output([
self.git_exe, '--git-dir', self.mirror_path, 'config', '--get-all',
'remote.origin.fetch'
],
cwd=self.mirror_path).decode(
'utf-8',
'ignore').strip().splitlines()
fetch_specs = subprocess.check_output(
[self.git_exe, 'config', '--get-all', 'remote.origin.fetch'],
cwd=rundir).decode('utf-8', 'ignore').strip().splitlines()
for spec in fetch_specs:
try:
self.print('Fetching %s' % spec)
with self.print_duration_of('fetch %s' % spec):
self.RunGit(fetch_cmd + [spec], retry=True)
self.RunGit(fetch_cmd + [spec], cwd=rundir, retry=True)
except subprocess.CalledProcessError:
if spec == '+refs/heads/*:refs/heads/*':
raise ClobberNeeded() # Corrupted cache.
@ -505,7 +499,7 @@ class Mirror(object):
self.print('Fetching %s' % commit)
try:
with self.print_duration_of('fetch %s' % commit):
self.RunGit(['fetch', 'origin', commit], retry=True)
self.RunGit(['fetch', 'origin', commit], cwd=rundir, retry=True)
except subprocess.CalledProcessError:
logging.warning('Fetch of %s failed' % commit)
@ -525,7 +519,8 @@ class Mirror(object):
with lockfile.lock(self.mirror_path, lock_timeout):
try:
self._ensure_bootstrapped(depth, bootstrap, reset_fetch_config)
self._fetch(verbose, depth, no_fetch_tags, reset_fetch_config)
self._fetch(self.mirror_path, verbose, depth, no_fetch_tags,
reset_fetch_config)
except ClobberNeeded:
# This is a major failure, we need to clean and force a bootstrap.
gclient_utils.rmtree(self.mirror_path)
@ -534,7 +529,8 @@ class Mirror(object):
bootstrap,
reset_fetch_config,
force=True)
self._fetch(verbose, depth, no_fetch_tags, reset_fetch_config)
self._fetch(self.mirror_path, verbose, depth, no_fetch_tags,
reset_fetch_config)
def update_bootstrap(self, prune=False, gc_aggressive=False):
# NOTE: There have been cases where repos were being recursively uploaded

@ -92,10 +92,8 @@ class GitCacheTest(unittest.TestCase):
# Add a bad refspec to the cache's fetch config.
cache_dir = os.path.join(
self.cache_dir, mirror.UrlToCacheDir(self.origin_dir))
self.git([
'--git-dir', cache_dir, 'config', '--add', 'remote.origin.fetch',
'+refs/heads/foo:refs/heads/foo'
],
self.git(['config', '--add', 'remote.origin.fetch',
'+refs/heads/foo:refs/heads/foo'],
cwd=cache_dir)
mirror.populate(reset_fetch_config=True)

Loading…
Cancel
Save