diff options
author | Jason Song <i@wolfogre.com> | 2022-12-28 18:03:21 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-28 11:03:21 +0100 |
commit | e9bc2c77c35d078c5ba5e6107c3551f31410c936 (patch) | |
tree | 8c0b771a9efe60101fd5520db7403ed9c59e2f31 /services/repository | |
parent | 9b4da56963692819d236b07504e565d4b4fb4021 (diff) | |
download | gitea-e9bc2c77c35d078c5ba5e6107c3551f31410c936.tar.gz gitea-e9bc2c77c35d078c5ba5e6107c3551f31410c936.zip |
Use complete SHA to create and query commit status (#22244) (#22257)
Backport #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>
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')
-rw-r--r-- | services/repository/files/commit.go | 5 | ||||
-rw-r--r-- | services/repository/files/tree.go | 2 |
2 files changed, 5 insertions, 2 deletions
diff --git a/services/repository/files/commit.go b/services/repository/files/commit.go index bc5a4c8ed3..72e2279ae5 100644 --- a/services/repository/files/commit.go +++ b/services/repository/files/commit.go @@ -30,9 +30,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 59e5690977..513b8a2274 100644 --- a/services/repository/files/tree.go +++ b/services/repository/files/tree.go @@ -50,7 +50,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 |