Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(92)

Unified Diff: git_cache.py

Issue 440213005: Add 'git cache fetch' subcommand. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: git_cache.py
diff --git a/git_cache.py b/git_cache.py
index 59bd48cbc0c22a03552e510c77df2fed00ae7195..1fa7e4556871a82e9de7090146ccf7035523a140 100755
--- a/git_cache.py
+++ b/git_cache.py
@@ -564,6 +564,54 @@ def CMDpopulate(parser, args):
mirror.populate(**kwargs)
+@subcommand.usage('Fetch new commits into cache and current checkout')
+def CMDfetch(parser, args):
+ """Update mirror, and fetch in cwd."""
+ parser.add_option('--all', action='store_true', help='Fetch all remotes')
+ options, args = parser.parse_args(args)
+
+ # Figure out which remotes to fetch. This mimics the behavior of regular
+ # 'git fetch'. Note that in the case of "stacked" or "pipelined" branches,
+ # this will NOT try to traverse up the branching structure to find the
+ # ultimate remote to update.
+ remotes = []
+ if options.all:
+ assert not args, 'fatal: fetch --all does not take a repository argument'
+ remotes = subprocess.check_output([Mirror.git_exe, 'remote']).splitlines()
+ elif args:
+ remotes = args
+ else:
+ current_branch = subprocess.check_output(
+ [Mirror.git_exe, 'rev-parse', '--abbrev-ref', 'HEAD']).strip()
+ if current_branch != 'HEAD':
+ upstream = subprocess.check_output(
+ [Mirror.git_exe, 'config', 'branch.%s.remote' % current_branch]
+ ).strip()
+ if upstream and upstream != '.':
+ remotes = [upstream]
+ if not remotes:
+ remotes = ['origin']
+
+ cachepath = Mirror.GetCachePath()
+ git_dir = os.path.abspath(subprocess.check_output(
+ [Mirror.git_exe, 'rev-parse', '--git-dir']))
+ git_dir = os.path.abspath(git_dir)
+ if git_dir.startswith(cachepath):
+ mirror = Mirror.FromPath(git_dir)
+ mirror.populate()
+ return 0
+ for remote in remotes:
+ remote_url = subprocess.check_output(
+ [Mirror.git_exe, 'config', 'remote.%s.url' % remote]).strip()
+ if remote_url.startswith(cachepath):
+ mirror = Mirror.FromPath(remote_url)
+ mirror.print = lambda *args: None
+ print('Updating git cache...')
+ mirror.populate()
+ subprocess.check_call([Mirror.git_exe, 'fetch', remote])
+ return 0
+
+
@subcommand.usage('[url of repo to unlock, or -a|--all]')
def CMDunlock(parser, args):
"""Unlock one or all repos if their lock files are still around."""
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698