3 test_description
='checkout long paths on Windows
5 Ensures that Git for Windows can deal with long paths (>260) enabled via core.longpaths'
9 if test_have_prereq NOT_MINGW
11 skip_all
='skipping MINGW specific long paths test'
15 test_expect_success setup
'
16 p=longpathxx && # -> 10
17 p=$p$p$p$p$p && # -> 50
18 p=$p$p$p$p$p && # -> 250
20 path=${p}/longtestfile && # -> 263 (MAX_PATH = 260)
22 blob=$(echo foobar | git hash-object -w --stdin) &&
24 printf "100644 %s 0\t%s\n" "$blob" "$path" |
25 git update-index --add --index-info &&
26 git commit -m initial -q
29 test_expect_success
'checkout of long paths without core.longpaths fails' '
30 git config core.longpaths false &&
31 test_must_fail git checkout -f 2>error &&
32 grep -q "Filename too long" error &&
33 test_path_is_missing longpa~1/longtestfile
36 test_expect_success
'checkout of long paths with core.longpaths works' '
37 git config core.longpaths true &&
39 test_path_is_file longpa~1/longtestfile
42 test_expect_success
'update of long paths' '
43 echo frotz >> longpa~1/longtestfile &&
44 echo $path > expect &&
45 git ls-files -m > actual &&
46 test_cmp expect actual &&
48 git commit -m second &&
49 git grep "frotz" HEAD -- $path
52 test_expect_success cleanup
'
53 # bash cannot delete the trash dir if it contains a long path
54 # lets help cleaning up (unless in debug mode)
55 test ! -z "$debug" || rm -rf longpa~1
58 # check that the template used in the test won't be too long:
59 abspath
="$(pwd -W)"/testdir
60 test ${#abspath} -gt 230 ||
61 test_set_prereq SHORTABSPATH
63 test_expect_success SHORTABSPATH
'clean up path close to MAX_PATH' '
64 p=/123456789abcdef/123456789abcdef/123456789abcdef/123456789abc/ef &&
66 subdir="x$(echo "$p" | tail -c $((253 - ${#abspath})))" &&
67 # Now, $abspath/$subdir has exactly 254 characters, and is inside CWD
68 p2="$abspath/$subdir" &&
71 # Be careful to overcome path limitations of the MSys tools and split
72 # the $subdir into two parts. ($subdir2 has to contain 16 chars and a
73 # slash somewhere following; that is why we asked for abspath <= 230 and
74 # why we placed a slash near the end of the $subdir template.)
75 subdir2=${subdir#????????????????*/} &&
76 subdir1=testdir/${subdir%/$subdir2} &&
77 mkdir -p "$subdir1" &&
79 # The most important case is when absolute path is 258 characters long,
80 # and that will be when i == 4.
84 touch $subdir2/one-file &&
85 mv ${subdir2%%/*} "$subdir1/" &&
86 subdir2=z${subdir2} &&
91 # now check that git is able to clear the tree:
94 git config core.longpaths yes &&