Skip to content

Commit 5bb534a

Browse files
szedergitster
authored andcommitted
t9902-completion: add tests demonstrating issues with quoted pathnames
Completion functions see all words on the command line verbatim, including any backslash-escapes, single and double quotes that might be there. Furthermore, git commands quote pathnames if they contain certain special characters. All these create various issues when doing git-aware path completion. Add a couple of failing tests to demonstrate these issues. Later patches in this series will discuss these issues in detail as they fix them. Signed-off-by: SZEDER Gábor <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent fe0a9ea commit 5bb534a

File tree

1 file changed

+91
-0
lines changed

1 file changed

+91
-0
lines changed

t/t9902-completion.sh

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1427,6 +1427,97 @@ test_expect_success 'complete files' '
14271427
test_completion "git add mom" "momified"
14281428
'
14291429

1430+
# The next tests only care about how the completion script deals with
1431+
# unusual characters in path names. By defining a custom completion
1432+
# function to list untracked files they won't be influenced by future
1433+
# changes of the completion functions of real git commands, and we
1434+
# don't have to bother with adding files to the index in these tests.
1435+
_git_test_path_comp ()
1436+
{
1437+
__git_complete_index_file --others
1438+
}
1439+
1440+
test_expect_failure 'complete files - escaped characters on cmdline' '
1441+
test_when_finished "rm -rf \"New|Dir\"" &&
1442+
mkdir "New|Dir" &&
1443+
>"New|Dir/New&File.c" &&
1444+
1445+
test_completion "git test-path-comp N" \
1446+
"New|Dir" && # Bash will turn this into "New\|Dir/"
1447+
test_completion "git test-path-comp New\\|D" \
1448+
"New|Dir" &&
1449+
test_completion "git test-path-comp New\\|Dir/N" \
1450+
"New|Dir/New&File.c" && # Bash will turn this into
1451+
# "New\|Dir/New\&File.c "
1452+
test_completion "git test-path-comp New\\|Dir/New\\&F" \
1453+
"New|Dir/New&File.c"
1454+
'
1455+
1456+
test_expect_failure 'complete files - quoted characters on cmdline' '
1457+
test_when_finished "rm -r \"New(Dir\"" &&
1458+
mkdir "New(Dir" &&
1459+
>"New(Dir/New)File.c" &&
1460+
1461+
test_completion "git test-path-comp \"New(D" "New(Dir" &&
1462+
test_completion "git test-path-comp \"New(Dir/New)F" \
1463+
"New(Dir/New)File.c"
1464+
'
1465+
1466+
test_expect_failure 'complete files - UTF-8 in ls-files output' '
1467+
test_when_finished "rm -r árvíztűrő" &&
1468+
mkdir árvíztűrő &&
1469+
>"árvíztűrő/Сайн яваарай" &&
1470+
1471+
test_completion "git test-path-comp á" "árvíztűrő" &&
1472+
test_completion "git test-path-comp árvíztűrő/С" \
1473+
"árvíztűrő/Сайн яваарай"
1474+
'
1475+
1476+
if test_have_prereq !MINGW &&
1477+
mkdir 'New\Dir' 2>/dev/null &&
1478+
touch 'New\Dir/New"File.c' 2>/dev/null
1479+
then
1480+
test_set_prereq FUNNYNAMES_BS_DQ
1481+
else
1482+
say "Your filesystem does not allow \\ and \" in filenames."
1483+
rm -rf 'New\Dir'
1484+
fi
1485+
test_expect_failure FUNNYNAMES_BS_DQ \
1486+
'complete files - C-style escapes in ls-files output' '
1487+
test_when_finished "rm -r \"New\\\\Dir\"" &&
1488+
1489+
test_completion "git test-path-comp N" "New\\Dir" &&
1490+
test_completion "git test-path-comp New\\\\D" "New\\Dir" &&
1491+
test_completion "git test-path-comp New\\\\Dir/N" \
1492+
"New\\Dir/New\"File.c" &&
1493+
test_completion "git test-path-comp New\\\\Dir/New\\\"F" \
1494+
"New\\Dir/New\"File.c"
1495+
'
1496+
1497+
if test_have_prereq !MINGW &&
1498+
mkdir $'New\034Special\035Dir' 2>/dev/null &&
1499+
touch $'New\034Special\035Dir/New\036Special\037File' 2>/dev/null
1500+
then
1501+
test_set_prereq FUNNYNAMES_SEPARATORS
1502+
else
1503+
say 'Your filesystem does not allow special separator characters (FS, GS, RS, US) in filenames.'
1504+
rm -rf $'New\034Special\035Dir'
1505+
fi
1506+
test_expect_failure FUNNYNAMES_SEPARATORS \
1507+
'complete files - \nnn-escaped control characters in ls-files output' '
1508+
test_when_finished "rm -r '$'New\034Special\035Dir''" &&
1509+
1510+
# Note: these will be literal separator characters on the cmdline.
1511+
test_completion "git test-path-comp N" "'$'New\034Special\035Dir''" &&
1512+
test_completion "git test-path-comp '$'New\034S''" \
1513+
"'$'New\034Special\035Dir''" &&
1514+
test_completion "git test-path-comp '$'New\034Special\035Dir/''" \
1515+
"'$'New\034Special\035Dir/New\036Special\037File''" &&
1516+
test_completion "git test-path-comp '$'New\034Special\035Dir/New\036S''" \
1517+
"'$'New\034Special\035Dir/New\036Special\037File''"
1518+
'
1519+
1520+
14301521
test_expect_success "completion uses <cmd> completion for alias: !sh -c 'git <cmd> ...'" '
14311522
test_config alias.co "!sh -c '"'"'git checkout ...'"'"'" &&
14321523
test_completion "git co m" <<-\EOF

0 commit comments

Comments
 (0)