Chromium Code Reviews| Index: git_cache.py |
| diff --git a/git_cache.py b/git_cache.py |
| index 59bd48cbc0c22a03552e510c77df2fed00ae7195..4708f13286fcd8b72f835e33277282fe5e2c581e 100755 |
| --- a/git_cache.py |
| +++ b/git_cache.py |
| @@ -564,6 +564,52 @@ 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'. |
| + 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( |
|
iannucci
2014/08/07 18:29:53
won't this need to go up all the way to the rootmo
szager1
2014/08/07 18:32:53
git doesn't behave that way; it only looks at the
szager1
2014/08/07 18:38:48
Also, I think the degenerate base case will work f
|
| + [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: |
|
iannucci
2014/08/07 18:29:53
local branches will have an upstream of '.'
szager1
2014/08/07 18:32:53
Fixed.
|
| + 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.""" |