mirror of
https://github.com/git/git.git
synced 2024-12-14 04:18:16 +08:00
cc89331ddc
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>
39 lines
734 B
Bash
Executable File
39 lines
734 B
Bash
Executable File
#!/bin/sh
|
|
#
|
|
# Copyright (c) 2006 Junio C Hamano
|
|
#
|
|
|
|
test_description='git read-tree --prefix test.
|
|
'
|
|
|
|
TEST_PASSES_SANITIZE_LEAK=true
|
|
. ./test-lib.sh
|
|
|
|
test_expect_success setup '
|
|
echo hello >one &&
|
|
git update-index --add one &&
|
|
tree=$(git write-tree) &&
|
|
echo tree is $tree
|
|
'
|
|
|
|
echo 'one
|
|
two/one' >expect
|
|
|
|
test_expect_success 'read-tree --prefix' '
|
|
git read-tree --prefix=two/ $tree &&
|
|
git ls-files >actual &&
|
|
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
|