Git archive and trailing "/" in prefix
With --prefix=string that does not end with a slash, the top-level entries are written out with the specified prefix as expected, but no paths in the directories are added. Fix this by adding the prefix in write_archive_entry() instead of letting get_pathspec() and read_tree_recursive() pair; they are designed to only handle prefixes that are path components. Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>
René Scharfe committed
Oct 8, 2009 at 18:46 UTC
ebfbdb340ad9a1b6fbaf91464f0fd86643fdcb46
2 files changed
+16
-3
archive.c
+4
-3
@@ -115,6 +115,7 @@ static int write_archive_entry(const unsigned char *sha1, const char *base,
115
116
strbuf_reset(&path);
117
strbuf_grow(&path, PATH_MAX);
118
+ strbuf_add(&path, args->base, args->baselen);
119
strbuf_add(&path, base, baselen);
120
strbuf_addstr(&path, filename);
121
path_without_prefix = path.buf + args->baselen;
@@ -187,8 +188,8 @@ int write_archive_entries(struct archiver_args *args,
188
git_attr_set_direction(GIT_ATTR_INDEX, &the_index);
189
}
190
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);
193
if (err == READ_TREE_RECURSIVE)
194
err = 0;
195
return err;
@@ -211,7 +212,7 @@ static const struct archiver *lookup_archiver(const char *name)
212
static void parse_pathspec_arg(const char **pathspec,
213
struct archiver_args *ar_args)
214
{
214
- ar_args->pathspec = get_pathspec(ar_args->base, pathspec);
215
+ ar_args->pathspec = get_pathspec("", pathspec);
216
}
217
218
static void parse_treeish_arg(const char **argv,
t/t5000-tar-tree.sh
+12
@@ -230,4 +230,16 @@ test_expect_success \
230
'git archive --list outside of a git repo' \
231
'GIT_DIR=some/non-existing/directory git archive --list'
232
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
+
245
test_done