mirror of
https://github.com/git/git.git
synced 2024-11-19 03:23:56 +01:00
Fix archive format with -- on the command line
Giving --format from the command line, or using output file extention to DWIM the output format, with a pathspec that is disambiguated with an explicit double-dash on the command line, e.g. git archive -o file --format=zip HEAD -- path git archive -o file.zip HEAD -- path didn't work correctly. This was because the code reordered (when one was given) or added (when the format was inferred) a --format argument at the end, effectively making it to "archive HEAD -- path --format=zip", i.e. an extra pathspec that is unlikely to match anything. The command line argument list should always be "options, revs and then paths", and we should set a good example by inserting the --format at the beginning instead. Reported-by: Ilari Liusvaara <ilari.liusvaara@elisanet.fi> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
1456b043fc
commit
782a0005fc
@ -106,13 +106,17 @@ int cmd_archive(int argc, const char **argv, const char *prefix)
|
||||
if (format) {
|
||||
sprintf(fmt_opt, "--format=%s", format);
|
||||
/*
|
||||
* This is safe because either --format and/or --output must
|
||||
* have been given on the original command line if we get to
|
||||
* this point, and parse_options() must have eaten at least
|
||||
* one argument, i.e. we have enough room to append to argv[].
|
||||
* We have enough room in argv[] to muck it in place,
|
||||
* because either --format and/or --output must have
|
||||
* been given on the original command line if we get
|
||||
* to this point, and parse_options() must have eaten
|
||||
* it, i.e. we can add back one element to the array.
|
||||
* But argv[] may contain "--"; we should make it the
|
||||
* first option.
|
||||
*/
|
||||
argv[argc++] = fmt_opt;
|
||||
argv[argc] = NULL;
|
||||
memmove(argv + 2, argv + 1, sizeof(*argv) * argc);
|
||||
argv[1] = fmt_opt;
|
||||
argv[++argc] = NULL;
|
||||
}
|
||||
|
||||
if (remote)
|
||||
|
Loading…
Reference in New Issue
Block a user