diff --git a/AUTHORS b/AUTHORS index d6518600..e9d54cfe 100644 --- a/AUTHORS +++ b/AUTHORS @@ -6,3 +6,4 @@ Roan Kattouw Antoine Musso Yuriy Taraday Pavel Sedlák +Ori Livneh diff --git a/README.rst b/README.rst index d1381d57..5c7c3833 100644 --- a/README.rst +++ b/README.rst @@ -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 diff --git a/git-review b/git-review index 39abcae0..16f481a2 100755 --- a/git-review +++ b/git-review @@ -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: