Merge branch 'mg/sha1-path-advise'

* mg/sha1-path-advise:
  sha1_name: Suggest commit:./file for path in subdir
  t1506: factor out test for "Did you mean..."
This commit is contained in:
Junio C Hamano 2011-04-27 11:36:40 -07:00
Родитель b5a49471f0 e41d718c7d
Коммит 385185403e
2 изменённых файлов: 19 добавлений и 9 удалений

Просмотреть файл

@ -1012,11 +1012,13 @@ static void diagnose_invalid_sha1_path(const char *prefix,
if (!get_tree_entry(tree_sha1, fullname, if (!get_tree_entry(tree_sha1, fullname,
sha1, &mode)) { sha1, &mode)) {
die("Path '%s' exists, but not '%s'.\n" die("Path '%s' exists, but not '%s'.\n"
"Did you mean '%s:%s'?", "Did you mean '%s:%s' aka '%s:./%s'?",
fullname, fullname,
filename, filename,
object_name, object_name,
fullname); fullname,
object_name,
filename);
} }
die("Path '%s' does not exist in '%s'", die("Path '%s' does not exist in '%s'",
filename, object_name); filename, object_name);
@ -1065,9 +1067,10 @@ static void diagnose_invalid_index_path(int stage,
if (ce_namelen(ce) == fullnamelen && if (ce_namelen(ce) == fullnamelen &&
!memcmp(ce->name, fullname, fullnamelen)) !memcmp(ce->name, fullname, fullnamelen))
die("Path '%s' is in the index, but not '%s'.\n" die("Path '%s' is in the index, but not '%s'.\n"
"Did you mean ':%d:%s'?", "Did you mean ':%d:%s' aka ':%d:./%s'?",
fullname, filename, fullname, filename,
ce_stage(ce), fullname); ce_stage(ce), fullname,
ce_stage(ce), filename);
} }
if (!lstat(filename, &st)) if (!lstat(filename, &st))

Просмотреть файл

@ -6,6 +6,13 @@ exec </dev/null
. ./test-lib.sh . ./test-lib.sh
test_did_you_mean ()
{
printf "fatal: Path '$2$3' $4, but not ${5:-'$3'}.\n" >expected &&
printf "Did you mean '$1:$2$3'${2:+ aka '$1:./$3'}?\n" >>expected &&
test_cmp expected error
}
HASH_file= HASH_file=
test_expect_success 'set up basic repo' ' test_expect_success 'set up basic repo' '
@ -106,7 +113,7 @@ test_expect_success 'incorrect file in sha1:path' '
grep "fatal: Path '"'"'index-only.txt'"'"' exists on disk, but not in '"'"'HEAD'"'"'." error && grep "fatal: Path '"'"'index-only.txt'"'"' exists on disk, but not in '"'"'HEAD'"'"'." error &&
(cd subdir && (cd subdir &&
test_must_fail git rev-parse HEAD:file2.txt 2> error && test_must_fail git rev-parse HEAD:file2.txt 2> error &&
grep "Did you mean '"'"'HEAD:subdir/file2.txt'"'"'?" error ) test_did_you_mean HEAD subdir/ file2.txt exists )
' '
test_expect_success 'incorrect file in :path and :N:path' ' test_expect_success 'incorrect file in :path and :N:path' '
@ -115,14 +122,14 @@ test_expect_success 'incorrect file in :path and :N:path' '
test_must_fail git rev-parse :1:nothing.txt 2> error && test_must_fail git rev-parse :1:nothing.txt 2> error &&
grep "Path '"'"'nothing.txt'"'"' does not exist (neither on disk nor in the index)." error && grep "Path '"'"'nothing.txt'"'"' does not exist (neither on disk nor in the index)." error &&
test_must_fail git rev-parse :1:file.txt 2> error && test_must_fail git rev-parse :1:file.txt 2> error &&
grep "Did you mean '"'"':0:file.txt'"'"'?" error && test_did_you_mean ":0" "" file.txt "is in the index" "at stage 1" &&
(cd subdir && (cd subdir &&
test_must_fail git rev-parse :1:file.txt 2> error && test_must_fail git rev-parse :1:file.txt 2> error &&
grep "Did you mean '"'"':0:file.txt'"'"'?" error && test_did_you_mean ":0" "" file.txt "is in the index" "at stage 1" &&
test_must_fail git rev-parse :file2.txt 2> error && test_must_fail git rev-parse :file2.txt 2> error &&
grep "Did you mean '"'"':0:subdir/file2.txt'"'"'?" error && test_did_you_mean ":0" subdir/ file2.txt "is in the index" &&
test_must_fail git rev-parse :2:file2.txt 2> error && test_must_fail git rev-parse :2:file2.txt 2> error &&
grep "Did you mean '"'"':0:subdir/file2.txt'"'"'?" error) && test_did_you_mean :0 subdir/ file2.txt "is in the index") &&
test_must_fail git rev-parse :disk-only.txt 2> error && test_must_fail git rev-parse :disk-only.txt 2> error &&
grep "fatal: Path '"'"'disk-only.txt'"'"' exists on disk, but not in the index." error grep "fatal: Path '"'"'disk-only.txt'"'"' exists on disk, but not in the index." error
' '