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
This commit is contained in:
commit
758d0773ba
@ -438,8 +438,13 @@ static void init_pathspec_item(struct pathspec_item *item, unsigned flags,
|
||||
} else {
|
||||
match = prefix_path_gently(prefix, prefixlen,
|
||||
&prefixlen, copyfrom);
|
||||
if (!match)
|
||||
die(_("%s: '%s' is outside repository"), elt, copyfrom);
|
||||
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(hint_path));
|
||||
}
|
||||
}
|
||||
|
||||
item->match = match;
|
||||
|
9
setup.c
9
setup.c
@ -120,8 +120,13 @@ char *prefix_path_gently(const char *prefix, int len,
|
||||
char *prefix_path(const char *prefix, int len, const char *path)
|
||||
{
|
||||
char *r = prefix_path_gently(prefix, len, NULL, path);
|
||||
if (!r)
|
||||
die(_("'%s' is outside repository"), path);
|
||||
if (!r) {
|
||||
const char *hint_path = get_git_work_tree();
|
||||
if (!hint_path)
|
||||
hint_path = get_git_dir();
|
||||
die(_("'%s' is outside repository at '%s'"), path,
|
||||
absolute_path(hint_path));
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
|
38
t/t6136-pathspec-in-bare.sh
Executable file
38
t/t6136-pathspec-in-bare.sh
Executable file
@ -0,0 +1,38 @@
|
||||
#!/bin/sh
|
||||
|
||||
test_description='diagnosing out-of-scope pathspec'
|
||||
|
||||
. ./test-lib.sh
|
||||
|
||||
test_expect_success 'setup a bare and non-bare repository' '
|
||||
test_commit file1 &&
|
||||
git clone --bare . bare
|
||||
'
|
||||
|
||||
test_expect_success 'log and ls-files in a bare repository' '
|
||||
(
|
||||
cd bare &&
|
||||
test_must_fail git log -- .. >out 2>err &&
|
||||
test_must_be_empty out &&
|
||||
test_i18ngrep "outside repository" err &&
|
||||
|
||||
test_must_fail git ls-files -- .. >out 2>err &&
|
||||
test_must_be_empty out &&
|
||||
test_i18ngrep "outside repository" err
|
||||
)
|
||||
'
|
||||
|
||||
test_expect_success 'log and ls-files in .git directory' '
|
||||
(
|
||||
cd .git &&
|
||||
test_must_fail git log -- .. >out 2>err &&
|
||||
test_must_be_empty out &&
|
||||
test_i18ngrep "outside repository" err &&
|
||||
|
||||
test_must_fail git ls-files -- .. >out 2>err &&
|
||||
test_must_be_empty out &&
|
||||
test_i18ngrep "outside repository" err
|
||||
)
|
||||
'
|
||||
|
||||
test_done
|
Loading…
Reference in New Issue
Block a user