forked from forgejo/forgejo
Delete old git.NewCommand() and use it as git.NewCommandContext() (#18552)
This commit is contained in:
parent
8ae5e6d7fd
commit
3043eb36bf
74 changed files with 258 additions and 263 deletions
|
@ -24,7 +24,7 @@ const PullRequestPrefix = "refs/for/"
|
|||
|
||||
// IsReferenceExist returns true if given reference exists in the repository.
|
||||
func IsReferenceExist(ctx context.Context, repoPath, name string) bool {
|
||||
_, err := NewCommandContext(ctx, "show-ref", "--verify", "--", name).RunInDir(repoPath)
|
||||
_, err := NewCommand(ctx, "show-ref", "--verify", "--", name).RunInDir(repoPath)
|
||||
return err == nil
|
||||
}
|
||||
|
||||
|
@ -46,7 +46,7 @@ func (repo *Repository) GetHEADBranch() (*Branch, error) {
|
|||
if repo == nil {
|
||||
return nil, fmt.Errorf("nil repo")
|
||||
}
|
||||
stdout, err := NewCommandContext(repo.Ctx, "symbolic-ref", "HEAD").RunInDir(repo.Path)
|
||||
stdout, err := NewCommand(repo.Ctx, "symbolic-ref", "HEAD").RunInDir(repo.Path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -65,13 +65,13 @@ func (repo *Repository) GetHEADBranch() (*Branch, error) {
|
|||
|
||||
// SetDefaultBranch sets default branch of repository.
|
||||
func (repo *Repository) SetDefaultBranch(name string) error {
|
||||
_, err := NewCommandContext(repo.Ctx, "symbolic-ref", "HEAD", BranchPrefix+name).RunInDir(repo.Path)
|
||||
_, err := NewCommand(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 NewCommandContext(repo.Ctx, "symbolic-ref", "HEAD").RunInDir(repo.Path)
|
||||
return NewCommand(repo.Ctx, "symbolic-ref", "HEAD").RunInDir(repo.Path)
|
||||
}
|
||||
|
||||
// GetBranch returns a branch by it's name
|
||||
|
@ -124,7 +124,7 @@ type DeleteBranchOptions struct {
|
|||
|
||||
// DeleteBranch delete a branch by name on repository.
|
||||
func (repo *Repository) DeleteBranch(name string, opts DeleteBranchOptions) error {
|
||||
cmd := NewCommandContext(repo.Ctx, "branch")
|
||||
cmd := NewCommand(repo.Ctx, "branch")
|
||||
|
||||
if opts.Force {
|
||||
cmd.AddArguments("-D")
|
||||
|
@ -140,7 +140,7 @@ func (repo *Repository) DeleteBranch(name string, opts DeleteBranchOptions) erro
|
|||
|
||||
// CreateBranch create a new branch
|
||||
func (repo *Repository) CreateBranch(branch, oldbranchOrCommit string) error {
|
||||
cmd := NewCommandContext(repo.Ctx, "branch")
|
||||
cmd := NewCommand(repo.Ctx, "branch")
|
||||
cmd.AddArguments("--", branch, oldbranchOrCommit)
|
||||
|
||||
_, err := cmd.RunInDir(repo.Path)
|
||||
|
@ -150,7 +150,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 := NewCommandContext(repo.Ctx, "remote", "add")
|
||||
cmd := NewCommand(repo.Ctx, "remote", "add")
|
||||
if fetch {
|
||||
cmd.AddArguments("-f")
|
||||
}
|
||||
|
@ -162,7 +162,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 := NewCommandContext(repo.Ctx, "remote", "rm", name).RunInDir(repo.Path)
|
||||
_, err := NewCommand(repo.Ctx, "remote", "rm", name).RunInDir(repo.Path)
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -173,6 +173,6 @@ func (branch *Branch) GetCommit() (*Commit, error) {
|
|||
|
||||
// RenameBranch rename a branch
|
||||
func (repo *Repository) RenameBranch(from, to string) error {
|
||||
_, err := NewCommandContext(repo.Ctx, "branch", "-m", from, to).RunInDir(repo.Path)
|
||||
_, err := NewCommand(repo.Ctx, "branch", "-m", from, to).RunInDir(repo.Path)
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue