Skip to content

Commit

Permalink
use go-git for commits
Browse files Browse the repository at this point in the history
  • Loading branch information
jesseduffield committed Aug 9, 2018
1 parent bebe94b commit 4832d36
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
16 changes: 15 additions & 1 deletion gitcommands.go
Expand Up @@ -14,6 +14,8 @@ import (
"github.com/fatih/color"
"github.com/jesseduffield/gocui"
gitconfig "github.com/tcnksm/go-gitconfig"
git "gopkg.in/src-d/go-git.v4"
"gopkg.in/src-d/go-git.v4/plumbing/object"
)

var (
Expand Down Expand Up @@ -455,7 +457,19 @@ func gitCommit(g *gocui.Gui, message string) (string, error) {
runSubProcess(g, "bash", "-c", "git commit -m \""+message+"\"")
return "", nil
}
return runDirectCommand("git commit -m \"" + message + "\"")
userName, _ := gitconfig.Global("user.name")
userEmail, _ := gitconfig.Global("user.email")
_, err := w.Commit(message, &git.CommitOptions{
Author: &object.Signature{
Name: userName,
Email: userEmail,
When: time.Now(),
},
})
if err != nil {
return err.Error(), err
}
return "", nil
}

func gitPull() (string, error) {
Expand Down
16 changes: 16 additions & 0 deletions main.go
Expand Up @@ -14,6 +14,7 @@ import (

"github.com/fatih/color"
"github.com/jesseduffield/gocui"
git "gopkg.in/src-d/go-git.v4"
)

// ErrSubProcess is raised when we are running a subprocess
Expand All @@ -28,6 +29,8 @@ var (
date string
debuggingFlag = flag.Bool("debug", false, "a boolean")
versionFlag = flag.Bool("v", false, "Print the current version")

w *git.Worktree
)

func homeDirectory() string {
Expand Down Expand Up @@ -88,6 +91,18 @@ func fallbackVersion() string {
return string(byteVersion)
}

func setupWorktree() {
r, err := git.PlainOpen(".")
if err != nil {
panic(err)
}

w, err = r.Worktree()
if err != nil {
panic(err)
}
}

func main() {
startTime = time.Now()
devLog("\n\n\n\n\n\n\n\n\n\n")
Expand All @@ -101,6 +116,7 @@ func main() {
}
verifyInGitRepo()
navigateToRepoRootDirectory()
setupWorktree()
for {
if err := run(); err != nil {
if err == gocui.ErrQuit {
Expand Down

0 comments on commit 4832d36

Please sign in to comment.