summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar Junio C Hamano <gitster@pobox.com>2018-02-27 10:33:50 -0800
committerLibravatar Junio C Hamano <gitster@pobox.com>2018-02-27 10:33:51 -0800
commitee9db32d42a4b628157ecd395305d83cc630f7aa (patch)
tree334d4b6b702fad567a9ef82b65df2995f7c1b661
parentMerge branch 'ab/untracked-cache-invalidation-docs' (diff)
parentblame: tighten command line parser (diff)
downloadtgif-ee9db32d42a4b628157ecd395305d83cc630f7aa.tar.xz
Merge branch 'jc/blame-missing-path'
"git blame HEAD COPYING" in a bare repository failed to run, while "git blame HEAD -- COPYING" run just fine. This has been corrected. * jc/blame-missing-path: blame: tighten command line parser
-rw-r--r--builtin/blame.c20
1 files changed, 14 insertions, 6 deletions
diff --git a/builtin/blame.c b/builtin/blame.c
index 005f55aaa2..9dcb367b90 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -649,6 +649,15 @@ static int blame_move_callback(const struct option *option, const char *arg, int
return 0;
}
+static int is_a_rev(const char *name)
+{
+ struct object_id oid;
+
+ if (get_oid(name, &oid))
+ return 0;
+ return OBJ_NONE < sha1_object_info(oid.hash, NULL);
+}
+
int cmd_blame(int argc, const char **argv, const char *prefix)
{
struct rev_info revs;
@@ -845,16 +854,15 @@ parse_done:
} else {
if (argc < 2)
usage_with_options(blame_opt_usage, options);
- path = add_prefix(prefix, argv[argc - 1]);
- if (argc == 3 && !file_exists(path)) { /* (2b) */
+ if (argc == 3 && is_a_rev(argv[argc - 1])) { /* (2b) */
path = add_prefix(prefix, argv[1]);
argv[1] = argv[2];
+ } else { /* (2a) */
+ if (argc == 2 && is_a_rev(argv[1]) && !get_git_work_tree())
+ die("missing <path> to blame");
+ path = add_prefix(prefix, argv[argc - 1]);
}
argv[argc - 1] = "--";
-
- setup_work_tree();
- if (!file_exists(path))
- die_errno("cannot stat path '%s'", path);
}
revs.disable_stdin = 1;