Do not show 500 error when default branch doesn't exist (#34096) (#34097)

Backport #34096
This commit is contained in:
wxiaoguang authored and GitHub committed 2025-04-02 18:16:41 +08:00
1 parent 25e409e025
commit 8f75f61b64
6 files changed
+49 -4

No files matched your search

+12
View File
@@ -173,6 +173,18 @@ func GetBranch(ctx context.Context, repoID int64, branchName string) (*Branch, e
return &branch, nil
}
// IsBranchExist returns true if the branch exists in the repository.
func IsBranchExist(ctx context.Context, repoID int64, branchName string) (bool, error) {
var branch Branch
has, err := db.GetEngine(ctx).Where("repo_id=?", repoID).And("name=?", branchName).Get(&branch)
if err != nil {
return false, err
} else if !has {
return false, nil
}
return !branch.IsDeleted, nil
}
func GetBranches(ctx context.Context, repoID int64, branchNames []string, includeDeleted bool) ([]*Branch, error) {
branches := make([]*Branch, 0, len(branchNames))