aboutsummaryrefslogtreecommitdiffstats
path: root/services/repository/files
diff options
context:
space:
mode:
authorJason Song <i@wolfogre.com>2022-12-27 21:12:49 +0800
committerGitHub <noreply@github.com>2022-12-27 21:12:49 +0800
commit6cf09ccab402fe84a5313e1d3e755e284ebbc845 (patch)
treeb1fad807c2a16fded8b6bda84583c421ec86230c /services/repository/files
parent90237d8abd0e6479c1464ac0f32fff6a2ce4a0b4 (diff)
downloadgitea-6cf09ccab402fe84a5313e1d3e755e284ebbc845.tar.gz
gitea-6cf09ccab402fe84a5313e1d3e755e284ebbc845.zip
Use complete SHA to create and query commit status (#22244)
Fix #13485. Co-authored-by: delvh <dev.lh@web.de> Co-authored-by: Lauris BH <lauris@nix.lv> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Diffstat (limited to 'services/repository/files')
-rw-r--r--services/repository/files/commit.go5
-rw-r--r--services/repository/files/tree.go2
2 files changed, 5 insertions, 2 deletions
diff --git a/services/repository/files/commit.go b/services/repository/files/commit.go
index c49b03d608..74f9eb868d 100644
--- a/services/repository/files/commit.go
+++ b/services/repository/files/commit.go
@@ -29,9 +29,12 @@ func CreateCommitStatus(ctx context.Context, repo *repo_model.Repository, creato
}
defer closer.Close()
- if _, err := gitRepo.GetCommit(sha); err != nil {
+ if commit, err := gitRepo.GetCommit(sha); err != nil {
gitRepo.Close()
return fmt.Errorf("GetCommit[%s]: %w", sha, err)
+ } else if len(sha) != git.SHAFullLength {
+ // use complete commit sha
+ sha = commit.ID.String()
}
gitRepo.Close()
diff --git a/services/repository/files/tree.go b/services/repository/files/tree.go
index 1aa6d0df36..f4304ea630 100644
--- a/services/repository/files/tree.go
+++ b/services/repository/files/tree.go
@@ -49,7 +49,7 @@ func GetTreeBySHA(ctx context.Context, repo *repo_model.Repository, gitRepo *git
copy(treeURL[apiURLLen:], "/git/trees/")
// 40 is the size of the sha1 hash in hexadecimal format.
- copyPos := len(treeURL) - 40
+ copyPos := len(treeURL) - git.SHAFullLength
if perPage <= 0 || perPage > setting.API.DefaultGitTreesPerPage {
perPage = setting.API.DefaultGitTreesPerPage