mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-10 15:35:59 +01:00
To have compatibility with GitHub/GitHubEnterprise
when archive downloading with sha1, even if supplied part of sha1, GH/GHE gives a filename with full(long) sha1. This patch make GitBucket to be compatible with GH/GHE behaviour. You can check that difference by following url. I upload same repo as in GitHuB to GitBucket demo site. GitHub: https://github.com/MunGell/awesome-for-beginners/archive/fc7d067.tar.gz GitBucket: http://gitbucket.herokuapp.com/root/awesome-for-beginners/archive/fc7d067.tar.gz GH returns, awesome-for-beginners-fc7d067cb13559f248bb362253ff2fa3b2617aba.tar.gz Otherwise GitBucket returns, awesome-for-beginners-fc7d067.tar.gz
This commit is contained in:
@@ -670,12 +670,14 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
||||
|
||||
private def archiveRepository(name: String, suffix: String, repository: RepositoryService.RepositoryInfo): Unit = {
|
||||
val revision = name.stripSuffix(suffix)
|
||||
|
||||
val filename = repository.name + "-" +
|
||||
(if(revision.length == 40) revision.substring(0, 10) else revision).replace('/', '-') + suffix
|
||||
|
||||
|
||||
using(Git.open(getRepositoryDir(repository.owner, repository.name))){ git =>
|
||||
val revCommit = JGitUtil.getRevCommitFromId(git, git.getRepository.resolve(revision))
|
||||
|
||||
val sha1 = git.getRepository.resolve(revision).getName()
|
||||
|
||||
val filename = repository.name + "-" +
|
||||
(if(sha1.startsWith(revision)) sha1 else revision).replace('/','-') + suffix
|
||||
|
||||
contentType = "application/octet-stream"
|
||||
response.setHeader("Content-Disposition", s"attachment; filename=${filename}")
|
||||
|
||||
Reference in New Issue
Block a user