diff options
Diffstat (limited to 'repo')
-rwxr-xr-x | repo | 43 |
1 files changed, 43 insertions, 0 deletions
@@ -13,6 +13,7 @@ from __future__ import print_function | |||
13 | import datetime | 13 | import datetime |
14 | import os | 14 | import os |
15 | import platform | 15 | import platform |
16 | import shlex | ||
16 | import subprocess | 17 | import subprocess |
17 | import sys | 18 | import sys |
18 | 19 | ||
@@ -693,6 +694,24 @@ def _SetConfig(cwd, name, value): | |||
693 | run_git('config', name, value, cwd=cwd) | 694 | run_git('config', name, value, cwd=cwd) |
694 | 695 | ||
695 | 696 | ||
697 | def _GetRepoConfig(name): | ||
698 | """Read a repo configuration option.""" | ||
699 | config = os.path.join(home_dot_repo, 'config') | ||
700 | if not os.path.exists(config): | ||
701 | return None | ||
702 | |||
703 | cmd = ['config', '--file', config, '--get', name] | ||
704 | ret = run_git(*cmd, check=False) | ||
705 | if ret.returncode == 0: | ||
706 | return ret.stdout | ||
707 | elif ret.returncode == 1: | ||
708 | return None | ||
709 | else: | ||
710 | print('repo: error: git %s failed:\n%s' % (' '.join(cmd), ret.stderr), | ||
711 | file=sys.stderr) | ||
712 | raise RunError() | ||
713 | |||
714 | |||
696 | def _InitHttp(): | 715 | def _InitHttp(): |
697 | handlers = [] | 716 | handlers = [] |
698 | 717 | ||
@@ -876,6 +895,25 @@ class _Options(object): | |||
876 | version = False | 895 | version = False |
877 | 896 | ||
878 | 897 | ||
898 | def _ExpandAlias(name): | ||
899 | """Look up user registered aliases.""" | ||
900 | # We don't resolve aliases for existing subcommands. This matches git. | ||
901 | if name in {'gitc-init', 'help', 'init'}: | ||
902 | return name, [] | ||
903 | |||
904 | alias = _GetRepoConfig('alias.%s' % (name,)) | ||
905 | if alias is None: | ||
906 | return name, [] | ||
907 | |||
908 | args = alias.strip().split(' ', 1) | ||
909 | name = args[0] | ||
910 | if len(args) == 2: | ||
911 | args = shlex.split(args[1]) | ||
912 | else: | ||
913 | args = [] | ||
914 | return name, args | ||
915 | |||
916 | |||
879 | def _ParseArguments(args): | 917 | def _ParseArguments(args): |
880 | cmd = None | 918 | cmd = None |
881 | opt = _Options() | 919 | opt = _Options() |
@@ -1004,6 +1042,11 @@ def main(orig_args): | |||
1004 | file=sys.stderr) | 1042 | file=sys.stderr) |
1005 | sys.exit(1) | 1043 | sys.exit(1) |
1006 | if not repo_main: | 1044 | if not repo_main: |
1045 | # Only expand aliases here since we'll be parsing the CLI ourselves. | ||
1046 | # If we had repo_main, alias expansion would happen in main.py. | ||
1047 | cmd, alias_args = _ExpandAlias(cmd) | ||
1048 | args = alias_args + args | ||
1049 | |||
1007 | if opt.help: | 1050 | if opt.help: |
1008 | _Usage() | 1051 | _Usage() |
1009 | if cmd == 'help': | 1052 | if cmd == 'help': |