Skip to content

Commit 758d077

Browse files
committed
Merge branch 'es/outside-repo-errmsg-hints' into maint
An earlier update to show the location of working tree in the error message did not consider the possibility that a git command may be run in a bare repository, which has been corrected. * es/outside-repo-errmsg-hints: prefix_path: show gitdir if worktree unavailable prefix_path: show gitdir when arg is outside repo
2 parents f0c344c + 5c20398 commit 758d077

File tree

3 files changed

+52
-4
lines changed

3 files changed

+52
-4
lines changed

pathspec.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -438,8 +438,13 @@ static void init_pathspec_item(struct pathspec_item *item, unsigned flags,
438438
} else {
439439
match = prefix_path_gently(prefix, prefixlen,
440440
&prefixlen, copyfrom);
441-
if (!match)
442-
die(_("%s: '%s' is outside repository"), elt, copyfrom);
441+
if (!match) {
442+
const char *hint_path = get_git_work_tree();
443+
if (!hint_path)
444+
hint_path = get_git_dir();
445+
die(_("%s: '%s' is outside repository at '%s'"), elt,
446+
copyfrom, absolute_path(hint_path));
447+
}
443448
}
444449

445450
item->match = match;

setup.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,13 @@ char *prefix_path_gently(const char *prefix, int len,
120120
char *prefix_path(const char *prefix, int len, const char *path)
121121
{
122122
char *r = prefix_path_gently(prefix, len, NULL, path);
123-
if (!r)
124-
die(_("'%s' is outside repository"), path);
123+
if (!r) {
124+
const char *hint_path = get_git_work_tree();
125+
if (!hint_path)
126+
hint_path = get_git_dir();
127+
die(_("'%s' is outside repository at '%s'"), path,
128+
absolute_path(hint_path));
129+
}
125130
return r;
126131
}
127132

t/t6136-pathspec-in-bare.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/sh
2+
3+
test_description='diagnosing out-of-scope pathspec'
4+
5+
. ./test-lib.sh
6+
7+
test_expect_success 'setup a bare and non-bare repository' '
8+
test_commit file1 &&
9+
git clone --bare . bare
10+
'
11+
12+
test_expect_success 'log and ls-files in a bare repository' '
13+
(
14+
cd bare &&
15+
test_must_fail git log -- .. >out 2>err &&
16+
test_must_be_empty out &&
17+
test_i18ngrep "outside repository" err &&
18+
19+
test_must_fail git ls-files -- .. >out 2>err &&
20+
test_must_be_empty out &&
21+
test_i18ngrep "outside repository" err
22+
)
23+
'
24+
25+
test_expect_success 'log and ls-files in .git directory' '
26+
(
27+
cd .git &&
28+
test_must_fail git log -- .. >out 2>err &&
29+
test_must_be_empty out &&
30+
test_i18ngrep "outside repository" err &&
31+
32+
test_must_fail git ls-files -- .. >out 2>err &&
33+
test_must_be_empty out &&
34+
test_i18ngrep "outside repository" err
35+
)
36+
'
37+
38+
test_done

0 commit comments

Comments
 (0)