Merge "Provide usage help even if not in Git directory"

This commit is contained in:
Jenkins 2013-05-31 03:24:15 +00:00 committed by Gerrit Code Review
commit 7b475f1aae
3 changed files with 20 additions and 14 deletions

View File

@ -6,3 +6,4 @@ Roan Kattouw <roan.kattouw@gmail.com>
Antoine Musso <hashar@free.fr>
Yuriy Taraday <yorik.sar@gmail.com>
Pavel Sedlák <psedlak@redhat.com>
Ori Livneh <ori@wikimedia.org>

View File

@ -142,4 +142,4 @@ Use ``git review`` to submit patches (after creating a gerrit account that links
# Do your commits
git review
# Enter your username if promped
# Enter your username if prompted

View File

@ -401,7 +401,7 @@ def check_color_support():
return _has_color
def get_config(config_file):
def get_config(config_file=None):
"""Generate the configuration map by starting with some built-in defaults
and then loading GLOBAL_CONFIG, USER_CONFIG, and a repository-specific
.gitreview file, if they exist. In case of conflict, the configuration file
@ -409,7 +409,7 @@ def get_config(config_file):
"""
config = DEFAULTS.copy()
for filename in (GLOBAL_CONFIG, USER_CONFIG, config_file):
if os.path.exists(filename):
if filename is not None and os.path.exists(filename):
config.update(load_config_file(filename))
return config
@ -959,15 +959,6 @@ to ensure proper behavior with gerrit. Thanks!
def main():
(top_dir, git_dir) = git_directories()
config = get_config(os.path.join(top_dir, ".gitreview"))
hook_file = os.path.join(git_dir, "hooks", "commit-msg")
defaultrebase = convert_bool(
git_config_get_value("gitreview", "rebase",
default=str(config['defaultrebase'])))
usage = "git review [OPTIONS] ... [BRANCH]"
import argparse
@ -1064,7 +1055,20 @@ def main():
parser.add_argument("--version", action="version",
version='%s version %s' %
(os.path.split(sys.argv[0])[-1], version))
parser.add_argument("branch", nargs="?", default=config['defaultbranch'])
parser.add_argument("branch", nargs="?")
try:
(top_dir, git_dir) = git_directories()
except GitDirectoriesException:
if sys.argv[1:] in ([], ['-h'], ['--help']):
parser.print_help()
sys.exit(1)
raise
config = get_config(os.path.join(top_dir, ".gitreview"))
defaultrebase = convert_bool(
git_config_get_value("gitreview", "rebase",
default=str(config['defaultrebase'])))
parser.set_defaults(dry=False,
draft=False,
rebase=defaultrebase,
@ -1073,8 +1077,8 @@ def main():
setup=False,
list=False,
yes=False,
branch=config['defaultbranch'],
remote=config['defaultremote'])
options = parser.parse_args()
if options.license:
@ -1117,6 +1121,7 @@ def main():
if options.custom_script:
run_custom_script("pre")
hook_file = os.path.join(git_dir, "hooks", "commit-msg")
have_hook = os.path.exists(hook_file) and os.access(hook_file, os.X_OK)
if not have_hook: