mirror of
https://chromium.googlesource.com/chromium/tools/depot_tools.git
synced 2026-01-11 18:51:29 +00:00
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>
This commit is contained in:
36
git_cache.py
36
git_cache.py
@@ -234,8 +234,6 @@ class Mirror(object):
|
|||||||
def RunGit(self, cmd, print_stdout=True, **kwargs):
|
def RunGit(self, cmd, print_stdout=True, **kwargs):
|
||||||
"""Run git in a subprocess."""
|
"""Run git in a subprocess."""
|
||||||
cwd = kwargs.setdefault('cwd', self.mirror_path)
|
cwd = kwargs.setdefault('cwd', self.mirror_path)
|
||||||
if "--git-dir" not in cmd:
|
|
||||||
cmd = ['--git-dir', cwd] + cmd
|
|
||||||
kwargs.setdefault('print_stdout', False)
|
kwargs.setdefault('print_stdout', False)
|
||||||
if print_stdout:
|
if print_stdout:
|
||||||
kwargs.setdefault('filter_fn', self.print)
|
kwargs.setdefault('filter_fn', self.print)
|
||||||
@@ -448,12 +446,11 @@ class Mirror(object):
|
|||||||
# Start with a bare git dir.
|
# Start with a bare git dir.
|
||||||
self.RunGit(['init', '--bare'], cwd=self.mirror_path)
|
self.RunGit(['init', '--bare'], cwd=self.mirror_path)
|
||||||
# Set appropriate symbolic-ref
|
# Set appropriate symbolic-ref
|
||||||
remote_info = exponential_backoff_retry(lambda: subprocess.check_output(
|
remote_info = exponential_backoff_retry(
|
||||||
[
|
lambda: subprocess.check_output(
|
||||||
self.git_exe, '--git-dir', self.mirror_path, 'remote', 'show',
|
[self.git_exe, 'remote', 'show', self.url],
|
||||||
self.url
|
cwd=self.mirror_path).decode('utf-8', 'ignore').strip()
|
||||||
],
|
)
|
||||||
cwd=self.mirror_path).decode('utf-8', 'ignore').strip())
|
|
||||||
default_branch_regexp = re.compile(r'HEAD branch: (.*)$')
|
default_branch_regexp = re.compile(r'HEAD branch: (.*)$')
|
||||||
m = default_branch_regexp.search(remote_info, re.MULTILINE)
|
m = default_branch_regexp.search(remote_info, re.MULTILINE)
|
||||||
if m:
|
if m:
|
||||||
@@ -467,12 +464,13 @@ class Mirror(object):
|
|||||||
len(pack_files))
|
len(pack_files))
|
||||||
|
|
||||||
def _fetch(self,
|
def _fetch(self,
|
||||||
|
rundir,
|
||||||
verbose,
|
verbose,
|
||||||
depth,
|
depth,
|
||||||
no_fetch_tags,
|
no_fetch_tags,
|
||||||
reset_fetch_config,
|
reset_fetch_config,
|
||||||
prune=True):
|
prune=True):
|
||||||
self.config(self.mirror_path, reset_fetch_config)
|
self.config(rundir, reset_fetch_config)
|
||||||
|
|
||||||
fetch_cmd = ['fetch']
|
fetch_cmd = ['fetch']
|
||||||
if verbose:
|
if verbose:
|
||||||
@@ -485,18 +483,14 @@ class Mirror(object):
|
|||||||
fetch_cmd.append('--prune')
|
fetch_cmd.append('--prune')
|
||||||
fetch_cmd.append('origin')
|
fetch_cmd.append('origin')
|
||||||
|
|
||||||
fetch_specs = subprocess.check_output([
|
fetch_specs = subprocess.check_output(
|
||||||
self.git_exe, '--git-dir', self.mirror_path, 'config', '--get-all',
|
[self.git_exe, 'config', '--get-all', 'remote.origin.fetch'],
|
||||||
'remote.origin.fetch'
|
cwd=rundir).decode('utf-8', 'ignore').strip().splitlines()
|
||||||
],
|
|
||||||
cwd=self.mirror_path).decode(
|
|
||||||
'utf-8',
|
|
||||||
'ignore').strip().splitlines()
|
|
||||||
for spec in fetch_specs:
|
for spec in fetch_specs:
|
||||||
try:
|
try:
|
||||||
self.print('Fetching %s' % spec)
|
self.print('Fetching %s' % spec)
|
||||||
with self.print_duration_of('fetch %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:
|
except subprocess.CalledProcessError:
|
||||||
if spec == '+refs/heads/*:refs/heads/*':
|
if spec == '+refs/heads/*:refs/heads/*':
|
||||||
raise ClobberNeeded() # Corrupted cache.
|
raise ClobberNeeded() # Corrupted cache.
|
||||||
@@ -505,7 +499,7 @@ class Mirror(object):
|
|||||||
self.print('Fetching %s' % commit)
|
self.print('Fetching %s' % commit)
|
||||||
try:
|
try:
|
||||||
with self.print_duration_of('fetch %s' % commit):
|
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:
|
except subprocess.CalledProcessError:
|
||||||
logging.warning('Fetch of %s failed' % commit)
|
logging.warning('Fetch of %s failed' % commit)
|
||||||
|
|
||||||
@@ -525,7 +519,8 @@ class Mirror(object):
|
|||||||
with lockfile.lock(self.mirror_path, lock_timeout):
|
with lockfile.lock(self.mirror_path, lock_timeout):
|
||||||
try:
|
try:
|
||||||
self._ensure_bootstrapped(depth, bootstrap, reset_fetch_config)
|
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:
|
except ClobberNeeded:
|
||||||
# This is a major failure, we need to clean and force a bootstrap.
|
# This is a major failure, we need to clean and force a bootstrap.
|
||||||
gclient_utils.rmtree(self.mirror_path)
|
gclient_utils.rmtree(self.mirror_path)
|
||||||
@@ -534,7 +529,8 @@ class Mirror(object):
|
|||||||
bootstrap,
|
bootstrap,
|
||||||
reset_fetch_config,
|
reset_fetch_config,
|
||||||
force=True)
|
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):
|
def update_bootstrap(self, prune=False, gc_aggressive=False):
|
||||||
# NOTE: There have been cases where repos were being recursively uploaded
|
# 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.
|
# Add a bad refspec to the cache's fetch config.
|
||||||
cache_dir = os.path.join(
|
cache_dir = os.path.join(
|
||||||
self.cache_dir, mirror.UrlToCacheDir(self.origin_dir))
|
self.cache_dir, mirror.UrlToCacheDir(self.origin_dir))
|
||||||
self.git([
|
self.git(['config', '--add', 'remote.origin.fetch',
|
||||||
'--git-dir', cache_dir, 'config', '--add', 'remote.origin.fetch',
|
'+refs/heads/foo:refs/heads/foo'],
|
||||||
'+refs/heads/foo:refs/heads/foo'
|
|
||||||
],
|
|
||||||
cwd=cache_dir)
|
cwd=cache_dir)
|
||||||
|
|
||||||
mirror.populate(reset_fetch_config=True)
|
mirror.populate(reset_fetch_config=True)
|
||||||
|
|||||||
Reference in New Issue
Block a user