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
This commit is contained in:

committed by
Clark Boylan

parent
06a036ac91
commit
279774db59
32
git-review
32
git-review
@@ -217,6 +217,23 @@ def run_custom_script(action):
|
|||||||
print(output)
|
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):
|
class CannotInstallHook(CommandFailed):
|
||||||
"Problems encountered installing commit-msg hook"
|
"Problems encountered installing commit-msg hook"
|
||||||
EXIT_CODE = 2
|
EXIT_CODE = 2
|
||||||
@@ -294,7 +311,7 @@ def add_remote(hostname, port, project, remote):
|
|||||||
|
|
||||||
username = os.getenv("USERNAME")
|
username = os.getenv("USERNAME")
|
||||||
if not username:
|
if not username:
|
||||||
username = run_command('git config --get gitreview.username')
|
username = git_config_get_value("gitreview", "username")
|
||||||
if not username:
|
if not username:
|
||||||
username = os.getenv("USER")
|
username = os.getenv("USER")
|
||||||
if port is None:
|
if port is None:
|
||||||
@@ -362,11 +379,6 @@ def parse_git_show(remote, verb):
|
|||||||
return (hostname, username, str(port), project_name)
|
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():
|
def check_color_support():
|
||||||
global _has_color
|
global _has_color
|
||||||
if _has_color is None:
|
if _has_color is None:
|
||||||
@@ -507,8 +519,12 @@ def get_branch_name(target_branch):
|
|||||||
def assert_one_change(remote, branch, yes, have_hook):
|
def assert_one_change(remote, branch, yes, have_hook):
|
||||||
has_color = check_color_support()
|
has_color = check_color_support()
|
||||||
if has_color:
|
if has_color:
|
||||||
color = git_config_get_value("color", "ui").lower()
|
color = git_config_get_value("color", "ui")
|
||||||
if(color == "" or color == "true"):
|
if color is None:
|
||||||
|
color = "auto"
|
||||||
|
else:
|
||||||
|
color = color.lower()
|
||||||
|
if (color == "" or color == "true"):
|
||||||
color = "auto"
|
color = "auto"
|
||||||
elif color == "false":
|
elif color == "false":
|
||||||
color = "never"
|
color = "never"
|
||||||
|
@@ -268,6 +268,9 @@ Exit status larger than 31 indicates problem with
|
|||||||
communication with Gerrit or remote Git repository,
|
communication with Gerrit or remote Git repository,
|
||||||
exit status larger than 63 means there was a problem with
|
exit status larger than 63 means there was a problem with
|
||||||
a local repository or a working copy.
|
a local repository or a working copy.
|
||||||
|
|
||||||
|
Exit status larger than or equal to 128 means internal
|
||||||
|
error in running the "git" command.
|
||||||
.Pp
|
.Pp
|
||||||
.Sh EXAMPLES
|
.Sh EXAMPLES
|
||||||
To fetch a remote change number 3004:
|
To fetch a remote change number 3004:
|
||||||
|
Reference in New Issue
Block a user