path: root/t/
diff options
authorRené Scharfe <>2010-02-07 23:30:20 (GMT)
committerJunio C Hamano <>2010-02-07 23:40:27 (GMT)
commitfe12d8e84f745303d64757307e9a6a81a6608018 (patch)
tree0e0fbad1cb5efcb49c893c5a94f2bcbdc15754af /t/
parent2b26e0e18907132eaac2a8163de0cac552217082 (diff)
archive: simplify archive format guessing
The code to guess an output archive's format consumed any --format options and built a new one. Jonathan noticed that it does so in an unsafe way, risking to overflow the static buffer fmt_opt. Change the code to keep the existing --format options intact and to only add a new one if a format could be guessed based on the output file name. The new option is added as the first one, allowing the existing ones to overrule it, i.e. explicit --format options given on the command line win over format guesses, as before. To simplify the code further, format_from_name() is changed to return the full --format option, thus no potentially dangerous sprintf() calls are needed any more. Reported-by: Jonathan Nieder <> Signed-off-by: Rene Scharfe <> Signed-off-by: Junio C Hamano <>
Diffstat (limited to 't/')
1 files changed, 10 insertions, 0 deletions
diff --git a/t/ b/t/
index 0037f63..27bfba5 100755
--- a/t/
+++ b/t/
@@ -189,6 +189,16 @@ test_expect_success 'git archive --format=zip with --output' \
'git archive --format=zip HEAD &&
+test_expect_success 'git archive with --output, inferring format' '
+ git archive HEAD &&
+ test_cmp
+test_expect_success 'git archive with --output, override inferred format' '
+ git archive --format=tar HEAD &&
+ test_cmp b.tar
$UNZIP -v >/dev/null 2>&1
if [ $? -eq 127 ]; then
say "Skipping ZIP tests, because unzip was not found"