Skip to content

Commit a3402c1

Browse files
committed
Merge branch 'mg/sha1-path-advise' into maint
* mg/sha1-path-advise: sha1_name: Suggest commit:./file for path in subdir t1506: factor out test for "Did you mean..."
2 parents d022443 + e41d718 commit a3402c1

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

sha1_name.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,11 +1012,13 @@ static void diagnose_invalid_sha1_path(const char *prefix,
10121012
if (!get_tree_entry(tree_sha1, fullname,
10131013
sha1, &mode)) {
10141014
die("Path '%s' exists, but not '%s'.\n"
1015-
"Did you mean '%s:%s'?",
1015+
"Did you mean '%s:%s' aka '%s:./%s'?",
10161016
fullname,
10171017
filename,
10181018
object_name,
1019-
fullname);
1019+
fullname,
1020+
object_name,
1021+
filename);
10201022
}
10211023
die("Path '%s' does not exist in '%s'",
10221024
filename, object_name);
@@ -1065,9 +1067,10 @@ static void diagnose_invalid_index_path(int stage,
10651067
if (ce_namelen(ce) == fullnamelen &&
10661068
!memcmp(ce->name, fullname, fullnamelen))
10671069
die("Path '%s' is in the index, but not '%s'.\n"
1068-
"Did you mean ':%d:%s'?",
1070+
"Did you mean ':%d:%s' aka ':%d:./%s'?",
10691071
fullname, filename,
1070-
ce_stage(ce), fullname);
1072+
ce_stage(ce), fullname,
1073+
ce_stage(ce), filename);
10711074
}
10721075

10731076
if (!lstat(filename, &st))

t/t1506-rev-parse-diagnosis.sh

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ exec </dev/null
66

77
. ./test-lib.sh
88

9+
test_did_you_mean ()
10+
{
11+
printf "fatal: Path '$2$3' $4, but not ${5:-'$3'}.\n" >expected &&
12+
printf "Did you mean '$1:$2$3'${2:+ aka '$1:./$3'}?\n" >>expected &&
13+
test_cmp expected error
14+
}
15+
916
HASH_file=
1017

1118
test_expect_success 'set up basic repo' '
@@ -106,7 +113,7 @@ test_expect_success 'incorrect file in sha1:path' '
106113
grep "fatal: Path '"'"'index-only.txt'"'"' exists on disk, but not in '"'"'HEAD'"'"'." error &&
107114
(cd subdir &&
108115
test_must_fail git rev-parse HEAD:file2.txt 2> error &&
109-
grep "Did you mean '"'"'HEAD:subdir/file2.txt'"'"'?" error )
116+
test_did_you_mean HEAD subdir/ file2.txt exists )
110117
'
111118

112119
test_expect_success 'incorrect file in :path and :N:path' '
@@ -115,14 +122,14 @@ test_expect_success 'incorrect file in :path and :N:path' '
115122
test_must_fail git rev-parse :1:nothing.txt 2> error &&
116123
grep "Path '"'"'nothing.txt'"'"' does not exist (neither on disk nor in the index)." error &&
117124
test_must_fail git rev-parse :1:file.txt 2> error &&
118-
grep "Did you mean '"'"':0:file.txt'"'"'?" error &&
125+
test_did_you_mean ":0" "" file.txt "is in the index" "at stage 1" &&
119126
(cd subdir &&
120127
test_must_fail git rev-parse :1:file.txt 2> error &&
121-
grep "Did you mean '"'"':0:file.txt'"'"'?" error &&
128+
test_did_you_mean ":0" "" file.txt "is in the index" "at stage 1" &&
122129
test_must_fail git rev-parse :file2.txt 2> error &&
123-
grep "Did you mean '"'"':0:subdir/file2.txt'"'"'?" error &&
130+
test_did_you_mean ":0" subdir/ file2.txt "is in the index" &&
124131
test_must_fail git rev-parse :2:file2.txt 2> error &&
125-
grep "Did you mean '"'"':0:subdir/file2.txt'"'"'?" error) &&
132+
test_did_you_mean :0 subdir/ file2.txt "is in the index") &&
126133
test_must_fail git rev-parse :disk-only.txt 2> error &&
127134
grep "fatal: Path '"'"'disk-only.txt'"'"' exists on disk, but not in the index." error
128135
'

0 commit comments

Comments
 (0)