From: Dominik Maier <dmnk@google.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>,
"Patrick Steinhardt" <ps@pks.im>, "Johannes Sixt" <j6t@kdbg.org>,
"Jean-Noël Avila" <jn.avila@free.fr>,
dmnk+artist@google.com, "Dominik Maier" <dmnk@google.com>
Subject: [PATCH] archive: reject remote --add-file in callback
Date: Thu, 19 Nov 2026 20:23:11 +0100 [thread overview]
Message-ID: <20261119192311.2685319-1-dmnk@google.com> (raw)
parse_archive_args() only checks "is_remote && args->extra_files.nr"
after parse_options() returns. When git-upload-archive parses client
arguments, add_file_cb() runs first and calls stat() on the requested
path on the server filesystem, reporting "File not found" or "Not a
regular file" before the "--remote" incompatibility check is reached
(and succeeding altogether if "--no-add-file" follows).
Pass is_remote into add_file_cb() and reject "--add-file" and
"--add-virtual-file" immediately before touching the filesystem.
Signed-off-by: Dominik Maier <dmnk@google.com>
---
archive.c | 31 ++++++++++++++++++++++---------
t/t5000-tar-tree.sh | 9 +++++++++
2 files changed, 31 insertions(+), 9 deletions(-)
diff --git a/archive.c b/archive.c
index 59790be986..b983209ce4 100644
--- a/archive.c
+++ b/archive.c
@@ -559,15 +559,27 @@ static void extra_file_info_clear(void *util, const char *str UNUSED)
free(info);
}
+struct add_file_data {
+ struct archiver_args *args;
+ const char **basep;
+ int is_remote;
+};
+
static int add_file_cb(const struct option *opt, const char *arg, int unset)
{
- struct archiver_args *args = opt->value;
- const char **basep = (const char **)opt->defval;
- const char *base = *basep;
+ struct add_file_data *data = opt->value;
+ struct archiver_args *args = data->args;
+ const char *base = *data->basep;
char *path;
struct string_list_item *item;
struct extra_file_info *info;
+ if (data->is_remote)
+ die(_("options '%s' and '%s' cannot be used together"),
+ !strcmp(opt->long_name, "add-virtual-file") ?
+ "--add-virtual-file" : "--add-file",
+ "--remote");
+
if (unset) {
string_list_clear_func(&args->extra_files,
extra_file_info_clear);
@@ -645,6 +657,11 @@ static int parse_archive_args(int argc, const char **argv,
int i;
int list = 0;
int worktree_attributes = 0;
+ struct add_file_data add_file_data = {
+ .args = args,
+ .basep = &base,
+ .is_remote = is_remote,
+ };
struct option opts[] = {
OPT_GROUP(""),
OPT_STRING(0, "format", &format, N_("fmt"), N_("archive format")),
@@ -653,20 +670,18 @@ static int parse_archive_args(int argc, const char **argv,
{
.type = OPTION_CALLBACK,
.long_name = "add-file",
- .value = args,
+ .value = &add_file_data,
.argh = N_("file"),
.help = N_("add untracked file to archive"),
.callback = add_file_cb,
- .defval = (intptr_t) &base,
},
{
.type = OPTION_CALLBACK,
.long_name = "add-virtual-file",
- .value = args,
+ .value = &add_file_data,
.argh = N_("path:content"),
.help = N_("add untracked file to archive"),
.callback = add_file_cb,
- .defval = (intptr_t) &base,
},
OPT_STRING('o', "output", &output, N_("file"),
N_("write the archive to this file")),
@@ -702,8 +717,6 @@ static int parse_archive_args(int argc, const char **argv,
die(_("the option '%s' requires '%s'"), "--exec", "--remote");
if (output)
die(_("Unexpected option --output"));
- if (is_remote && args->extra_files.nr)
- die(_("options '%s' and '%s' cannot be used together"), "--add-file", "--remote");
if (!base)
base = "";
diff --git a/t/t5000-tar-tree.sh b/t/t5000-tar-tree.sh
index 3ad600c793..930a9fcb29 100755
--- a/t/t5000-tar-tree.sh
+++ b/t/t5000-tar-tree.sh
@@ -237,6 +237,15 @@ check_tar with_untracked2
check_added with_untracked2 untracked one/untracked
check_added with_untracked2 untracked two/untracked
+test_expect_success 'git archive --remote rejects --add-file before stat' '
+ test_must_fail git archive --remote=. --add-file=no-such-file HEAD 2>err &&
+ test_grep "cannot be used together" err &&
+ test_grep ! "File not found" err &&
+ echo untracked >untracked &&
+ test_must_fail git archive --remote=. --add-file=untracked --no-add-file HEAD 2>err &&
+ test_grep "cannot be used together" err
+'
+
test_expect_success 'git archive on large files' '
test_config core.bigfilethreshold 1 &&
git archive HEAD >b3.tar &&
--
2.56.1.750.gf70dc682cf-goog
reply other threads:[~2026-11-19 19:23 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261119192311.2685319-1-dmnk@google.com \
--to=dmnk@google.com \
--cc=dmnk+artist@google.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=j6t@kdbg.org \
--cc=jn.avila@free.fr \
--cc=ps@pks.im \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox