@@ -1209,6 +1209,124 @@ test_expect_success 'teardown after ref completion' '
12091209 git remote remove other
12101210'
12111211
1212+
1213+ test_path_completion ()
1214+ {
1215+ test $# = 2 || error " bug in the test script: not 2 parameters to test_path_completion"
1216+
1217+ local cur=" $1 " expected=" $2 "
1218+ echo " $expected " > expected &&
1219+ (
1220+ # In the following tests calling this function we only
1221+ # care about how __git_complete_index_file() deals with
1222+ # unusual characters in path names. By requesting only
1223+ # untracked files we dont have to bother adding any
1224+ # paths to the index in those tests.
1225+ __git_complete_index_file --others &&
1226+ print_comp
1227+ ) &&
1228+ test_cmp expected out
1229+ }
1230+
1231+ test_expect_success ' setup for path completion tests' '
1232+ mkdir simple-dir \
1233+ "spaces in dir" \
1234+ árvíztűrő &&
1235+ touch simple-dir/simple-file \
1236+ "spaces in dir/spaces in file" \
1237+ "árvíztűrő/Сайн яваарай" &&
1238+ if test_have_prereq !MINGW &&
1239+ mkdir BS\\dir \
1240+ ' $' separators\034 in\035 dir' ' &&
1241+ touch BS\\dir/DQ\"file \
1242+ ' $' separators\034 in\035 dir/sep\036 in\037 file' '
1243+ then
1244+ test_set_prereq FUNNYNAMES
1245+ else
1246+ rm -rf BS\\dir ' $' separators\034 in\035 dir' '
1247+ fi
1248+ '
1249+
1250+ test_expect_success ' __git_complete_index_file - simple' '
1251+ test_path_completion simple simple-dir && # Bash is supposed to
1252+ # add the trailing /.
1253+ test_path_completion simple-dir/simple simple-dir/simple-file
1254+ '
1255+
1256+ test_expect_success \
1257+ ' __git_complete_index_file - escaped characters on cmdline' '
1258+ test_path_completion spac "spaces in dir" && # Bash will turn this
1259+ # into "spaces\ in\ dir"
1260+ test_path_completion "spaces\\ i" \
1261+ "spaces in dir" &&
1262+ test_path_completion "spaces\\ in\\ dir/s" \
1263+ "spaces in dir/spaces in file" &&
1264+ test_path_completion "spaces\\ in\\ dir/spaces\\ i" \
1265+ "spaces in dir/spaces in file"
1266+ '
1267+
1268+ test_expect_success \
1269+ ' __git_complete_index_file - quoted characters on cmdline' '
1270+ # Testing with an opening but without a corresponding closing
1271+ # double quote is important.
1272+ test_path_completion \"spac "spaces in dir" &&
1273+ test_path_completion "\"spaces i" \
1274+ "spaces in dir" &&
1275+ test_path_completion "\"spaces in dir/s" \
1276+ "spaces in dir/spaces in file" &&
1277+ test_path_completion "\"spaces in dir/spaces i" \
1278+ "spaces in dir/spaces in file"
1279+ '
1280+
1281+ test_expect_success ' __git_complete_index_file - UTF-8 in ls-files output' '
1282+ test_path_completion á árvíztűrő &&
1283+ test_path_completion árvíztűrő/С "árvíztűrő/Сайн яваарай"
1284+ '
1285+
1286+ test_expect_success FUNNYNAMES \
1287+ ' __git_complete_index_file - C-style escapes in ls-files output' '
1288+ test_path_completion BS \
1289+ BS\\dir &&
1290+ test_path_completion BS\\\\d \
1291+ BS\\dir &&
1292+ test_path_completion BS\\\\dir/DQ \
1293+ BS\\dir/DQ\"file &&
1294+ test_path_completion BS\\\\dir/DQ\\\"f \
1295+ BS\\dir/DQ\"file
1296+ '
1297+
1298+ test_expect_success FUNNYNAMES \
1299+ ' __git_complete_index_file - \nnn-escaped characters in ls-files output' '
1300+ test_path_completion sep ' $' separators\034 in\035 dir' ' &&
1301+ test_path_completion ' $' separators\034 i' ' \
1302+ ' $' separators\034 in\035 dir' ' &&
1303+ test_path_completion ' $' separators\034 in\035 dir/sep' ' \
1304+ ' $' separators\034 in\035 dir/sep\036 in\037 file' ' &&
1305+ test_path_completion ' $' separators\034 in\035 dir/sep\036 i' ' \
1306+ ' $' separators\034 in\035 dir/sep\036 in\037 file' '
1307+ '
1308+
1309+ test_expect_success FUNNYNAMES \
1310+ ' __git_complete_index_file - removing repeated quoted path components' '
1311+ test_when_finished rm -r repeated-quoted &&
1312+ mkdir repeated-quoted && # A directory whose name in itself
1313+ # would not be quoted ...
1314+ >repeated-quoted/0-file &&
1315+ >repeated-quoted/1\"file && # ... but here the file makes the
1316+ # dirname quoted ...
1317+ >repeated-quoted/2-file &&
1318+ >repeated-quoted/3\"file && # ... and here, too.
1319+
1320+ # Still, we shold only list the directory name only once.
1321+ test_path_completion repeated repeated-quoted
1322+ '
1323+
1324+ test_expect_success ' teardown after path completion tests' '
1325+ rm -rf simple-dir "spaces in dir" árvíztűrő \
1326+ BS\\dir ' $' separators\034 in\035 dir' '
1327+ '
1328+
1329+
12121330test_expect_success ' __git_get_config_variables' '
12131331 cat >expect <<-EOF &&
12141332 name-1
@@ -1469,113 +1587,6 @@ test_expect_success 'complete files' '
14691587 test_completion "git add mom" "momified"
14701588'
14711589
1472- # The next tests only care about how the completion script deals with
1473- # unusual characters in path names. By defining a custom completion
1474- # function to list untracked files they won't be influenced by future
1475- # changes of the completion functions of real git commands, and we
1476- # don't have to bother with adding files to the index in these tests.
1477- _git_test_path_comp ()
1478- {
1479- __git_complete_index_file --others
1480- }
1481-
1482- test_expect_success ' complete files - escaped characters on cmdline' '
1483- test_when_finished "rm -rf \"New|Dir\"" &&
1484- mkdir "New|Dir" &&
1485- >"New|Dir/New&File.c" &&
1486-
1487- test_completion "git test-path-comp N" \
1488- "New|Dir" && # Bash will turn this into "New\|Dir/"
1489- test_completion "git test-path-comp New\\|D" \
1490- "New|Dir" &&
1491- test_completion "git test-path-comp New\\|Dir/N" \
1492- "New|Dir/New&File.c" && # Bash will turn this into
1493- # "New\|Dir/New\&File.c "
1494- test_completion "git test-path-comp New\\|Dir/New\\&F" \
1495- "New|Dir/New&File.c"
1496- '
1497-
1498- test_expect_success ' complete files - quoted characters on cmdline' '
1499- test_when_finished "rm -r \"New(Dir\"" &&
1500- mkdir "New(Dir" &&
1501- >"New(Dir/New)File.c" &&
1502-
1503- # Testing with an opening but without a corresponding closing
1504- # double quote is important.
1505- test_completion "git test-path-comp \"New(D" "New(Dir" &&
1506- test_completion "git test-path-comp \"New(Dir/New)F" \
1507- "New(Dir/New)File.c"
1508- '
1509-
1510- test_expect_success ' complete files - UTF-8 in ls-files output' '
1511- test_when_finished "rm -r árvíztűrő" &&
1512- mkdir árvíztűrő &&
1513- >"árvíztűrő/Сайн яваарай" &&
1514-
1515- test_completion "git test-path-comp á" "árvíztűrő" &&
1516- test_completion "git test-path-comp árvíztűrő/С" \
1517- "árvíztűrő/Сайн яваарай"
1518- '
1519-
1520- # Testing with a path containing a backslash is important.
1521- if test_have_prereq ! MINGW &&
1522- mkdir ' New\Dir' 2> /dev/null &&
1523- touch ' New\Dir/New"File.c' 2> /dev/null
1524- then
1525- test_set_prereq FUNNYNAMES_BS_DQ
1526- else
1527- say " Your filesystem does not allow \\ and \" in filenames."
1528- rm -rf ' New\Dir'
1529- fi
1530- test_expect_success FUNNYNAMES_BS_DQ \
1531- ' complete files - C-style escapes in ls-files output' '
1532- test_when_finished "rm -r \"New\\\\Dir\"" &&
1533-
1534- test_completion "git test-path-comp N" "New\\Dir" &&
1535- test_completion "git test-path-comp New\\\\D" "New\\Dir" &&
1536- test_completion "git test-path-comp New\\\\Dir/N" \
1537- "New\\Dir/New\"File.c" &&
1538- test_completion "git test-path-comp New\\\\Dir/New\\\"F" \
1539- "New\\Dir/New\"File.c"
1540- '
1541-
1542- if test_have_prereq ! MINGW &&
1543- mkdir $' New\034 Special\035 Dir' 2> /dev/null &&
1544- touch $' New\034 Special\035 Dir/New\036 Special\037 File' 2> /dev/null
1545- then
1546- test_set_prereq FUNNYNAMES_SEPARATORS
1547- else
1548- say ' Your filesystem does not allow special separator characters (FS, GS, RS, US) in filenames.'
1549- rm -rf $' New\034 Special\035 Dir'
1550- fi
1551- test_expect_success FUNNYNAMES_SEPARATORS \
1552- ' complete files - \nnn-escaped control characters in ls-files output' '
1553- test_when_finished "rm -r ' $' New\034 Special\035 Dir' ' " &&
1554-
1555- # Note: these will be literal separator characters on the cmdline.
1556- test_completion "git test-path-comp N" "' $' New\034 Special\035 Dir' ' " &&
1557- test_completion "git test-path-comp ' $' New\034 S' ' " \
1558- "' $' New\034 Special\035 Dir' ' " &&
1559- test_completion "git test-path-comp ' $' New\034 Special\035 Dir/' ' " \
1560- "' $' New\034 Special\035 Dir/New\036 Special\037 File' ' " &&
1561- test_completion "git test-path-comp ' $' New\034 Special\035 Dir/New\036 S' ' " \
1562- "' $' New\034 Special\035 Dir/New\036 Special\037 File' ' "
1563- '
1564-
1565- test_expect_success FUNNYNAMES_BS_DQ \
1566- ' complete files - removing repeated quoted path components' '
1567- test_when_finished rm -rf NewDir &&
1568- mkdir NewDir && # A dirname which in itself would not be quoted ...
1569- >NewDir/0-file &&
1570- >NewDir/1\"file && # ... but here the file makes the dirname quoted ...
1571- >NewDir/2-file &&
1572- >NewDir/3\"file && # ... and here, too.
1573-
1574- # Still, we should only list it once.
1575- test_completion "git test-path-comp New" "NewDir"
1576- '
1577-
1578-
15791590test_expect_success " completion uses <cmd> completion for alias: !sh -c 'git <cmd> ...'" '
15801591 test_config alias.co "!sh -c ' " '" ' git checkout ...' " '" ' " &&
15811592 test_completion "git co m" <<-\EOF
0 commit comments