diff options
author | Victoria Dye <vdye@github.com> | 2022-03-01 23:24:26 +0300 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2022-03-01 23:36:00 +0300 |
commit | cc89331ddc92cd89012eaf7937d167b3e0beaecc (patch) | |
tree | 78663939bf347fdc04f0d2171830a4463194bb7f /t/t1003-read-tree-prefix.sh | |
parent | 2c521b0e4900d8e7ff1f611ed956cfdd67f03eb0 (diff) |
read-tree: explicitly disallow prefixes with a leading '/'
Exit with an error if a prefix provided to `git read-tree --prefix` begins
with '/'. In most cases, prefixes like this result in an "invalid path"
error; however, the repository root would be interpreted as valid when
specified as '--prefix=/'. This is due to leniency around trailing directory
separators on prefixes (e.g., allowing both '--prefix=my-dir' and
'--prefix=my-dir/') - the '/' in the prefix is actually the *trailing*
slash, although it could be misinterpreted as a *leading* slash.
To remove the confusing repo root-as-'/' case and make it clear that
prefixes should not begin with '/', exit with an error if the first
character of the provided prefix is '/'.
Helped-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Victoria Dye <vdye@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't/t1003-read-tree-prefix.sh')
-rwxr-xr-x | t/t1003-read-tree-prefix.sh | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/t/t1003-read-tree-prefix.sh b/t/t1003-read-tree-prefix.sh index e0db2066f3..c860c08ecb 100755 --- a/t/t1003-read-tree-prefix.sh +++ b/t/t1003-read-tree-prefix.sh @@ -25,4 +25,14 @@ test_expect_success 'read-tree --prefix' ' cmp expect actual ' +test_expect_success 'read-tree --prefix with leading slash exits with error' ' + git rm -rf . && + test_must_fail git read-tree --prefix=/two/ $tree && + git read-tree --prefix=two/ $tree && + + git rm -rf . && + test_must_fail git read-tree --prefix=/ $tree && + git read-tree --prefix= $tree +' + test_done |