mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-31 21:28:11 +09:00 
			
		
		
		
	Move get/set default branch from git package to gitrepo package to hide repopath (#29126)
This commit is contained in:
		| @@ -55,15 +55,8 @@ func (repo *Repository) GetHEADBranch() (*Branch, error) { | ||||
| 	}, nil | ||||
| } | ||||
|  | ||||
| // SetDefaultBranch sets default branch of repository. | ||||
| func (repo *Repository) SetDefaultBranch(name string) error { | ||||
| 	_, _, err := NewCommand(repo.Ctx, "symbolic-ref", "HEAD").AddDynamicArguments(BranchPrefix + name).RunStdString(&RunOpts{Dir: repo.Path}) | ||||
| 	return err | ||||
| } | ||||
|  | ||||
| // GetDefaultBranch gets default branch of repository. | ||||
| func (repo *Repository) GetDefaultBranch() (string, error) { | ||||
| 	stdout, _, err := NewCommand(repo.Ctx, "symbolic-ref", "HEAD").RunStdString(&RunOpts{Dir: repo.Path}) | ||||
| func GetDefaultBranch(ctx context.Context, repoPath string) (string, error) { | ||||
| 	stdout, _, err := NewCommand(ctx, "symbolic-ref", "HEAD").RunStdString(&RunOpts{Dir: repoPath}) | ||||
| 	if err != nil { | ||||
| 		return "", err | ||||
| 	} | ||||
|   | ||||
| @@ -30,3 +30,20 @@ func GetBranchCommitID(ctx context.Context, repo Repository, branch string) (str | ||||
|  | ||||
| 	return gitRepo.GetBranchCommitID(branch) | ||||
| } | ||||
|  | ||||
| // SetDefaultBranch sets default branch of repository. | ||||
| func SetDefaultBranch(ctx context.Context, repo Repository, name string) error { | ||||
| 	_, _, err := git.NewCommand(ctx, "symbolic-ref", "HEAD"). | ||||
| 		AddDynamicArguments(git.BranchPrefix + name). | ||||
| 		RunStdString(&git.RunOpts{Dir: repoPath(repo)}) | ||||
| 	return err | ||||
| } | ||||
|  | ||||
| // GetDefaultBranch gets default branch of repository. | ||||
| func GetDefaultBranch(ctx context.Context, repo Repository) (string, error) { | ||||
| 	return git.GetDefaultBranch(ctx, repoPath(repo)) | ||||
| } | ||||
|  | ||||
| func GetWikiDefaultBranch(ctx context.Context, repo Repository) (string, error) { | ||||
| 	return git.GetDefaultBranch(ctx, wikiPath(repo)) | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user