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'. Note that in the case of "stacked" or "pipelined" branches, |
| 575 # this will NOT try to traverse up the branching structure to find the |
| 576 # ultimate remote to update. |
| 577 remotes = [] |
| 578 if options.all: |
| 579 assert not args, 'fatal: fetch --all does not take a repository argument' |
| 580 remotes = subprocess.check_output([Mirror.git_exe, 'remote']).splitlines() |
| 581 elif args: |
| 582 remotes = args |
| 583 else: |
| 584 current_branch = subprocess.check_output( |
| 585 [Mirror.git_exe, 'rev-parse', '--abbrev-ref', 'HEAD']).strip() |
| 586 if current_branch != 'HEAD': |
| 587 upstream = subprocess.check_output( |
| 588 [Mirror.git_exe, 'config', 'branch.%s.remote' % current_branch] |
| 589 ).strip() |
| 590 if upstream and upstream != '.': |
| 591 remotes = [upstream] |
| 592 if not remotes: |
| 593 remotes = ['origin'] |
| 594 |
| 595 cachepath = Mirror.GetCachePath() |
| 596 git_dir = os.path.abspath(subprocess.check_output( |
| 597 [Mirror.git_exe, 'rev-parse', '--git-dir'])) |
| 598 git_dir = os.path.abspath(git_dir) |
| 599 if git_dir.startswith(cachepath): |
| 600 mirror = Mirror.FromPath(git_dir) |
| 601 mirror.populate() |
| 602 return 0 |
| 603 for remote in remotes: |
| 604 remote_url = subprocess.check_output( |
| 605 [Mirror.git_exe, 'config', 'remote.%s.url' % remote]).strip() |
| 606 if remote_url.startswith(cachepath): |
| 607 mirror = Mirror.FromPath(remote_url) |
| 608 mirror.print = lambda *args: None |
| 609 print('Updating git cache...') |
| 610 mirror.populate() |
| 611 subprocess.check_call([Mirror.git_exe, 'fetch', remote]) |
| 612 return 0 |
| 613 |
| 614 |
567 @subcommand.usage('[url of repo to unlock, or -a|--all]') | 615 @subcommand.usage('[url of repo to unlock, or -a|--all]') |
568 def CMDunlock(parser, args): | 616 def CMDunlock(parser, args): |
569 """Unlock one or all repos if their lock files are still around.""" | 617 """Unlock one or all repos if their lock files are still around.""" |
570 parser.add_option('--force', '-f', action='store_true', | 618 parser.add_option('--force', '-f', action='store_true', |
571 help='Actually perform the action') | 619 help='Actually perform the action') |
572 parser.add_option('--all', '-a', action='store_true', | 620 parser.add_option('--all', '-a', action='store_true', |
573 help='Unlock all repository caches') | 621 help='Unlock all repository caches') |
574 options, args = parser.parse_args(args) | 622 options, args = parser.parse_args(args) |
575 if len(args) > 1 or (len(args) == 0 and not options.all): | 623 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') | 624 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 | 679 return options, args |
632 | 680 |
633 | 681 |
634 def main(argv): | 682 def main(argv): |
635 dispatcher = subcommand.CommandDispatcher(__name__) | 683 dispatcher = subcommand.CommandDispatcher(__name__) |
636 return dispatcher.execute(OptionParser(), argv) | 684 return dispatcher.execute(OptionParser(), argv) |
637 | 685 |
638 | 686 |
639 if __name__ == '__main__': | 687 if __name__ == '__main__': |
640 sys.exit(main(sys.argv[1:])) | 688 sys.exit(main(sys.argv[1:])) |
OLD | NEW |