fast-import: fix file access when run from subdir
commit9dc607f1c29de88bc5194df49cc7f834e528a3e9
authorJeff King <peff@peff.net>
Tue, 28 Mar 2023 20:54:13 +0000 (28 16:54 -0400)
committerJunio C Hamano <gitster@pobox.com>
Tue, 28 Mar 2023 21:11:24 +0000 (28 14:11 -0700)
treecaa0023398a0667e97a59119e35feafc1546fcc5
parent8d90352acc5c855620042fdcc6092f23a276af6d
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>
builtin/fast-import.c
t/t9304-fast-import-marks.sh