Skip to content

Commit a17a960

Browse files
committed
Merge branch 'rs/maint-archive-prefix'
* rs/maint-archive-prefix: Git archive and trailing "/" in prefix
2 parents e12bfd8 + ebfbdb3 commit a17a960

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

archive.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ static int write_archive_entry(const unsigned char *sha1, const char *base,
115115

116116
strbuf_reset(&path);
117117
strbuf_grow(&path, PATH_MAX);
118+
strbuf_add(&path, args->base, args->baselen);
118119
strbuf_add(&path, base, baselen);
119120
strbuf_addstr(&path, filename);
120121
path_without_prefix = path.buf + args->baselen;
@@ -187,8 +188,8 @@ int write_archive_entries(struct archiver_args *args,
187188
git_attr_set_direction(GIT_ATTR_INDEX, &the_index);
188189
}
189190

190-
err = read_tree_recursive(args->tree, args->base, args->baselen, 0,
191-
args->pathspec, write_archive_entry, &context);
191+
err = read_tree_recursive(args->tree, "", 0, 0, args->pathspec,
192+
write_archive_entry, &context);
192193
if (err == READ_TREE_RECURSIVE)
193194
err = 0;
194195
return err;
@@ -211,7 +212,7 @@ static const struct archiver *lookup_archiver(const char *name)
211212
static void parse_pathspec_arg(const char **pathspec,
212213
struct archiver_args *ar_args)
213214
{
214-
ar_args->pathspec = get_pathspec(ar_args->base, pathspec);
215+
ar_args->pathspec = get_pathspec("", pathspec);
215216
}
216217

217218
static void parse_treeish_arg(const char **argv,

t/t5000-tar-tree.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,4 +230,16 @@ test_expect_success \
230230
'git archive --list outside of a git repo' \
231231
'GIT_DIR=some/non-existing/directory git archive --list'
232232

233+
test_expect_success 'git-archive --prefix=olde-' '
234+
git archive --prefix=olde- >h.tar HEAD &&
235+
(
236+
mkdir h &&
237+
cd h &&
238+
"$TAR" xf - <../h.tar
239+
) &&
240+
test -d h/olde-a &&
241+
test -d h/olde-a/bin &&
242+
test -f h/olde-a/bin/sh
243+
'
244+
233245
test_done

0 commit comments

Comments
 (0)