mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-10-26 08:06:15 +01:00
Fix Repository Contents Upload API for nested path (#3843)
This commit is contained in:
@@ -142,10 +142,11 @@ trait ApiRepositoryContentsControllerBase extends ControllerBase {
|
||||
val revCommit = JGitUtil.getRevCommitFromId(git, git.getRepository.resolve(branch))
|
||||
revCommit.name
|
||||
}
|
||||
val paths = multiParams("splat").head.split("/")
|
||||
val fullPath = multiParams("splat").head
|
||||
val paths = fullPath.split("/")
|
||||
val path = paths.take(paths.size - 1).toList.mkString("/")
|
||||
Using.resource(Git.open(getRepositoryDir(params("owner"), params("repository")))) { git =>
|
||||
val fileInfo = getFileInfo(git, commit, path, false)
|
||||
val fileInfo = getFileInfo(git, commit, fullPath, ignoreCase = false)
|
||||
|
||||
fileInfo match {
|
||||
case Some(f) if !data.sha.contains(f.id.getName) =>
|
||||
|
||||
@@ -183,14 +183,14 @@ class ApiIntegrationTest extends AnyFunSuite {
|
||||
.branch("main")
|
||||
.content("create")
|
||||
.message("Create content")
|
||||
.path("README.md")
|
||||
.path("test.txt")
|
||||
.commit()
|
||||
|
||||
assert(createResult.getContent.isFile == true)
|
||||
assert(createResult.getContent.isFile)
|
||||
assert(IOUtils.toString(createResult.getContent.read(), "UTF-8") == "create")
|
||||
|
||||
val content1 = repo.getFileContent("README.md")
|
||||
assert(content1.isFile == true)
|
||||
val content1 = repo.getFileContent("test.txt")
|
||||
assert(content1.isFile)
|
||||
assert(IOUtils.toString(content1.read(), "UTF-8") == "create")
|
||||
assert(content1.getSha == createResult.getContent.getSha)
|
||||
|
||||
@@ -200,14 +200,14 @@ class ApiIntegrationTest extends AnyFunSuite {
|
||||
.branch("main")
|
||||
.content("update")
|
||||
.message("Update content")
|
||||
.path("README.md")
|
||||
.path("test.txt")
|
||||
.sha(content1.getSha)
|
||||
.commit()
|
||||
|
||||
assert(updateResult.getContent.isFile == true)
|
||||
assert(updateResult.getContent.isFile)
|
||||
assert(IOUtils.toString(updateResult.getContent.read(), "UTF-8") == "update")
|
||||
|
||||
val content2 = repo.getFileContent("README.md")
|
||||
val content2 = repo.getFileContent("test.txt")
|
||||
assert(content2.isFile == true)
|
||||
assert(IOUtils.toString(content2.read(), "UTF-8") == "update")
|
||||
assert(content2.getSha == updateResult.getContent.getSha)
|
||||
|
||||
Reference in New Issue
Block a user