Skip to content

Commit eb0224c

Browse files
committed
archive: read local configuration
Since b9605bc ("config: only read .git/config from configured repos", 2016-09-12), we do not read from ".git/config" unless we know we are in a repository. "git archive" however didn't do the repository discovery and instead relied on the old behaviour. Teach the command to run a "gentle" version of repository discovery so that local configuration variables are honoured. [jc: stole tests from peff] Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3f0ec06 commit eb0224c

File tree

6 files changed

+40
-15
lines changed

6 files changed

+40
-15
lines changed

Diff for: archive.c

+2-6
Original file line numberDiff line numberDiff line change
@@ -504,23 +504,19 @@ static int parse_archive_args(int argc, const char **argv,
504504
}
505505

506506
int write_archive(int argc, const char **argv, const char *prefix,
507-
int setup_prefix, const char *name_hint, int remote)
507+
const char *name_hint, int remote)
508508
{
509-
int nongit = 0;
510509
const struct archiver *ar = NULL;
511510
struct archiver_args args;
512511

513-
if (setup_prefix && prefix == NULL)
514-
prefix = setup_git_directory_gently(&nongit);
515-
516512
git_config_get_bool("uploadarchive.allowunreachable", &remote_allow_unreachable);
517513
git_config(git_default_config, NULL);
518514

519515
init_tar_archiver();
520516
init_zip_archiver();
521517

522518
argc = parse_archive_args(argc, argv, &ar, &args, name_hint, remote);
523-
if (nongit) {
519+
if (!startup_info->have_repository) {
524520
/*
525521
* We know this will die() with an error, so we could just
526522
* die ourselves; but its error message will be more specific

Diff for: archive.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ typedef int (*write_archive_entry_fn_t)(struct archiver_args *args,
3636
unsigned int mode);
3737

3838
extern int write_archive_entries(struct archiver_args *args, write_archive_entry_fn_t write_entry);
39-
extern int write_archive(int argc, const char **argv, const char *prefix, int setup_prefix, const char *name_hint, int remote);
39+
extern int write_archive(int argc, const char **argv, const char *prefix, const char *name_hint, int remote);
4040

4141
const char *archive_format_from_filename(const char *filename);
4242
extern void *sha1_file_to_archive(const struct archiver_args *args,

Diff for: builtin/archive.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ int cmd_archive(int argc, const char **argv, const char *prefix)
8585
const char *output = NULL;
8686
const char *remote = NULL;
8787
struct option local_opts[] = {
88-
OPT_STRING('o', "output", &output, N_("file"),
89-
N_("write the archive to this file")),
88+
OPT_FILENAME('o', "output", &output,
89+
N_("write the archive to this file")),
9090
OPT_STRING(0, "remote", &remote, N_("repo"),
9191
N_("retrieve the archive from remote repository <repo>")),
9292
OPT_STRING(0, "exec", &exec, N_("command"),
@@ -105,5 +105,5 @@ int cmd_archive(int argc, const char **argv, const char *prefix)
105105

106106
setvbuf(stderr, NULL, _IOLBF, BUFSIZ);
107107

108-
return write_archive(argc, argv, prefix, 1, output, 0);
108+
return write_archive(argc, argv, prefix, output, 0);
109109
}

Diff for: builtin/upload-archive.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ int cmd_upload_archive_writer(int argc, const char **argv, const char *prefix)
4343
}
4444

4545
/* parse all options sent by the client */
46-
return write_archive(sent_argv.argc, sent_argv.argv, prefix, 0, NULL, 1);
46+
return write_archive(sent_argv.argc, sent_argv.argv, prefix, NULL, 1);
4747
}
4848

4949
__attribute__((format (printf, 1, 2)))

Diff for: git.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ static struct cmd_struct commands[] = {
396396
{ "am", cmd_am, RUN_SETUP | NEED_WORK_TREE },
397397
{ "annotate", cmd_annotate, RUN_SETUP },
398398
{ "apply", cmd_apply, RUN_SETUP_GENTLY },
399-
{ "archive", cmd_archive },
399+
{ "archive", cmd_archive, RUN_SETUP_GENTLY },
400400
{ "bisect--helper", cmd_bisect__helper, RUN_SETUP },
401401
{ "blame", cmd_blame, RUN_SETUP },
402402
{ "branch", cmd_branch, RUN_SETUP },

Diff for: t/t5000-tar-tree.sh

+32-3
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,20 @@ check_tar() {
9494
'
9595
}
9696

97+
# run "$@" inside a non-git directory
98+
nongit () {
99+
test -d non-repo ||
100+
mkdir non-repo ||
101+
return 1
102+
103+
(
104+
GIT_CEILING_DIRECTORIES=$(pwd) &&
105+
export GIT_CEILING_DIRECTORIES &&
106+
cd non-repo &&
107+
"$@"
108+
)
109+
}
110+
97111
test_expect_success \
98112
'populate workdir' \
99113
'mkdir a &&
@@ -179,6 +193,15 @@ test_expect_success 'git archive --remote' \
179193
'git archive --remote=. HEAD >b5.tar &&
180194
test_cmp_bin b.tar b5.tar'
181195

196+
test_expect_success 'git archive --remote with configured remote' '
197+
git config remote.foo.url . &&
198+
(
199+
cd a &&
200+
git archive --remote=foo --output=../b5-nick.tar HEAD
201+
) &&
202+
test_cmp_bin b.tar b5-nick.tar
203+
'
204+
182205
test_expect_success \
183206
'validate file modification time' \
184207
'mkdir extract &&
@@ -197,9 +220,15 @@ test_expect_success 'git archive with --output, override inferred format' '
197220
test_cmp_bin b.tar d4.zip
198221
'
199222

200-
test_expect_success \
201-
'git archive --list outside of a git repo' \
202-
'GIT_DIR=some/non-existing/directory git archive --list'
223+
test_expect_success 'git archive --list outside of a git repo' '
224+
nongit git archive --list
225+
'
226+
227+
test_expect_success 'git archive --remote outside of a git repo' '
228+
git archive HEAD >expect.tar &&
229+
nongit git archive --remote="$PWD" HEAD >actual.tar &&
230+
test_cmp_bin expect.tar actual.tar
231+
'
203232

204233
test_expect_success 'clients cannot access unreachable commits' '
205234
test_commit unreachable &&

0 commit comments

Comments
 (0)