msysGit-based Git for Windows 1.x was superseded by Git for Windows 2.x
[git/mingw/4msysgit.git] / t / t2025-checkout-long-paths.sh
blob2504ce7602cd9afba798d1167a77958b0d86e01a
1 #!/bin/sh
3 test_description='checkout long paths on Windows
5 Ensures that Git for Windows can deal with long paths (>260) enabled via core.longpaths'
7 . ./test-lib.sh
9 if test_have_prereq NOT_MINGW
10 then
11 skip_all='skipping MINGW specific long paths test'
12 test_done
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 &&
38 git checkout -f &&
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 &&
47 git add $path &&
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 &&
65 p=y$p$p$p$p &&
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" &&
69 test 254 = ${#p2} &&
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" &&
78 i=0 &&
79 # The most important case is when absolute path is 258 characters long,
80 # and that will be when i == 4.
81 while test $i -le 7
83 mkdir -p $subdir2 &&
84 touch $subdir2/one-file &&
85 mv ${subdir2%%/*} "$subdir1/" &&
86 subdir2=z${subdir2} &&
87 i=$(($i+1)) ||
88 exit 1
89 done &&
91 # now check that git is able to clear the tree:
92 (cd testdir &&
93 git init &&
94 git config core.longpaths yes &&
95 git clean -fdx) &&
96 test ! -d "$subdir1"
99 test_done