Skip to content

Commit

Permalink
feat(go-git): implement push and --force functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
sharpvik committed Jun 30, 2022
1 parent 423bc80 commit 1b6be03
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
type (
Agent struct {
Config *Config
repo *git.Repository
workTree *git.Worktree
commitTitle string
}
Expand All @@ -38,11 +39,11 @@ func New(config *Config) *Agent {
}

func (a *Agent) Init() (err error) {
repo, err := git.PlainOpen(".")
a.repo, err = git.PlainOpen(".")
if err != nil {
return
}
a.workTree, err = repo.Worktree()
a.workTree, err = a.repo.Worktree()
return
}

Expand Down Expand Up @@ -73,11 +74,9 @@ func (a *Agent) Commit() (err error) {
}

func (a *Agent) Push() (err error) {
args := []string{"push"}
if a.Config.Push.Force {
args = append(args, "-f")
}
return try(exec.Command("git", args...))
return a.repo.Push(&git.PushOptions{
Force: a.Config.Push.Force,
})
}

func (a *Agent) longCommit() (err error) {
Expand Down

0 comments on commit 1b6be03

Please sign in to comment.