giteabot backport / giteabot (push) Skipped
release-nightly-snapcraft / build-and-publish (ubuntu-24.04) (push) Canceled after 0s
release-nightly-snapcraft / build-and-publish (ubuntu-24.04-arm) (push) Canceled after 0s
release-nightly / nightly-binary (push) Canceled after 0s
release-nightly / nightly-container (push) Canceled after 0s
Route package-level and Repository.IsReferenceExist through modules/got.ObjectExists, which probes `got cat -r` without -P. got cat resolves full/abbreviated object IDs, refs and tags but not path names, matching the commit_checker/merge_tree callers that pass commit IDs and the ref callers that pass ref names. This also removes the gogit/nogogit inconsistency where gogit rejected blob hashes and short hashes for IsReferenceExist; the got-backed path accepts them in both builds. IsObjectExist is left alone: its nogogit CatFileBatch implementation has different semantics and its only caller is marked FIXME. Verified: GOTMPDIR=/home/lotherk/.cache/gotmp go test ./modules/got ./modules/git -count=1
78 lines
2.6 KiB
Go
78 lines
2.6 KiB
Go
// Copyright 2024 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package git
|
|
|
|
import (
|
|
"context"
|
|
|
|
"gotea.dev/modules/git/gitrepo"
|
|
"gotea.dev/modules/got"
|
|
)
|
|
|
|
// GetBranchesByPath returns a branch by its path
|
|
// if limit = 0 it will not limit
|
|
func GetBranchesByPath(ctx context.Context, repo RepositoryFacade, skip, limit int) ([]string, int, error) {
|
|
gitRepo, err := OpenRepository(ctx, repo)
|
|
if err != nil {
|
|
return nil, 0, err
|
|
}
|
|
defer gitRepo.Close()
|
|
|
|
return gitRepo.GetBranchNames(ctx, skip, limit)
|
|
}
|
|
|
|
func GetBranchCommitID(ctx context.Context, repo RepositoryFacade, branch string) (string, error) {
|
|
return got.BranchCommitID(ctx, gitrepo.RepoLocalPath(repo), branch)
|
|
}
|
|
|
|
// SetDefaultBranch sets default branch of repository.
|
|
func SetDefaultBranch(ctx context.Context, repo RepositoryFacade, name string) error {
|
|
return got.SetDefaultBranch(ctx, gitrepo.RepoLocalPath(repo), name)
|
|
}
|
|
|
|
// GetDefaultBranch gets default branch of repository.
|
|
func GetDefaultBranch(ctx context.Context, repo RepositoryFacade) (string, error) {
|
|
return got.DefaultBranch(ctx, gitrepo.RepoLocalPath(repo))
|
|
}
|
|
|
|
// IsReferenceExist returns true if the given reference name or object ID exists
|
|
// in the repository. It accepts full/abbreviated object IDs, refs and tags;
|
|
// it does not resolve path names.
|
|
func IsReferenceExist(ctx context.Context, repo RepositoryFacade, name string) bool {
|
|
if name == "" {
|
|
return false
|
|
}
|
|
exists, err := got.ObjectExists(ctx, gitrepo.RepoLocalPath(repo), name)
|
|
if err != nil {
|
|
return false
|
|
}
|
|
return exists
|
|
}
|
|
|
|
// IsBranchExist returns true if given branch exists in the repository.
|
|
func IsBranchExist(ctx context.Context, repo RepositoryFacade, name string) bool {
|
|
return IsReferenceExist(ctx, repo, BranchPrefix+name)
|
|
}
|
|
|
|
// DeleteBranch delete a branch by name on repository.
|
|
//
|
|
// force is accepted for signature compatibility and ignored: got has no
|
|
// equivalent of git's "branch -d refuses unmerged", and every caller in gotea
|
|
// passes true. The deletion goes through got.DeleteBranchRef, which only ever
|
|
// touches refs/heads/<name>.
|
|
func DeleteBranch(ctx context.Context, repo RepositoryFacade, name string, force bool) error {
|
|
_ = force
|
|
return got.DeleteBranchRef(ctx, gitrepo.RepoLocalPath(repo), name)
|
|
}
|
|
|
|
// CreateBranch create a new branch
|
|
func CreateBranch(ctx context.Context, repo RepositoryFacade, branch, oldbranchOrCommit string) error {
|
|
return got.CreateBranch(ctx, gitrepo.RepoLocalPath(repo), branch, oldbranchOrCommit)
|
|
}
|
|
|
|
// RenameBranch rename a branch
|
|
func RenameBranch(ctx context.Context, repo RepositoryFacade, from, to string) error {
|
|
return got.RenameBranch(ctx, gitrepo.RepoLocalPath(repo), from, to)
|
|
}
|