OLD | NEW |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2014 The Chromium Authors. All rights reserved. | 2 # Copyright 2014 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """A git command for managing a local cache of git repositories.""" | 6 """A git command for managing a local cache of git repositories.""" |
7 | 7 |
8 from __future__ import print_function | 8 from __future__ import print_function |
9 import errno | 9 import errno |
10 import logging | 10 import logging |
(...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
557 'verbose': options.verbose, | 557 'verbose': options.verbose, |
558 'shallow': options.shallow, | 558 'shallow': options.shallow, |
559 'bootstrap': not options.no_bootstrap, | 559 'bootstrap': not options.no_bootstrap, |
560 'ignore_lock': options.ignore_locks, | 560 'ignore_lock': options.ignore_locks, |
561 } | 561 } |
562 if options.depth: | 562 if options.depth: |
563 kwargs['depth'] = options.depth | 563 kwargs['depth'] = options.depth |
564 mirror.populate(**kwargs) | 564 mirror.populate(**kwargs) |
565 | 565 |
566 | 566 |
567 @subcommand.usage('Fetch new commits into cache and current checkout') | |
568 def CMDfetch(parser, args): | |
569 """Update mirror, and fetch in cwd.""" | |
570 parser.add_option('--all', action='store_true', help='Fetch all remotes') | |
571 options, args = parser.parse_args(args) | |
572 | |
573 # Figure out which remotes to fetch. This mimics the behavior of regular | |
574 # 'git fetch'. | |
575 remotes = [] | |
576 if options.all: | |
577 assert not args, 'fatal: fetch --all does not take a repository argument' | |
578 remotes = subprocess.check_output([Mirror.git_exe, 'remote']).splitlines() | |
579 elif args: | |
580 remotes = args | |
581 else: | |
582 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
| |
583 [Mirror.git_exe, 'rev-parse', '--abbrev-ref', 'HEAD']).strip() | |
584 if current_branch != 'HEAD': | |
585 upstream = subprocess.check_output( | |
586 [Mirror.git_exe, 'config', 'branch.%s.remote' % current_branch] | |
587 ).strip() | |
588 if upstream: | |
iannucci
2014/08/07 18:29:53
local branches will have an upstream of '.'
szager1
2014/08/07 18:32:53
Fixed.
| |
589 remotes = [upstream] | |
590 if not remotes: | |
591 remotes = ['origin'] | |
592 | |
593 cachepath = Mirror.GetCachePath() | |
594 git_dir = os.path.abspath(subprocess.check_output( | |
595 [Mirror.git_exe, 'rev-parse', '--git-dir'])) | |
596 git_dir = os.path.abspath(git_dir) | |
597 if git_dir.startswith(cachepath): | |
598 mirror = Mirror.FromPath(git_dir) | |
599 mirror.populate() | |
600 return 0 | |
601 for remote in remotes: | |
602 remote_url = subprocess.check_output( | |
603 [Mirror.git_exe, 'config', 'remote.%s.url' % remote]).strip() | |
604 if remote_url.startswith(cachepath): | |
605 mirror = Mirror.FromPath(remote_url) | |
606 mirror.print = lambda *args: None | |
607 print('Updating git cache...') | |
608 mirror.populate() | |
609 subprocess.check_call([Mirror.git_exe, 'fetch', remote]) | |
610 return 0 | |
611 | |
612 | |
567 @subcommand.usage('[url of repo to unlock, or -a|--all]') | 613 @subcommand.usage('[url of repo to unlock, or -a|--all]') |
568 def CMDunlock(parser, args): | 614 def CMDunlock(parser, args): |
569 """Unlock one or all repos if their lock files are still around.""" | 615 """Unlock one or all repos if their lock files are still around.""" |
570 parser.add_option('--force', '-f', action='store_true', | 616 parser.add_option('--force', '-f', action='store_true', |
571 help='Actually perform the action') | 617 help='Actually perform the action') |
572 parser.add_option('--all', '-a', action='store_true', | 618 parser.add_option('--all', '-a', action='store_true', |
573 help='Unlock all repository caches') | 619 help='Unlock all repository caches') |
574 options, args = parser.parse_args(args) | 620 options, args = parser.parse_args(args) |
575 if len(args) > 1 or (len(args) == 0 and not options.all): | 621 if len(args) > 1 or (len(args) == 0 and not options.all): |
576 parser.error('git cache unlock takes exactly one repo url, or --all') | 622 parser.error('git cache unlock takes exactly one repo url, or --all') |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
631 return options, args | 677 return options, args |
632 | 678 |
633 | 679 |
634 def main(argv): | 680 def main(argv): |
635 dispatcher = subcommand.CommandDispatcher(__name__) | 681 dispatcher = subcommand.CommandDispatcher(__name__) |
636 return dispatcher.execute(OptionParser(), argv) | 682 return dispatcher.execute(OptionParser(), argv) |
637 | 683 |
638 | 684 |
639 if __name__ == '__main__': | 685 if __name__ == '__main__': |
640 sys.exit(main(sys.argv[1:])) | 686 sys.exit(main(sys.argv[1:])) |
OLD | NEW |