diff options
Diffstat (limited to 'modules/git/repo_branch.go')
-rw-r--r-- | modules/git/repo_branch.go | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/modules/git/repo_branch.go b/modules/git/repo_branch.go index 96f692826e..98b1bc8ae7 100644 --- a/modules/git/repo_branch.go +++ b/modules/git/repo_branch.go @@ -6,6 +6,7 @@ package git import ( + "context" "fmt" "strings" ) @@ -22,14 +23,14 @@ const PullRequestPrefix = "refs/for/" // TODO: /refs/for-review for suggest change interface // IsReferenceExist returns true if given reference exists in the repository. -func IsReferenceExist(repoPath, name string) bool { - _, err := NewCommand("show-ref", "--verify", "--", name).RunInDir(repoPath) +func IsReferenceExist(ctx context.Context, repoPath, name string) bool { + _, err := NewCommandContext(ctx, "show-ref", "--verify", "--", name).RunInDir(repoPath) return err == nil } // IsBranchExist returns true if given branch exists in the repository. -func IsBranchExist(repoPath, name string) bool { - return IsReferenceExist(repoPath, BranchPrefix+name) +func IsBranchExist(ctx context.Context, repoPath, name string) bool { + return IsReferenceExist(ctx, repoPath, BranchPrefix+name) } // Branch represents a Git branch. @@ -45,7 +46,7 @@ func (repo *Repository) GetHEADBranch() (*Branch, error) { if repo == nil { return nil, fmt.Errorf("nil repo") } - stdout, err := NewCommand("symbolic-ref", "HEAD").RunInDir(repo.Path) + stdout, err := NewCommandContext(repo.Ctx, "symbolic-ref", "HEAD").RunInDir(repo.Path) if err != nil { return nil, err } @@ -64,13 +65,13 @@ func (repo *Repository) GetHEADBranch() (*Branch, error) { // SetDefaultBranch sets default branch of repository. func (repo *Repository) SetDefaultBranch(name string) error { - _, err := NewCommand("symbolic-ref", "HEAD", BranchPrefix+name).RunInDir(repo.Path) + _, err := NewCommandContext(repo.Ctx, "symbolic-ref", "HEAD", BranchPrefix+name).RunInDir(repo.Path) return err } // GetDefaultBranch gets default branch of repository. func (repo *Repository) GetDefaultBranch() (string, error) { - return NewCommand("symbolic-ref", "HEAD").RunInDir(repo.Path) + return NewCommandContext(repo.Ctx, "symbolic-ref", "HEAD").RunInDir(repo.Path) } // GetBranch returns a branch by it's name @@ -118,7 +119,7 @@ type DeleteBranchOptions struct { // DeleteBranch delete a branch by name on repository. func (repo *Repository) DeleteBranch(name string, opts DeleteBranchOptions) error { - cmd := NewCommand("branch") + cmd := NewCommandContext(repo.Ctx, "branch") if opts.Force { cmd.AddArguments("-D") @@ -134,7 +135,7 @@ func (repo *Repository) DeleteBranch(name string, opts DeleteBranchOptions) erro // CreateBranch create a new branch func (repo *Repository) CreateBranch(branch, oldbranchOrCommit string) error { - cmd := NewCommand("branch") + cmd := NewCommandContext(repo.Ctx, "branch") cmd.AddArguments("--", branch, oldbranchOrCommit) _, err := cmd.RunInDir(repo.Path) @@ -144,7 +145,7 @@ func (repo *Repository) CreateBranch(branch, oldbranchOrCommit string) error { // AddRemote adds a new remote to repository. func (repo *Repository) AddRemote(name, url string, fetch bool) error { - cmd := NewCommand("remote", "add") + cmd := NewCommandContext(repo.Ctx, "remote", "add") if fetch { cmd.AddArguments("-f") } @@ -156,7 +157,7 @@ func (repo *Repository) AddRemote(name, url string, fetch bool) error { // RemoveRemote removes a remote from repository. func (repo *Repository) RemoveRemote(name string) error { - _, err := NewCommand("remote", "rm", name).RunInDir(repo.Path) + _, err := NewCommandContext(repo.Ctx, "remote", "rm", name).RunInDir(repo.Path) return err } @@ -167,6 +168,6 @@ func (branch *Branch) GetCommit() (*Commit, error) { // RenameBranch rename a branch func (repo *Repository) RenameBranch(from, to string) error { - _, err := NewCommand("branch", "-m", from, to).RunInDir(repo.Path) + _, err := NewCommandContext(repo.Ctx, "branch", "-m", from, to).RunInDir(repo.Path) return err } |