Skip to content

Commit bd41dd4

Browse files
committed
add context to branch commands
1 parent 00bb0b7 commit bd41dd4

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

modules/git/repo_branch.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ type Branch struct {
3434
}
3535

3636
// GetHEADBranch returns corresponding branch of HEAD.
37-
func (repo *Repository) GetHEADBranch() (*Branch, error) {
37+
func (repo *Repository) GetHEADBranch(ctx context.Context) (*Branch, error) {
3838
if repo == nil {
3939
return nil, fmt.Errorf("nil repo")
4040
}
41-
stdout, _, err := NewCommand("symbolic-ref", "HEAD").RunStdString(repo.Ctx, &RunOpts{Dir: repo.Path})
41+
stdout, _, err := NewCommand("symbolic-ref", "HEAD").RunStdString(ctx, &RunOpts{Dir: repo.Path})
4242
if err != nil {
4343
return nil, err
4444
}
@@ -104,7 +104,7 @@ type DeleteBranchOptions struct {
104104
}
105105

106106
// DeleteBranch delete a branch by name on repository.
107-
func (repo *Repository) DeleteBranch(name string, opts DeleteBranchOptions) error {
107+
func (repo *Repository) DeleteBranch(ctx context.Context, name string, opts DeleteBranchOptions) error {
108108
cmd := NewCommand("branch")
109109

110110
if opts.Force {
@@ -114,17 +114,17 @@ func (repo *Repository) DeleteBranch(name string, opts DeleteBranchOptions) erro
114114
}
115115

116116
cmd.AddDashesAndList(name)
117-
_, _, err := cmd.RunStdString(repo.Ctx, &RunOpts{Dir: repo.Path})
117+
_, _, err := cmd.RunStdString(ctx, &RunOpts{Dir: repo.Path})
118118

119119
return err
120120
}
121121

122122
// CreateBranch create a new branch
123-
func (repo *Repository) CreateBranch(branch, oldbranchOrCommit string) error {
123+
func (repo *Repository) CreateBranch(ctx context.Context, branch, oldbranchOrCommit string) error {
124124
cmd := NewCommand("branch")
125125
cmd.AddDashesAndList(branch, oldbranchOrCommit)
126126

127-
_, _, err := cmd.RunStdString(repo.Ctx, &RunOpts{Dir: repo.Path})
127+
_, _, err := cmd.RunStdString(ctx, &RunOpts{Dir: repo.Path})
128128

129129
return err
130130
}

routers/api/v1/repo/commits.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ func GetAllCommits(ctx *context.APIContext) {
180180
var baseCommit *git.Commit
181181
if len(sha) == 0 {
182182
// no sha supplied - use default branch
183-
head, err := ctx.Repo.GitRepo.GetHEADBranch()
183+
head, err := ctx.Repo.GitRepo.GetHEADBranch(ctx)
184184
if err != nil {
185185
ctx.APIErrorInternal(err)
186186
return

services/repository/branch.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ func DeleteBranch(ctx context.Context, doer *user_model.User, repo *repo_model.R
550550
}
551551
}
552552

553-
return gitRepo.DeleteBranch(branchName, git.DeleteBranchOptions{
553+
return gitRepo.DeleteBranch(ctx, branchName, git.DeleteBranchOptions{
554554
Force: true,
555555
})
556556
}); err != nil {

services/repository/migrate.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ func MigrateRepositoryGitData(ctx context.Context, u *user_model.User,
140140
if !repo.IsEmpty {
141141
if len(repo.DefaultBranch) == 0 {
142142
// Try to get HEAD branch and set it as default branch.
143-
headBranch, err := gitRepo.GetHEADBranch()
143+
headBranch, err := gitRepo.GetHEADBranch(ctx)
144144
if err != nil {
145145
return repo, fmt.Errorf("GetHEADBranch: %w", err)
146146
}

0 commit comments

Comments
 (0)