path: root/pathspec.c
diff options
authorEmily Shaffer <>2020-03-03 04:05:06 (GMT)
committerJunio C Hamano <>2020-03-15 16:35:46 (GMT)
commit5c20398699165a91af2d81ea2d20385bc8dd3627 (patch)
tree7ee6a11bb7465d2c938a39410c958acfb9639a43 /pathspec.c
parente0020b2f82910f50bc697d86aff70c3796fbdc41 (diff)
prefix_path: show gitdir if worktree unavailable
If there is no worktree at present, we can still hint the user about Git's current directory by showing them the absolute path to the Git directory. Even though the Git directory doesn't make it as easy to locate the worktree in question, it can still help a user figure out what's going on while developing a script. This fixes a segmentation fault introduced in e0020b2f ("prefix_path: show gitdir when arg is outside repo", 2020-02-14). Signed-off-by: Emily Shaffer <> [jc: added minimum tests, with help from Szeder Gábor] Signed-off-by: Junio C Hamano <>
Diffstat (limited to 'pathspec.c')
1 files changed, 6 insertions, 2 deletions
diff --git a/pathspec.c b/pathspec.c
index 166d255..8243e06 100644
--- a/pathspec.c
+++ b/pathspec.c
@@ -438,9 +438,13 @@ static void init_pathspec_item(struct pathspec_item *item, unsigned flags,
} else {
match = prefix_path_gently(prefix, prefixlen,
&prefixlen, copyfrom);
- if (!match)
+ if (!match) {
+ const char *hint_path = get_git_work_tree();
+ if (!hint_path)
+ hint_path = get_git_dir();
die(_("%s: '%s' is outside repository at '%s'"), elt,
- copyfrom, absolute_path(get_git_work_tree()));
+ copyfrom, absolute_path(hint_path));
+ }
item->match = match;