Skip to content

Commit

Permalink
Set up CI
Browse files Browse the repository at this point in the history
  • Loading branch information
akupila committed May 12, 2018
1 parent 95c6935 commit eeb8e4d
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 6 deletions.
36 changes: 36 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -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
37 changes: 37 additions & 0 deletions .gometalinter.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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`.

Expand Down
4 changes: 2 additions & 2 deletions parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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++
Expand Down
4 changes: 2 additions & 2 deletions parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
}

Expand Down
8 changes: 6 additions & 2 deletions printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package gitprompt
import (
"bufio"
"bytes"
"io"
"log"
"strconv"
"strings"
"unicode"
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit eeb8e4d

Please sign in to comment.