mirror of
https://github.com/go-gitea/gitea.git
synced 2025-12-17 19:58:48 +01:00
Revert interface change
This commit is contained in:
parent
2b4bddf837
commit
eda63517dd
@ -220,33 +220,19 @@ func RelativePath(ownerName, repoName string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// RelativePath should be an unix style path like username/reponame.git
|
// RelativePath should be an unix style path like username/reponame.git
|
||||||
func (repo *Repository) GetRelativePath() string {
|
func (repo *Repository) RelativePath() string {
|
||||||
return RelativePath(repo.OwnerName, repo.Name)
|
return RelativePath(repo.OwnerName, repo.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repo *Repository) GetDefaultBranch() string {
|
type StorageRepo string
|
||||||
return repo.DefaultBranch
|
|
||||||
}
|
|
||||||
|
|
||||||
type StorageRepo struct {
|
|
||||||
RelativePath string
|
|
||||||
DefaultBranch string
|
|
||||||
}
|
|
||||||
|
|
||||||
// RelativePath should be an unix style path like username/reponame.git
|
// RelativePath should be an unix style path like username/reponame.git
|
||||||
func (sr StorageRepo) GetRelativePath() string {
|
func (sr StorageRepo) RelativePath() string {
|
||||||
return sr.RelativePath
|
return string(sr)
|
||||||
}
|
|
||||||
|
|
||||||
func (sr StorageRepo) GetDefaultBranch() string {
|
|
||||||
return sr.DefaultBranch
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repo *Repository) WikiStorageRepo() StorageRepo {
|
func (repo *Repository) WikiStorageRepo() StorageRepo {
|
||||||
return StorageRepo{
|
return StorageRepo(strings.ToLower(repo.OwnerName) + "/" + strings.ToLower(repo.Name) + ".wiki.git")
|
||||||
RelativePath: strings.ToLower(repo.OwnerName) + "/" + strings.ToLower(repo.Name) + ".wiki.git",
|
|
||||||
DefaultBranch: repo.DefaultWikiBranch,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SanitizedOriginalURL returns a sanitized OriginalURL
|
// SanitizedOriginalURL returns a sanitized OriginalURL
|
||||||
|
|||||||
@ -32,9 +32,9 @@ func GetBranchCommitID(ctx context.Context, repo Repository, branch string) (str
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SetDefaultBranch sets default branch of repository.
|
// SetDefaultBranch sets default branch of repository.
|
||||||
func SetDefaultBranch(ctx context.Context, repo Repository) error {
|
func SetDefaultBranch(ctx context.Context, repo Repository, defaultBranch string) error {
|
||||||
_, _, err := git.NewCommand("symbolic-ref", "HEAD").
|
_, _, err := git.NewCommand("symbolic-ref", "HEAD").
|
||||||
AddDynamicArguments(git.BranchPrefix+repo.GetDefaultBranch()).
|
AddDynamicArguments(git.BranchPrefix+defaultBranch).
|
||||||
RunStdString(ctx, &git.RunOpts{Dir: repoPath(repo)})
|
RunStdString(ctx, &git.RunOpts{Dir: repoPath(repo)})
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,14 +17,13 @@ import (
|
|||||||
|
|
||||||
// Repository represents a git repository which stored in a disk
|
// Repository represents a git repository which stored in a disk
|
||||||
type Repository interface {
|
type Repository interface {
|
||||||
GetRelativePath() string // We don't assume how the directory structure of the repository is, so we only need the relative path
|
RelativePath() string // We don't assume how the directory structure of the repository is, so we only need the relative path
|
||||||
GetDefaultBranch() string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// RelativePath should be an unix style path like username/reponame.git
|
// RelativePath should be an unix style path like username/reponame.git
|
||||||
// This method should change it according to the current OS.
|
// This method should change it according to the current OS.
|
||||||
func repoPath(repo Repository) string {
|
func repoPath(repo Repository) string {
|
||||||
return filepath.Join(setting.RepoRootPath, filepath.FromSlash(repo.GetRelativePath()))
|
return filepath.Join(setting.RepoRootPath, filepath.FromSlash(repo.RelativePath()))
|
||||||
}
|
}
|
||||||
|
|
||||||
// OpenRepository opens the repository at the given relative path with the provided context.
|
// OpenRepository opens the repository at the given relative path with the provided context.
|
||||||
|
|||||||
@ -737,7 +737,7 @@ func updateBasicProperties(ctx *context.APIContext, opts api.EditRepoOption) err
|
|||||||
if opts.DefaultBranch != nil && repo.DefaultBranch != *opts.DefaultBranch && (repo.IsEmpty || gitrepo.IsBranchExist(ctx, ctx.Repo.Repository, *opts.DefaultBranch)) {
|
if opts.DefaultBranch != nil && repo.DefaultBranch != *opts.DefaultBranch && (repo.IsEmpty || gitrepo.IsBranchExist(ctx, ctx.Repo.Repository, *opts.DefaultBranch)) {
|
||||||
repo.DefaultBranch = *opts.DefaultBranch
|
repo.DefaultBranch = *opts.DefaultBranch
|
||||||
if !repo.IsEmpty {
|
if !repo.IsEmpty {
|
||||||
if err := gitrepo.SetDefaultBranch(ctx, repo); err != nil {
|
if err := gitrepo.SetDefaultBranch(ctx, repo, repo.DefaultBranch); err != nil {
|
||||||
ctx.APIErrorInternal(err)
|
ctx.APIErrorInternal(err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,7 +21,7 @@ func SetDefaultBranch(ctx *gitea_context.PrivateContext) {
|
|||||||
branch := ctx.PathParam("branch")
|
branch := ctx.PathParam("branch")
|
||||||
|
|
||||||
ctx.Repo.Repository.DefaultBranch = branch
|
ctx.Repo.Repository.DefaultBranch = branch
|
||||||
if err := gitrepo.SetDefaultBranch(ctx, ctx.Repo.Repository); err != nil {
|
if err := gitrepo.SetDefaultBranch(ctx, ctx.Repo.Repository, branch); err != nil {
|
||||||
ctx.JSON(http.StatusInternalServerError, private.Response{
|
ctx.JSON(http.StatusInternalServerError, private.Response{
|
||||||
Err: fmt.Sprintf("Unable to set default branch on repository: %s/%s Error: %v", ownerName, repoName, err),
|
Err: fmt.Sprintf("Unable to set default branch on repository: %s/%s Error: %v", ownerName, repoName, err),
|
||||||
})
|
})
|
||||||
|
|||||||
@ -647,7 +647,7 @@ func checkAndUpdateEmptyRepository(ctx context.Context, m *repo_model.Mirror, re
|
|||||||
m.Repo.DefaultBranch = firstName
|
m.Repo.DefaultBranch = firstName
|
||||||
}
|
}
|
||||||
// Update the git repository default branch
|
// Update the git repository default branch
|
||||||
if err := gitrepo.SetDefaultBranch(ctx, m.Repo); err != nil {
|
if err := gitrepo.SetDefaultBranch(ctx, m.Repo, m.Repo.DefaultBranch); err != nil {
|
||||||
log.Error("Failed to update default branch of underlying git repository %-v. Error: %v", m.Repo, err)
|
log.Error("Failed to update default branch of underlying git repository %-v. Error: %v", m.Repo, err)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|||||||
@ -124,14 +124,14 @@ func adoptRepository(ctx context.Context, repo *repo_model.Repository, defaultBr
|
|||||||
if len(defaultBranch) > 0 {
|
if len(defaultBranch) > 0 {
|
||||||
repo.DefaultBranch = defaultBranch
|
repo.DefaultBranch = defaultBranch
|
||||||
|
|
||||||
if err = gitrepo.SetDefaultBranch(ctx, repo); err != nil {
|
if err = gitrepo.SetDefaultBranch(ctx, repo, repo.DefaultBranch); err != nil {
|
||||||
return fmt.Errorf("setDefaultBranch: %w", err)
|
return fmt.Errorf("setDefaultBranch: %w", err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
repo.DefaultBranch, err = gitrepo.GetDefaultBranch(ctx, repo)
|
repo.DefaultBranch, err = gitrepo.GetDefaultBranch(ctx, repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
repo.DefaultBranch = setting.Repository.DefaultBranch
|
repo.DefaultBranch = setting.Repository.DefaultBranch
|
||||||
if err = gitrepo.SetDefaultBranch(ctx, repo); err != nil {
|
if err = gitrepo.SetDefaultBranch(ctx, repo, repo.DefaultBranch); err != nil {
|
||||||
return fmt.Errorf("setDefaultBranch: %w", err)
|
return fmt.Errorf("setDefaultBranch: %w", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -188,7 +188,7 @@ func adoptRepository(ctx context.Context, repo *repo_model.Repository, defaultBr
|
|||||||
repo.DefaultBranch = setting.Repository.DefaultBranch
|
repo.DefaultBranch = setting.Repository.DefaultBranch
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = gitrepo.SetDefaultBranch(ctx, repo); err != nil {
|
if err = gitrepo.SetDefaultBranch(ctx, repo, repo.DefaultBranch); err != nil {
|
||||||
return fmt.Errorf("setDefaultBranch: %w", err)
|
return fmt.Errorf("setDefaultBranch: %w", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -464,7 +464,7 @@ func RenameBranch(ctx context.Context, repo *repo_model.Repository, doer *user_m
|
|||||||
}
|
}
|
||||||
|
|
||||||
// repo's default branch has been updated in git_model.RenameBranch
|
// repo's default branch has been updated in git_model.RenameBranch
|
||||||
err2 = gitrepo.SetDefaultBranch(ctx, repo)
|
err2 = gitrepo.SetDefaultBranch(ctx, repo, repo.DefaultBranch)
|
||||||
if err2 != nil {
|
if err2 != nil {
|
||||||
return err2
|
return err2
|
||||||
}
|
}
|
||||||
@ -651,7 +651,7 @@ func SetRepoDefaultBranch(ctx context.Context, repo *repo_model.Repository, newB
|
|||||||
log.Error("CancelPreviousJobs: %v", err)
|
log.Error("CancelPreviousJobs: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return gitrepo.SetDefaultBranch(ctx, repo)
|
return gitrepo.SetDefaultBranch(ctx, repo, repo.DefaultBranch)
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@ -181,7 +181,7 @@ func initRepository(ctx context.Context, u *user_model.User, repo *repo_model.Re
|
|||||||
|
|
||||||
if len(opts.DefaultBranch) > 0 {
|
if len(opts.DefaultBranch) > 0 {
|
||||||
repo.DefaultBranch = opts.DefaultBranch
|
repo.DefaultBranch = opts.DefaultBranch
|
||||||
if err = gitrepo.SetDefaultBranch(ctx, repo); err != nil {
|
if err = gitrepo.SetDefaultBranch(ctx, repo, repo.DefaultBranch); err != nil {
|
||||||
return fmt.Errorf("setDefaultBranch: %w", err)
|
return fmt.Errorf("setDefaultBranch: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -281,7 +281,7 @@ func generateGitContent(ctx context.Context, repo, templateRepo, generateRepo *r
|
|||||||
repo.DefaultBranch = templateRepo.DefaultBranch
|
repo.DefaultBranch = templateRepo.DefaultBranch
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = gitrepo.SetDefaultBranch(ctx, repo); err != nil {
|
if err = gitrepo.SetDefaultBranch(ctx, repo, repo.DefaultBranch); err != nil {
|
||||||
return fmt.Errorf("setDefaultBranch: %w", err)
|
return fmt.Errorf("setDefaultBranch: %w", err)
|
||||||
}
|
}
|
||||||
if err = UpdateRepository(ctx, repo, false); err != nil {
|
if err = UpdateRepository(ctx, repo, false); err != nil {
|
||||||
|
|||||||
@ -278,7 +278,7 @@ func pushNewBranch(ctx context.Context, repo *repo_model.Repository, pusher *use
|
|||||||
repo.DefaultBranch = opts.RefName()
|
repo.DefaultBranch = opts.RefName()
|
||||||
repo.IsEmpty = false
|
repo.IsEmpty = false
|
||||||
if repo.DefaultBranch != setting.Repository.DefaultBranch {
|
if repo.DefaultBranch != setting.Repository.DefaultBranch {
|
||||||
if err := gitrepo.SetDefaultBranch(ctx, repo); err != nil {
|
if err := gitrepo.SetDefaultBranch(ctx, repo, repo.DefaultBranch); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -337,10 +337,8 @@ func changeRepositoryName(ctx context.Context, repo *repo_model.Repository, newR
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err = gitrepo.RenameRepository(ctx, repo,
|
if err = gitrepo.RenameRepository(ctx, repo,
|
||||||
repo_model.StorageRepo{
|
repo_model.StorageRepo(repo_model.RelativePath(repo.OwnerName, newRepoName)),
|
||||||
RelativePath: repo_model.RelativePath(repo.OwnerName, newRepoName),
|
); err != nil {
|
||||||
DefaultBranch: repo.DefaultBranch,
|
|
||||||
}); err != nil {
|
|
||||||
return fmt.Errorf("rename repository directory: %w", err)
|
return fmt.Errorf("rename repository directory: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -43,7 +43,7 @@ func InitWiki(ctx context.Context, repo *repo_model.Repository) error {
|
|||||||
return fmt.Errorf("InitRepository: %w", err)
|
return fmt.Errorf("InitRepository: %w", err)
|
||||||
} else if err = gitrepo.CreateDelegateHooks(ctx, repo.WikiStorageRepo()); err != nil {
|
} else if err = gitrepo.CreateDelegateHooks(ctx, repo.WikiStorageRepo()); err != nil {
|
||||||
return fmt.Errorf("createDelegateHooks: %w", err)
|
return fmt.Errorf("createDelegateHooks: %w", err)
|
||||||
} else if err = gitrepo.SetDefaultBranch(ctx, repo.WikiStorageRepo()); err != nil {
|
} else if err = gitrepo.SetDefaultBranch(ctx, repo.WikiStorageRepo(), repo.DefaultWikiBranch); err != nil {
|
||||||
return fmt.Errorf("unable to set default wiki branch to %q: %w", repo.DefaultWikiBranch, err)
|
return fmt.Errorf("unable to set default wiki branch to %q: %w", repo.DefaultWikiBranch, err)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user