mirror of
https://github.com/git-for-windows/git.git
synced 2026-02-03 18:59:59 -06:00
Windows paths are typically limited to MAX_PATH = 260 characters, even
though the underlying NTFS file system supports paths up to 32,767 chars.
This limitation is also evident in Windows Explorer, cmd.exe and many
other applications (including IDEs).
Particularly annoying is that most Windows APIs return bogus error codes
if a relative path only barely exceeds MAX_PATH in conjunction with the
current directory, e.g. ERROR_PATH_NOT_FOUND / ENOENT instead of the
infinitely more helpful ERROR_FILENAME_EXCED_RANGE / ENAMETOOLONG.
Many Windows wide char APIs support longer than MAX_PATH paths through the
file namespace prefix ('\\?\' or '\\?\UNC\') followed by an absolute path.
Notable exceptions include functions dealing with executables and the
current directory (CreateProcess, LoadLibrary, Get/SetCurrentDirectory) as
well as the entire shell API (ShellExecute, SHGetSpecialFolderPath...).
Introduce a handle_long_path function to check the length of a specified
path properly (and fail with ENAMETOOLONG), and to optionally expand long
paths using the '\\?\' file namespace prefix. Short paths will not be
modified, so we don't need to worry about device names (NUL, CON, AUX).
Contrary to MSDN docs, the GetFullPathNameW function doesn't seem to be
limited to MAX_PATH (at least not on Win7), so we can use it to do the
heavy lifting of the conversion (translate '/' to '\', eliminate '.' and
'..', and make an absolute path).
Add long path error checking to xutftowcs_path for APIs with hard MAX_PATH
limit.
Add a new MAX_LONG_PATH constant and xutftowcs_long_path function for APIs
that support long paths.
While improved error checking is always active, long paths support must be
explicitly enabled via 'core.longpaths' option. This is to prevent end
users from shooting themselves in the foot by checking out files that Windows
Explorer, cmd/bash or their favorite IDE cannot handle.
Test suite:
Test the case is when the full pathname length of a dir is close
to 260 (MAX_PATH).
Bug report and an original reproducer by Andrey Rogozhnikov:
https://github.com/msysgit/git/pull/122#issuecomment-43604199
[jes: adjusted test number to avoid conflicts, added support for
chdir(), etc]
Thanks-to: Martin W. Kirst <maki@bitkings.de>
Thanks-to: Doug Kelly <dougk.ff7@gmail.com>
Original-test-by: Andrey Rogozhnikov <rogozhnikov.andrey@gmail.com>
Signed-off-by: Karsten Blees <blees@dcon.de>
Signed-off-by: Stepan Kasal <kasal@ucw.cz>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Josh Soref <jsoref@gmail.com>
111 lines
2.7 KiB
Bash
Executable File
111 lines
2.7 KiB
Bash
Executable File
#!/bin/sh
|
|
#
|
|
# Copyright (c) 2013 Doug Kelly
|
|
#
|
|
|
|
test_description='Test submodules with a path near PATH_MAX
|
|
|
|
This test verifies that "git submodule" initialization, update and clones work, including with recursive submodules and paths approaching PATH_MAX (260 characters on Windows)
|
|
'
|
|
|
|
TEST_NO_CREATE_REPO=1
|
|
. ./test-lib.sh
|
|
|
|
# cloning a submodule calls is_git_directory("$path/../.git/modules/$path"),
|
|
# which effectively limits the maximum length to PATH_MAX / 2 minus some
|
|
# overhead; start with 3 * 36 = 108 chars (test 2 fails if >= 110)
|
|
longpath36=0123456789abcdefghijklmnopqrstuvwxyz
|
|
longpath180=$longpath36$longpath36$longpath36$longpath36$longpath36
|
|
|
|
# the git database must fit within PATH_MAX, which limits the submodule name
|
|
# to PATH_MAX - len(pwd) - ~90 (= len("/objects//") + 40-byte sha1 + some
|
|
# overhead from the test case)
|
|
pwd=$(pwd)
|
|
pwdlen=$(echo "$pwd" | wc -c)
|
|
longpath=$(echo $longpath180 | cut -c 1-$((170-$pwdlen)))
|
|
|
|
test_expect_success 'submodule with a long path' '
|
|
git config --global protocol.file.allow always &&
|
|
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= \
|
|
git -c init.defaultBranch=long init --bare remote &&
|
|
test_create_repo bundle1 &&
|
|
(
|
|
cd bundle1 &&
|
|
test_commit "shoot" &&
|
|
git rev-parse --verify HEAD >../expect
|
|
) &&
|
|
mkdir home &&
|
|
(
|
|
cd home &&
|
|
git clone ../remote test &&
|
|
cd test &&
|
|
git checkout -B long &&
|
|
git submodule add ../bundle1 $longpath &&
|
|
test_commit "sogood" &&
|
|
(
|
|
cd $longpath &&
|
|
git rev-parse --verify HEAD >actual &&
|
|
test_cmp ../../../expect actual
|
|
) &&
|
|
git push origin long
|
|
) &&
|
|
mkdir home2 &&
|
|
(
|
|
cd home2 &&
|
|
git clone ../remote test &&
|
|
cd test &&
|
|
git checkout long &&
|
|
git submodule update --init &&
|
|
(
|
|
cd $longpath &&
|
|
git rev-parse --verify HEAD >actual &&
|
|
test_cmp ../../../expect actual
|
|
)
|
|
)
|
|
'
|
|
|
|
test_expect_success 'recursive submodule with a long path' '
|
|
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= \
|
|
git -c init.defaultBranch=long init --bare super &&
|
|
test_create_repo child &&
|
|
(
|
|
cd child &&
|
|
test_commit "shoot" &&
|
|
git rev-parse --verify HEAD >../expect
|
|
) &&
|
|
test_create_repo parent &&
|
|
(
|
|
cd parent &&
|
|
git submodule add ../child $longpath &&
|
|
test_commit "aim"
|
|
) &&
|
|
mkdir home3 &&
|
|
(
|
|
cd home3 &&
|
|
git clone ../super test &&
|
|
cd test &&
|
|
git checkout -B long &&
|
|
git submodule add ../parent foo &&
|
|
git submodule update --init --recursive &&
|
|
test_commit "sogood" &&
|
|
(
|
|
cd foo/$longpath &&
|
|
git rev-parse --verify HEAD >actual &&
|
|
test_cmp ../../../../expect actual
|
|
) &&
|
|
git push origin long
|
|
) &&
|
|
mkdir home4 &&
|
|
(
|
|
cd home4 &&
|
|
git clone ../super test --recursive &&
|
|
(
|
|
cd test/foo/$longpath &&
|
|
git rev-parse --verify HEAD >actual &&
|
|
test_cmp ../../../../expect actual
|
|
)
|
|
)
|
|
'
|
|
|
|
test_done
|