mirror of
https://github.com/git/git.git
synced 2026-03-01 18:24:00 +01:00
Merge branch 'jr/apply-directory-normalize' into next
"git apply --directory=./un/../normalized/path" now normalizes the given path before using it. * jr/apply-directory-normalize: apply: normalize path in --directory argument
This commit is contained in:
4
apply.c
4
apply.c
@@ -5022,6 +5022,10 @@ static int apply_option_parse_directory(const struct option *opt,
|
||||
|
||||
strbuf_reset(&state->root);
|
||||
strbuf_addstr(&state->root, arg);
|
||||
|
||||
if (strbuf_normalize_path(&state->root) < 0)
|
||||
return error(_("unable to normalize directory: '%s'"), arg);
|
||||
|
||||
strbuf_complete(&state->root, '/');
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -43,6 +43,47 @@ test_expect_success 'apply --directory -p (2) ' '
|
||||
|
||||
'
|
||||
|
||||
test_expect_success 'apply --directory (./ prefix)' '
|
||||
git reset --hard initial &&
|
||||
git apply --directory=./some/sub -p3 --index patch &&
|
||||
echo Bello >expect &&
|
||||
git show :some/sub/dir/file >actual &&
|
||||
test_cmp expect actual &&
|
||||
test_cmp expect some/sub/dir/file
|
||||
'
|
||||
|
||||
test_expect_success 'apply --directory (double slash)' '
|
||||
git reset --hard initial &&
|
||||
git apply --directory=some//sub -p3 --index patch &&
|
||||
echo Bello >expect &&
|
||||
git show :some/sub/dir/file >actual &&
|
||||
test_cmp expect actual &&
|
||||
test_cmp expect some/sub/dir/file
|
||||
'
|
||||
|
||||
test_expect_success 'apply --directory (./ in the middle)' '
|
||||
git reset --hard initial &&
|
||||
git apply --directory=some/./sub -p3 --index patch &&
|
||||
echo Bello >expect &&
|
||||
git show :some/sub/dir/file >actual &&
|
||||
test_cmp expect actual &&
|
||||
test_cmp expect some/sub/dir/file
|
||||
'
|
||||
|
||||
test_expect_success 'apply --directory (../ in the middle)' '
|
||||
git reset --hard initial &&
|
||||
git apply --directory=some/../some/sub -p3 --index patch &&
|
||||
echo Bello >expect &&
|
||||
git show :some/sub/dir/file >actual &&
|
||||
test_cmp expect actual &&
|
||||
test_cmp expect some/sub/dir/file
|
||||
'
|
||||
|
||||
test_expect_success 'apply --directory rejects leading ../' '
|
||||
test_must_fail git apply --directory=../foo -p3 patch 2>err &&
|
||||
test_grep "unable to normalize directory" err
|
||||
'
|
||||
|
||||
cat > patch << EOF
|
||||
diff --git a/newfile b/newfile
|
||||
new file mode 100644
|
||||
|
||||
Reference in New Issue
Block a user