From 2d92ab32fd624349d308334befbf07adf9f179b9 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Tue, 19 Nov 2019 03:05:43 -0500 Subject: rev-parse: make --show-toplevel without a worktree an error Ever since it was introduced in 7cceca5ccc (Add 'git rev-parse --show-toplevel' option., 2010-01-12), the --show-toplevel option has treated a missing working tree as a quiet success: it neither prints a toplevel path, but nor does it report any kind of error. While a caller could distinguish this case by looking for an empty response, the behavior is rather confusing. We're better off complaining that there is no working tree, as other internal commands would do in similar cases (e.g., "git status" or any builtin with NEED_WORK_TREE set would just die()). So let's do the same here. While we're at it, let's clarify the documentation and add some tests, both for the new behavior and for the more mundane case (which was not covered). Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- builtin/rev-parse.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'builtin') diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c index 85ce2095bf..7a00da8203 100644 --- a/builtin/rev-parse.c +++ b/builtin/rev-parse.c @@ -803,6 +803,8 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix) const char *work_tree = get_git_work_tree(); if (work_tree) puts(work_tree); + else + die("this operation must be run in a work tree"); continue; } if (!strcmp(arg, "--show-superproject-working-tree")) { -- cgit v1.2.3