(refs #1848) Response refs which are started from specified ref string

when a exactly matched ref doesn't exist
This commit is contained in:
Naoki Takezoe
2018-01-20 04:29:49 +09:00
parent b72556c007
commit f075132878

View File

@@ -206,8 +206,21 @@ trait ApiControllerBase extends ControllerBase {
get("/api/v3/repos/:owner/:repo/git/refs/*") (referrersOnly { repository =>
val revstr = multiParams("splat").head
using(Git.open(getRepositoryDir(params("owner"), params("repo")))) { git =>
val sha = git.getRepository().findRef(revstr).getObjectId().name()
JsonFormat(ApiRef(revstr, ApiObject(sha)))
val ref = git.getRepository().findRef(revstr)
if(ref != null){
val sha = ref.getObjectId().name()
JsonFormat(ApiRef(revstr, ApiObject(sha)))
} else {
val refs = git.getRepository().getAllRefs().asScala
.collect { case (str, ref) if str.startsWith("refs/" + revstr) => ref }
JsonFormat(refs.map { ref =>
val sha = ref.getObjectId().name()
ApiRef(revstr, ApiObject(sha))
})
}
}
})