1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-06-10 19:16:14 +02:00
git/t/t9304-fast-import-marks.sh
Jeff King 9dc607f1c2 fast-import: fix file access when run from subdir
In cmd_fast_import(), we ignore the "prefix" argument entirely, even
though it tells us how we may have changed directory to the root of the
repository earlier in the process. Which means that if you run it from a
subdir and point to paths in the filesystem, like:

  cd subdir
  git fast-import --import-marks=foo <dump

then it will look for "foo" in the root of the repository, not the
current directory ("subdir/") which the user would have expected.

We can fix this by recording the prefix and using it as appropriate
whenever we open a file for reading or writing. I found each of these by
looking for cases where we call fopen() within fast-import.c, so this
should cover all cases. The new test triggers each one, as well as
making sure we don't accidentally apply the prefix when --relative-marks
is in use (since that option interprets some paths as relative to a
specific directory).

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2023-03-28 14:11:24 -07:00

82 lines
2.4 KiB
Bash
Executable File

#!/bin/sh
test_description='test exotic situations with marks'
. ./test-lib.sh
test_expect_success 'setup dump of basic history' '
test_commit one &&
git fast-export --export-marks=marks HEAD >dump
'
test_expect_success 'setup large marks file' '
# normally a marks file would have a lot of useful, unique
# marks. But for our purposes, just having a lot of nonsense
# ones is fine. Start at 1024 to avoid clashing with marks
# legitimately used in our tiny dump.
blob=$(git rev-parse HEAD:one.t) &&
for i in $(test_seq 1024 16384)
do
echo ":$i $blob" || return 1
done >>marks
'
test_expect_success 'import with large marks file' '
git fast-import --import-marks=marks <dump
'
test_expect_success 'setup dump with submodule' '
test_config_global protocol.file.allow always &&
git submodule add "$PWD" sub &&
git commit -m "add submodule" &&
git fast-export HEAD >dump
'
test_expect_success 'setup submodule mapping with large id' '
old=$(git rev-parse HEAD:sub) &&
new=$(echo $old | sed s/./a/g) &&
echo ":12345 $old" >from &&
echo ":12345 $new" >to
'
test_expect_success 'import with submodule mapping' '
git init dst &&
git -C dst fast-import \
--rewrite-submodules-from=sub:../from \
--rewrite-submodules-to=sub:../to \
<dump &&
git -C dst rev-parse HEAD:sub >actual &&
echo "$new" >expect &&
test_cmp expect actual
'
test_expect_success 'paths adjusted for relative subdir' '
git init deep-dst &&
mkdir deep-dst/subdir &&
>deep-dst/subdir/empty-marks &&
git -C deep-dst/subdir fast-import \
--rewrite-submodules-from=sub:../../from \
--rewrite-submodules-to=sub:../../to \
--import-marks=empty-marks \
--export-marks=exported-marks \
--export-pack-edges=exported-edges \
<dump &&
# we do not bother checking resulting repo; we just care that nothing
# complained about failing to open files for reading, and that files
# for writing were created in the expected spot
test_path_is_file deep-dst/subdir/exported-marks &&
test_path_is_file deep-dst/subdir/exported-edges
'
test_expect_success 'relative marks are not affected by subdir' '
git init deep-relative &&
mkdir deep-relative/subdir &&
git -C deep-relative/subdir fast-import \
--relative-marks \
--export-marks=exported-marks \
<dump &&
test_path_is_missing deep-relative/subdir/exported-marks &&
test_path_is_file deep-relative/.git/info/fast-import/exported-marks
'
test_done