From 279774db59d983de83ab4328e58108a811c68c02 Mon Sep 17 00:00:00 2001 From: Marcin Cieslak Date: Mon, 11 Feb 2013 00:13:18 +0100 Subject: [PATCH] git_config_get_value to return None - use git_config_get_value instead of "git config" - return None when no value is specified - fail with git error code >= 128 if .gitconfig has illegal format or some other serious git problem happens. Change-Id: Icedfb6a281948056f57bf1581ef186b503ba6b94 --- git-review | 32 ++++++++++++++++++++++++-------- git-review.1 | 3 +++ 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/git-review b/git-review index 2876939..29c975d 100755 --- a/git-review +++ b/git-review @@ -217,6 +217,23 @@ def run_custom_script(action): print(output) +def git_config_get_value(section, option, default=None): + try: + return run_command_exc(GitConfigException, + "git", "config", + "--get", + "%s.%s" % (section, option)).strip() + except GitConfigException as exc: + if exc.rc == 1: + return default + raise + + +class GitConfigException(CommandFailed): + """Git config value retrieval failed.""" + EXIT_CODE = 128 + + class CannotInstallHook(CommandFailed): "Problems encountered installing commit-msg hook" EXIT_CODE = 2 @@ -294,7 +311,7 @@ def add_remote(hostname, port, project, remote): username = os.getenv("USERNAME") if not username: - username = run_command('git config --get gitreview.username') + username = git_config_get_value("gitreview", "username") if not username: username = os.getenv("USER") if port is None: @@ -362,11 +379,6 @@ def parse_git_show(remote, verb): return (hostname, username, str(port), project_name) -def git_config_get_value(section, option): - cmd = "git config --get %s.%s" % (section, option) - return run_command(cmd).strip() - - def check_color_support(): global _has_color if _has_color is None: @@ -507,8 +519,12 @@ def get_branch_name(target_branch): def assert_one_change(remote, branch, yes, have_hook): has_color = check_color_support() if has_color: - color = git_config_get_value("color", "ui").lower() - if(color == "" or color == "true"): + color = git_config_get_value("color", "ui") + if color is None: + color = "auto" + else: + color = color.lower() + if (color == "" or color == "true"): color = "auto" elif color == "false": color = "never" diff --git a/git-review.1 b/git-review.1 index 0a1e8b5..a369779 100644 --- a/git-review.1 +++ b/git-review.1 @@ -268,6 +268,9 @@ Exit status larger than 31 indicates problem with communication with Gerrit or remote Git repository, exit status larger than 63 means there was a problem with a local repository or a working copy. + +Exit status larger than or equal to 128 means internal +error in running the "git" command. .Pp .Sh EXAMPLES To fetch a remote change number 3004: