+
Skip to content

archive: make --add-virtual-file honor --prefix #1719

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions archive.c
Original file line number Diff line number Diff line change
Expand Up @@ -365,12 +365,11 @@ int write_archive_entries(struct archiver_args *args,

put_be64(fake_oid.hash, i + 1);

strbuf_reset(&path_in_archive);
if (info->base)
strbuf_addstr(&path_in_archive, info->base);
if (!info->content) {
strbuf_reset(&path_in_archive);
if (info->base)
strbuf_addstr(&path_in_archive, info->base);
strbuf_addstr(&path_in_archive, basename(path));

strbuf_reset(&content);
if (strbuf_read_file(&content, path, info->stat.st_size) < 0)
err = error_errno(_("cannot read '%s'"), path);
Expand All @@ -380,8 +379,9 @@ int write_archive_entries(struct archiver_args *args,
canon_mode(info->stat.st_mode),
content.buf, content.len);
} else {
strbuf_addstr(&path_in_archive, path);
err = write_entry(args, &fake_oid,
path, strlen(path),
path_in_archive.buf, path_in_archive.len,
canon_mode(info->stat.st_mode),
info->content, info->stat.st_size);
}
Expand Down
14 changes: 12 additions & 2 deletions t/t5003-archive-zip.sh
Original file line number Diff line number Diff line change
Expand Up @@ -218,14 +218,24 @@ test_expect_success UNZIP 'git archive --format=zip --add-virtual-file' '
fi &&
git archive --format=zip >with_file_with_content.zip \
--add-virtual-file=\""$PATHNAME"\": \
--add-virtual-file=hello:world $EMPTY_TREE &&
--add-virtual-file=hello:world \
--add-virtual-file=with/dir/noprefix:withdirnopre \
--prefix=subdir/ --add-virtual-file=with/dirprefix:withdirprefix \
--prefix=subdir2/ --add-virtual-file=withoutdir:withoutdir \
--prefix= $EMPTY_TREE &&
test_when_finished "rm -rf tmp-unpack" &&
mkdir tmp-unpack && (
cd tmp-unpack &&
"$GIT_UNZIP" ../with_file_with_content.zip &&
test_path_is_file hello &&
test_path_is_file "$PATHNAME" &&
test world = $(cat hello)
test world = $(cat hello) &&
test_path_is_file with/dir/noprefix &&
test withdirnopre = $(cat with/dir/noprefix) &&
test_path_is_file subdir/with/dirprefix &&
test withdirprefix = $(cat subdir/with/dirprefix) &&
test_path_is_file subdir2/withoutdir &&
test withoutdir = $(cat subdir2/withoutdir)
)
'

Expand Down
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载