Ignore submodules in repository archive downloading (#2817)

This commit is contained in:
Naoki Takezoe
2021-07-11 16:55:44 +09:00
committed by GitHub
parent 897cc5eea4
commit 6a1da37e9a

View File

@@ -1223,34 +1223,37 @@ trait RepositoryViewerControllerBase extends ControllerBase {
}
if (treeWalk != null) {
while (treeWalk.next()) {
val entryPath =
if (path.isEmpty) baseName + "/" + treeWalk.getPathString
else path.split("/").last + treeWalk.getPathString.substring(path.length)
val mode = treeWalk.getFileMode.getBits
JGitUtil.openFile(git, repository, commit.getTree, treeWalk.getPathString) { in =>
val tempFile = File.createTempFile("gitbucket", ".archive")
val size = Using.resource(new FileOutputStream(tempFile)) { out =>
IOUtils.copy(
EolStreamTypeUtil.wrapInputStream(
in,
EolStreamTypeUtil
.detectStreamType(
OperationType.CHECKOUT_OP,
git.getRepository.getConfig.get(WorkingTreeOptions.KEY),
treeWalk.getAttributes
)
),
out
)
}
if (treeWalk.getFileMode != FileMode.GITLINK) {
val entryPath =
if (path.isEmpty) baseName + "/" + treeWalk.getPathString
else path.split("/").last + treeWalk.getPathString.substring(path.length)
val mode = treeWalk.getFileMode.getBits
val entry: ArchiveEntry = entryCreator(entryPath, size, date, mode)
archive.putArchiveEntry(entry)
Using.resource(new FileInputStream(tempFile)) { in =>
IOUtils.copy(in, archive)
JGitUtil.openFile(git, repository, commit.getTree, treeWalk.getPathString) { in =>
val tempFile = File.createTempFile("gitbucket", ".archive")
val size = Using.resource(new FileOutputStream(tempFile)) { out =>
IOUtils.copy(
EolStreamTypeUtil.wrapInputStream(
in,
EolStreamTypeUtil
.detectStreamType(
OperationType.CHECKOUT_OP,
git.getRepository.getConfig.get(WorkingTreeOptions.KEY),
treeWalk.getAttributes
)
),
out
)
}
val entry: ArchiveEntry = entryCreator(entryPath, size, date, mode)
archive.putArchiveEntry(entry)
Using.resource(new FileInputStream(tempFile)) { in =>
IOUtils.copy(in, archive)
}
archive.closeArchiveEntry()
tempFile.delete()
}
archive.closeArchiveEntry()
tempFile.delete()
}
}
}