[RFC] archive: behavior of --prefix with absolute or parent path components
- From
Pushkar Singh <pushkarkumarsingh1970@gmail.com>
- Date
- Apr 7, 2026, 16:21 UTC
- Message-ID
- <20260407162101.2285-1-pushkarkumarsingh1970@gmail.com>
Hi,
While experimenting with "git archive", I noticed some behavior around the --prefix option that might be worth clarifying.
Currently, --prefix accepts values such as absolute paths or ones with ..,
e.g.:
git archive --prefix=/ HEAD > out.tar
git archive --prefix=//// HEAD > out.tar
git archive --prefix=../../ HEAD > out.tarUpon listing the archive contents (e.g., tar -tf), you get entries like:
/a.txt
////a.txt
../../a.txtIn such cases, tar emits warnings like:
"Removing leading '/' from member names"
"Removing leading '../' from member names"This suggests that Git passes the prefix through as-is, relying on downstream tools to sanitize potentially unsafe paths.
From a user perspective, I was wondering:
- Is this behavior intentional (i.e., leaving validation to archive
consumers)?
- Would it be worth documenting this explicitly?
- Or should there be any normalization or validation at the Git level?I understand that Git generally avoids enforcing policy decisions in such cases, but I wanted to confirm whether this behavior is intentional.
I’d appreciate any thoughts on this :-)
Thanks, Pushkar