diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..3903251 --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,36 @@ +version: 2 +jobs: + build: + docker: + - image: golang:1.10 + working_directory: /go/src/github.com/akupila/gitprompt + steps: + - checkout + + - run: + name: Install gometalinter + command: | + go get github.com/alecthomas/gometalinter + gometalinter --install + + - run: + name: Run gometalinter + environment: + CGO_ENABLED: 0 + command: | + gometalinter ./... + + - run: + name: Test + command: | + git --version + git config --global user.email "test@test.com" + git config --global user.name "Test" + go test ./... -cover + + - run: + name: Build + environment: + CGO_ENABLED: 0 + command: | + go build -ldflags="-s -w" -o /out/gitprompt ./cmd/gitprompt diff --git a/.gometalinter.json b/.gometalinter.json new file mode 100644 index 0000000..daaedb7 --- /dev/null +++ b/.gometalinter.json @@ -0,0 +1,37 @@ +{ + "DisableAll": true, + "Enable": [ + "deadcode", + "errcheck", + "goconst", + "gocyclo", + "golint", + "gotype", + "ineffassign", + "interfacer", + "megacheck", + "misspell", + "staticcheck", + "unconvert", + "vet", + "vetshadow" + ], + "Skip": [ + "funcpb", + "state/statepb" + ], + "Exclude": [ + "/usr/local/go/src", + "/usr/local/Cellar", + "/go/src" + ], + "Deadline": "2m", + "Vendor": true, + "Cyclo": 20, + "Sort": [ + "linter", + "severity", + "path", + "line" + ] +} diff --git a/README.md b/README.md index 20cf331..3a9de7e 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,8 @@ # gitprompt +[![CircleCI](https://circleci.com/gh/akupila/gitprompt.svg?style=svg)](https://circleci.com/gh/akupila/gitprompt) +[![goreportcard](https://goreportcard.com/badge/github.com/akupila/gitprompt)](https://goreportcard.com/report/github.com/akupila/gitprompt) + gitprompt is a configurable, fast and zero-dependencies* way of getting the current git status to be displayed in the `PROMPT`. diff --git a/parser.go b/parser.go index 4561f34..f4a4546 100644 --- a/parser.go +++ b/parser.go @@ -16,7 +16,7 @@ func Parse() (*GitStatus, error) { stat, err := runGitCommand("git", "status", "--branch", "--porcelain=2") if err != nil { - if strings.HasPrefix(err.Error(), "fatal: not a git repository") { + if strings.HasPrefix(err.Error(), "fatal:") { return nil, nil } return nil, err @@ -31,7 +31,7 @@ func Parse() (*GitStatus, error) { status.Untracked++ case 'u': status.Conflicts++ - case '1': + case '1', '2': parts := strings.Split(line, " ") if parts[1][0] != '.' { status.Staged++ diff --git a/parser_test.go b/parser_test.go index a55b436..268307e 100644 --- a/parser_test.go +++ b/parser_test.go @@ -174,7 +174,7 @@ func TestParseHead(t *testing.T) { setupCommands(t, dir, ` git commit --allow-empty -m 'second' - git checkout head^ + git checkout HEAD^ `) s, _ = Parse() assertString(t, "branch", "", s.Branch) @@ -200,7 +200,7 @@ func setupTestDir(t *testing.T) (string, func()) { t.Fatalf("Create temp dir: %v", err) } - if err := os.Chdir(dir); err != nil { + if err = os.Chdir(dir); err != nil { t.Fatalf("Could not change dir: %v", err) } diff --git a/printer.go b/printer.go index 982e289..6b7c580 100644 --- a/printer.go +++ b/printer.go @@ -3,6 +3,8 @@ package gitprompt import ( "bufio" "bytes" + "io" + "log" "strconv" "strings" "unicode" @@ -258,11 +260,13 @@ func setData(g *group, s *GitStatus, ch rune) { } } -func (g *group) writeTo(b *bytes.Buffer) bool { +func (g *group) writeTo(b io.Writer) bool { if g.hasData && !g.hasValue { return false } - g.buf.WriteTo(b) + if _, err := g.buf.WriteTo(b); err != nil { + log.Panic(err) + } return true }