summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar Junio C Hamano <gitster@pobox.com>2019-12-05 12:52:45 -0800
committerLibravatar Junio C Hamano <gitster@pobox.com>2019-12-05 12:52:45 -0800
commit36fd304d819d412adf1ed81d6a983dabb28bfc9b (patch)
tree7fc4343de532b086f9c3af1e04811d43ed3d6581
parentMerge branch 'sg/unpack-progress-throughput' (diff)
parentrev-parse: make --show-toplevel without a worktree an error (diff)
downloadtgif-36fd304d819d412adf1ed81d6a983dabb28bfc9b.tar.xz
Merge branch 'jk/fail-show-toplevel-outside-working-tree'
"git rev-parse --show-toplevel" run outside of any working tree did not error out, which has been corrected. * jk/fail-show-toplevel-outside-working-tree: rev-parse: make --show-toplevel without a worktree an error
-rw-r--r--Documentation/git-rev-parse.txt3
-rw-r--r--builtin/rev-parse.c2
-rwxr-xr-xt/t1500-rev-parse.sh10
3 files changed, 14 insertions, 1 deletions
diff --git a/Documentation/git-rev-parse.txt b/Documentation/git-rev-parse.txt
index 9985477efe..19b12b6d43 100644
--- a/Documentation/git-rev-parse.txt
+++ b/Documentation/git-rev-parse.txt
@@ -262,7 +262,8 @@ print a message to stderr and exit with nonzero status.
directory.
--show-toplevel::
- Show the absolute path of the top-level directory.
+ Show the absolute path of the top-level directory of the working
+ tree. If there is no working tree, report an error.
--show-superproject-working-tree::
Show the absolute path of the root of the superproject's
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")) {
diff --git a/t/t1500-rev-parse.sh b/t/t1500-rev-parse.sh
index 0177fd815c..603019b541 100755
--- a/t/t1500-rev-parse.sh
+++ b/t/t1500-rev-parse.sh
@@ -146,6 +146,16 @@ test_expect_success 'rev-parse --show-object-format in repo' '
grep "unknown mode for --show-object-format: squeamish-ossifrage" err
'
+test_expect_success '--show-toplevel from subdir of working tree' '
+ pwd >expect &&
+ git -C sub/dir rev-parse --show-toplevel >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success '--show-toplevel from inside .git' '
+ test_must_fail git -C .git rev-parse --show-toplevel
+'
+
test_expect_success 'showing the superproject correctly' '
git rev-parse --show-superproject-working-tree >out &&
test_must_be_empty out &&