Skip to content

Commit cd97ae3

Browse files
committed
Merge branch 'jk/fail-show-toplevel-outside-working-tree' into next
"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
2 parents 0418db6 + 2d92ab3 commit cd97ae3

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

Documentation/git-rev-parse.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,8 @@ print a message to stderr and exit with nonzero status.
262262
directory.
263263

264264
--show-toplevel::
265-
Show the absolute path of the top-level directory.
265+
Show the absolute path of the top-level directory of the working
266+
tree. If there is no working tree, report an error.
266267

267268
--show-superproject-working-tree::
268269
Show the absolute path of the root of the superproject's

builtin/rev-parse.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -803,6 +803,8 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
803803
const char *work_tree = get_git_work_tree();
804804
if (work_tree)
805805
puts(work_tree);
806+
else
807+
die("this operation must be run in a work tree");
806808
continue;
807809
}
808810
if (!strcmp(arg, "--show-superproject-working-tree")) {

t/t1500-rev-parse.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,16 @@ test_expect_success 'rev-parse --show-object-format in repo' '
146146
grep "unknown mode for --show-object-format: squeamish-ossifrage" err
147147
'
148148

149+
test_expect_success '--show-toplevel from subdir of working tree' '
150+
pwd >expect &&
151+
git -C sub/dir rev-parse --show-toplevel >actual &&
152+
test_cmp expect actual
153+
'
154+
155+
test_expect_success '--show-toplevel from inside .git' '
156+
test_must_fail git -C .git rev-parse --show-toplevel
157+
'
158+
149159
test_expect_success 'showing the superproject correctly' '
150160
git rev-parse --show-superproject-working-tree >out &&
151161
test_must_be_empty out &&

0 commit comments

Comments
 (0)