mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-10-27 08:36:17 +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))
|
val revCommit = JGitUtil.getRevCommitFromId(git, git.getRepository.resolve(branch))
|
||||||
revCommit.name
|
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("/")
|
val path = paths.take(paths.size - 1).toList.mkString("/")
|
||||||
Using.resource(Git.open(getRepositoryDir(params("owner"), params("repository")))) { git =>
|
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 {
|
fileInfo match {
|
||||||
case Some(f) if !data.sha.contains(f.id.getName) =>
|
case Some(f) if !data.sha.contains(f.id.getName) =>
|
||||||
|
|||||||
@@ -183,14 +183,14 @@ class ApiIntegrationTest extends AnyFunSuite {
|
|||||||
.branch("main")
|
.branch("main")
|
||||||
.content("create")
|
.content("create")
|
||||||
.message("Create content")
|
.message("Create content")
|
||||||
.path("README.md")
|
.path("test.txt")
|
||||||
.commit()
|
.commit()
|
||||||
|
|
||||||
assert(createResult.getContent.isFile == true)
|
assert(createResult.getContent.isFile)
|
||||||
assert(IOUtils.toString(createResult.getContent.read(), "UTF-8") == "create")
|
assert(IOUtils.toString(createResult.getContent.read(), "UTF-8") == "create")
|
||||||
|
|
||||||
val content1 = repo.getFileContent("README.md")
|
val content1 = repo.getFileContent("test.txt")
|
||||||
assert(content1.isFile == true)
|
assert(content1.isFile)
|
||||||
assert(IOUtils.toString(content1.read(), "UTF-8") == "create")
|
assert(IOUtils.toString(content1.read(), "UTF-8") == "create")
|
||||||
assert(content1.getSha == createResult.getContent.getSha)
|
assert(content1.getSha == createResult.getContent.getSha)
|
||||||
|
|
||||||
@@ -200,14 +200,14 @@ class ApiIntegrationTest extends AnyFunSuite {
|
|||||||
.branch("main")
|
.branch("main")
|
||||||
.content("update")
|
.content("update")
|
||||||
.message("Update content")
|
.message("Update content")
|
||||||
.path("README.md")
|
.path("test.txt")
|
||||||
.sha(content1.getSha)
|
.sha(content1.getSha)
|
||||||
.commit()
|
.commit()
|
||||||
|
|
||||||
assert(updateResult.getContent.isFile == true)
|
assert(updateResult.getContent.isFile)
|
||||||
assert(IOUtils.toString(updateResult.getContent.read(), "UTF-8") == "update")
|
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(content2.isFile == true)
|
||||||
assert(IOUtils.toString(content2.read(), "UTF-8") == "update")
|
assert(IOUtils.toString(content2.read(), "UTF-8") == "update")
|
||||||
assert(content2.getSha == updateResult.getContent.getSha)
|
assert(content2.getSha == updateResult.getContent.getSha)
|
||||||
|
|||||||
Reference in New Issue
Block a user