]> git.ipfire.org Git - thirdparty/git.git/commit - abspath.c
bundle: don't blindly apply prefix_filename() to "-"
authorJunio C Hamano <gitster@pobox.com>
Sat, 4 Mar 2023 10:27:56 +0000 (05:27 -0500)
committerJunio C Hamano <gitster@pobox.com>
Mon, 6 Mar 2023 21:12:56 +0000 (13:12 -0800)
commita8bfa99d443d3c461217db4924f8eca24caa055a
treee6b109e0ad33d97d927cd428e021efd2c5a3aa8a
parentef3b291a5f19d7e3b7f4cc4524003e50d40614f7
bundle: don't blindly apply prefix_filename() to "-"

A user can specify a filename to a command from the command line,
either as the value given to a command line option, or a command
line argument.  When it is given as a relative filename, in the
user's mind, it is relative to the directory "git" was started from,
but by the time the filename is used, "git" would almost always have
chdir()'ed up to the root level of the working tree.

The given filename, if it is relative, needs to be prefixed with the
path to the current directory, and it typically is done by calling
prefix_filename() helper function.  For commands that can also take
"-" to use the standard input or the standard output, however, this
needs to be done with care.

"git bundle create" uses the next word on the command line as the
output filename, and can take "-" to mean "write to the standard
output".  It blindly called prefix_filename(), so running it in a
subdirectory did not quite work as expected.

Introduce a new helper, prefix_filename_except_for_dash(), and use
it to help "git bundle create" codepath.

Reported-by: Michael Henry
Helped-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
abspath.c
builtin/bundle.c
cache.h
t/t6020-bundle-misc.sh