]> git.ipfire.org Git - thirdparty/git.git/commit - archive.c
archive: improve support for running in subdirectory
authorRené Scharfe <l.s.r@web.de>
Fri, 24 Mar 2023 22:27:11 +0000 (23:27 +0100)
committerJunio C Hamano <gitster@pobox.com>
Fri, 24 Mar 2023 22:51:25 +0000 (15:51 -0700)
commit92b1dd1b9e6e272c5115d6e37e19a892610a2686
tree2503aedc0bbb05d5b53879416bda5e36c417624d
parent73876f4861cd3d187a4682290ab75c9dccadbc56
archive: improve support for running in subdirectory

When git archive is started in a subdirectory, it archives its
corresponding tree and its child objects, only.  That is intended.  It
does that by effectively cd'ing into that tree and setting "prefix" to
the empty string.

This has unfortunate consequences, though: Attributes are anchored at
the root of the repository and git archive still applies them to
subtrees, causing mismatches.  And when checking pathspecs it cannot
tell the difference between one that doesn't match anthing or one that
matches some actual blob outside of the subdirectory, leading to a
confusing error message.

Fix that by keeping the "prefix" value and passing it to pathspec and
attribute functions, and shortening it using relative_path() for paths
written to the archive and (if --verbose is given) to stdout.

Still reject attempts to archive files outside the current directory,
but print a more specific error in that case.  Recognizing it requires a
full traversal of the subtree for each pathspec, however.  Allowing them
would be easier, but archive entry paths starting with "../" can be
problematic to extract -- e.g. bsdtar skips them by default.

Reported-by: Cristian Le <cristian.le@mpsd.mpg.de>
Reported-by: Matthias Görgens <matthias.goergens@gmail.com>
Signed-off-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
archive.c
t/t5000-tar-tree.sh
t/t5001-archive-attr.sh