mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
66 lines
1.6 KiB
Go
66 lines
1.6 KiB
Go
package git
|
|
|
|
import (
|
|
"fmt"
|
|
"os/exec"
|
|
"strings"
|
|
|
|
"github.com/senorprogrammer/wtf/wtf"
|
|
)
|
|
|
|
type Client struct{}
|
|
|
|
func NewClient() *Client {
|
|
return &Client{}
|
|
}
|
|
|
|
/* -------------------- Exported Functions -------------------- */
|
|
|
|
func (client *Client) Branch() string {
|
|
arg := []string{client.gitDir(), client.workTree(), "rev-parse", "--abbrev-ref", "HEAD"}
|
|
cmd := exec.Command("git", arg...)
|
|
str := wtf.ExecuteCommand(cmd)
|
|
|
|
return str
|
|
}
|
|
|
|
func (client *Client) ChangedFiles() []string {
|
|
arg := []string{client.gitDir(), client.workTree(), "status", "--porcelain"}
|
|
cmd := exec.Command("git", arg...)
|
|
str := wtf.ExecuteCommand(cmd)
|
|
|
|
data := strings.Split(str, "\n")
|
|
|
|
return data
|
|
}
|
|
|
|
func (client *Client) Commits() []string {
|
|
numStr := fmt.Sprintf("-n %d", Config.UInt("wtf.git.commitCount", 10))
|
|
|
|
arg := []string{client.gitDir(), client.workTree(), "log", "--date=format:\"%b %d, %Y\"", numStr, "--pretty=format:\"[forestgreen]%h [white]%s [grey]%an on %cd[white]\""}
|
|
cmd := exec.Command("git", arg...)
|
|
str := wtf.ExecuteCommand(cmd)
|
|
|
|
data := strings.Split(str, "\n")
|
|
|
|
return data
|
|
}
|
|
|
|
func (client *Client) Repository() string {
|
|
arg := []string{client.gitDir(), client.workTree(), "rev-parse", "--show-toplevel"}
|
|
cmd := exec.Command("git", arg...)
|
|
str := wtf.ExecuteCommand(cmd)
|
|
|
|
return str
|
|
}
|
|
|
|
/* -------------------- Exported Functions -------------------- */
|
|
|
|
func (client *Client) gitDir() string {
|
|
return fmt.Sprintf("--git-dir=%s/.git", Config.UString("wtf.git.repository"))
|
|
}
|
|
|
|
func (client *Client) workTree() string {
|
|
return fmt.Sprintf("--work-tree=%s", Config.UString("wtf.git.repository"))
|
|
}
|