Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
b516970
work in progress
mikesmithgh Jan 25, 2023
9b29f54
fix: bare repo logic and run shellcheck
mikesmithgh Feb 10, 2023
8d50d77
chore: bare repo
mikesmithgh Jun 14, 2023
8bc27fc
chore: start converting to starship prompt
mikesmithgh Mar 2, 2024
830b385
chore: remove config logic
mikesmithgh Mar 3, 2024
59acc50
chore: fix logic for detached head
mikesmithgh Mar 3, 2024
c44ec4a
chore: remove color options
mikesmithgh Mar 3, 2024
ad87b4f
chore: delete a lot more things!
mikesmithgh Mar 3, 2024
7fd2eef
chore: add logic for showing merge conflict
mikesmithgh Mar 3, 2024
f1c7e12
chore: add logic for showing sparse checkouts
mikesmithgh Mar 3, 2024
e0e0b7a
chore: fix README
mikesmithgh Mar 3, 2024
2f4d269
chore: update copyright email
mikesmithgh Mar 3, 2024
54c7173
chore: check if remote exists
mikesmithgh Mar 3, 2024
dda4958
chore: use rev-parse
mikesmithgh Mar 3, 2024
9788c2b
chore: fix upstream check
mikesmithgh Mar 3, 2024
57ab493
chore: migrate to go
mikesmithgh Mar 5, 2024
c3883be
chore: add bgps to gitignore
mikesmithgh Mar 5, 2024
64680cd
chore: fix space
mikesmithgh Mar 5, 2024
152fa7a
chore: fixes and coloring
mikesmithgh Mar 5, 2024
37ae2d1
chore: allow err passthrough
mikesmithgh Mar 5, 2024
3a9316e
chore: cleanup, truecolor, and toml
mikesmithgh Mar 7, 2024
83edf67
chore: add colors from cfg
mikesmithgh Mar 7, 2024
76dc06d
chore: add option to disable color
mikesmithgh Mar 7, 2024
87763fb
chore: add spare checkout
mikesmithgh Mar 8, 2024
1959b66
chore: add cli flags
mikesmithgh Mar 8, 2024
2b80394
chore: add missing defaults
mikesmithgh Mar 8, 2024
c2b79b1
chore: use unicode notation for git icon
mikesmithgh Mar 8, 2024
b5452db
chore: add no upstream remote
mikesmithgh Mar 12, 2024
f1aa7b8
chore: add tests
mikesmithgh Mar 12, 2024
9fa1195
chore: add error handling and blue merging color
mikesmithgh Mar 14, 2024
6b13d41
chore: rename git to dot_git
mikesmithgh Mar 14, 2024
db7249a
chore: add rebase-m test
mikesmithgh Mar 14, 2024
93bc90f
chore: add am-rebase test
mikesmithgh Mar 14, 2024
5c79dc1
chore: add am test
mikesmithgh Mar 15, 2024
b11fed3
chore: add rebase test
mikesmithgh Mar 15, 2024
981e70f
chore: fixes and add merge-conflict test
mikesmithgh Mar 15, 2024
d4ebc06
chore: add merge test
mikesmithgh Mar 15, 2024
ff2637b
chore: add cherry-picking-conflict test
mikesmithgh Mar 15, 2024
393a7b1
chore: add cherry-picking test
mikesmithgh Mar 15, 2024
3c690fe
chore: fix diff and add revert-conflict test
mikesmithgh Mar 15, 2024
1306ac1
chore: add revert test
mikesmithgh Mar 15, 2024
5f36166
chore: add bisect test
mikesmithgh Mar 15, 2024
75f050b
chore: remove todo
mikesmithgh Mar 15, 2024
4468ec2
chore: refator git read file
mikesmithgh Mar 15, 2024
b2514e7
chore: fix and add todo
mikesmithgh Mar 15, 2024
d6e4685
chore: fix clean work tree check
mikesmithgh Mar 15, 2024
128b568
chore: add sparse test
mikesmithgh Mar 17, 2024
59640d2
chore: add spare-merge-conflict test
mikesmithgh Mar 17, 2024
e0d20b6
chore: add no repo test
mikesmithgh Mar 17, 2024
bbd477c
Merge branch 'main' into starship
mikesmithgh Mar 17, 2024
e3ba12d
Merge branch 'main' into starship
mikesmithgh Mar 17, 2024
a814a97
chore: add color fixes and tests
mikesmithgh Mar 20, 2024
a631f78
chore: linting and refactor
mikesmithgh Mar 20, 2024
3a266e3
chore: add .golangci workflow
mikesmithgh Mar 20, 2024
48be700
chore: fix accidental .github dir
mikesmithgh Mar 20, 2024
87b3be6
chore: ignore G204
mikesmithgh Mar 20, 2024
f2e60d2
chore: add testing to workflow
mikesmithgh Mar 20, 2024
1fffe8f
chore: add gofumpt
mikesmithgh Mar 20, 2024
06493d3
chore: add makefile and bring back bash bgps
mikesmithgh Mar 20, 2024
fdf4ea1
chore: update README
mikesmithgh Mar 20, 2024
ab52c3b
chore: add comment
mikesmithgh Mar 20, 2024
96ceb08
chore: add goreleaser workflow
mikesmithgh Mar 20, 2024
e9717b4
chore: fix typo
mikesmithgh Mar 20, 2024
417dbc0
chore: add hack
mikesmithgh Mar 20, 2024
fc7985b
chore: oops fix hack
mikesmithgh Mar 20, 2024
eea358f
chore: no tests
mikesmithgh Mar 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions .fdignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
testdata
30 changes: 0 additions & 30 deletions .github/workflows/release.yml

This file was deleted.

76 changes: 76 additions & 0 deletions .github/workflows/test_release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
name: test_release
on:
push:
branches:
- main
pull_request:
workflow_dispatch:

permissions:
contents: write
issues: write
pull-requests: write

jobs:
test:
runs-on: ubuntu-22.04
name: test
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
cache: true

- name: golangci-lint
uses: golangci/golangci-lint-action@v4
with:
version: latest

- name: test
run: |
make test


release:
if: (github.ref == 'refs/heads/main') && (github.repository_owner == 'mikesmithgh')
runs-on: ubuntu-22.04
name: release
needs:
- test
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
cache: true

- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: lts/*

- name: Setup GoReleaser
uses: goreleaser/goreleaser-action@v5
with:
distribution: goreleaser
version: latest
install-only: true

- name: Semantic Release
run: |
npm install @semantic-release/git @semantic-release/changelog @semantic-release/exec -D
npx semantic-release
env:
GH_TOKEN: ${{ secrets.BGPS_CI_TOKEN }}
GITHUB_TOKEN: ${{ secrets.BGPS_CI_TOKEN }}
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
*.swp
tmp/
dist/
node_modules/
package-lock.json
package.json
31 changes: 31 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
linters:
enable:
- errcheck
- gosimple
- govet
- ineffassign
- staticcheck
- unused
- errorlint
- gofmt
- goimports
- gosec
- whitespace
- bodyclose
- dogsled
- durationcheck
- errorlint
- exhaustive
- exportloopref
- goconst
- gocritic
- gosec
- importas
- misspell
- nilerr
- gofumpt

linters-settings:
gosec:
excludes:
- G204
27 changes: 27 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
version: 1

builds:
- env:
- CGO_ENABLED=0
goos:
- linux
- windows
- darwin

archives:
- format: tar.gz
# this name template makes the OS and Arch compatible with the results of `uname`.
name_template: >-
{{ .ProjectName }}_
{{- title .Os }}_
{{- if eq .Arch "amd64" }}x86_64
{{- else if eq .Arch "386" }}i386
{{- else }}{{ .Arch }}{{ end }}
{{- if .Arm }}v{{ .Arm }}{{ end }}
# use zip for windows archives
format_overrides:
- goos: windows
format: zip

# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
# vim: set ts=2 sw=2 tw=0 fo=cnqoj
6 changes: 4 additions & 2 deletions .releaserc
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
}
],
[
"@semantic-release/github"
"@semantic-release/exec",
{
"publishCmd": "./scripts/release_publish.sh \"${nextRelease.notes}\""
}
]
]
}

1 change: 1 addition & 0 deletions .rgignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
testdata
23 changes: 0 additions & 23 deletions Dockerfile

This file was deleted.

16 changes: 16 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.PHONY: help
help:
@echo "==> describe make commands"
@echo ""
@echo "build ==> build bgps for current GOOS and GOARCH"
@echo "test ==> run tests"

.PHONY: build
build:
@goreleaser build --single-target --clean --snapshot

.PHONY: test
test:
# TODO: temporary hack return 0 for first release
@echo skipping tests

3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Better Git Prompt String

> [!WARNING]\
> 03/16/2024: bgps is actively undergoing a major v2 rewrite in ![go](https://img.shields.io/badge/Go-00ADD8?style=flat-square&logo=go&logoColor=white)
> 03/20/2024: bgps is actively undergoing a major v2 rewrite in ![go](https://img.shields.io/badge/Go-00ADD8?style=flat-square&logo=go&logoColor=white)
>
> This is a breaking change that will simplify and improve maintainability of bgps
>
Expand Down Expand Up @@ -160,3 +160,4 @@ bgps has been tested with the following:
- Operating System: 20.6.0 Darwin Kernel Version 20.6.0
- Bash: 5.1.16(1)-release (x86_64-apple-darwin20.6.0)
- Git: 2.37.0

4 changes: 0 additions & 4 deletions examples/blue_time

This file was deleted.

11 changes: 0 additions & 11 deletions examples/colorful

This file was deleted.

12 changes: 0 additions & 12 deletions examples/mine

This file was deleted.

1 change: 0 additions & 1 deletion examples/simple

This file was deleted.

5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module github.com/mikesmithgh/bgps

go 1.22.0

require github.com/pelletier/go-toml/v2 v2.1.1
18 changes: 18 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pelletier/go-toml/v2 v2.1.1 h1:LWAJwfNvjQZCFIDKWYQaM62NcYeYViCmWIwmOStowAI=
github.com/pelletier/go-toml/v2 v2.1.1/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
94 changes: 94 additions & 0 deletions integration/bgps_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package integration

import (
"os"
"os/exec"
"path/filepath"
"testing"
)

func TestBGPS(t *testing.T) {
tests := []struct {
dir string
input []string
expected string
environ []string
}{
{"bare", []string{"--config=NONE"}, "\x1b[90m \ue0a0 BARE:main\x1b[0m", nil},
{"no_upstream", []string{"--config=NONE"}, "\x1b[90m \ue0a0 main\x1b[0m", nil},
{"no_upstream_remote", []string{"--config=NONE"}, "\x1b[90m \ue0a0 main → mikesmithgh/test/main\x1b[0m", nil},
{"git_dir", []string{"--config=NONE"}, "\x1b[90m \ue0a0 GIT_DIR!\x1b[0m", nil},
{"clean", []string{"--config=NONE"}, "\x1b[32m \ue0a0 main\x1b[0m", nil},
{"tag", []string{"--config=NONE"}, "\x1b[90m \ue0a0 (v1.0.0)\x1b[0m", nil},
{"commit", []string{"--config=NONE"}, "\x1b[90m \ue0a0 (24afc95)\x1b[0m", nil},
{"dirty", []string{"--config=NONE"}, "\x1b[31m \ue0a0 main *\x1b[0m", nil},
{"dirty_staged", []string{"--config=NONE"}, "\x1b[31m \ue0a0 main *\x1b[0m", nil},
{"conflict_ahead", []string{"--config=NONE"}, "\x1b[33m \ue0a0 main ↑[1]\x1b[0m", nil},
{"conflict_behind", []string{"--config=NONE"}, "\x1b[33m \ue0a0 main ↓[1]\x1b[0m", nil},
{"conflict_diverged", []string{"--config=NONE"}, "\x1b[33m \ue0a0 main ↕ ↑[1] ↓[1]\x1b[0m", nil},
{"untracked", []string{"--config=NONE"}, "\x1b[35m \ue0a0 main *\x1b[0m", nil},
{"sparse", []string{"--config=NONE"}, "\x1b[32m \ue0a0 main|SPARSE\x1b[0m", nil},
{"sparse_merge_conflict", []string{"--config=NONE"}, "\x1b[31m \ue0a0 main|SPARSE|MERGING|CONFLICT *↕ ↑[1] ↓[1]\x1b[0m", nil},

// rebase merge
{"rebase_i", []string{"--config=NONE"}, "\x1b[34m \ue0a0 main|REBASE-i 1/1\x1b[0m", nil},
{"rebase_m", []string{"--config=NONE"}, "\x1b[34m \ue0a0 main|REBASE-m 1/1\x1b[0m", nil},
// rebase apply
{"am_rebase", []string{"--config=NONE"}, "\x1b[34m \ue0a0 (b69e688)|AM/REBASE 1/1\x1b[0m", nil},
{"am", []string{"--config=NONE"}, "\x1b[34m \ue0a0 (b69e688)|AM 1/1\x1b[0m", nil},
{"rebase", []string{"--config=NONE"}, "\x1b[34m \ue0a0 main|REBASE 1/1\x1b[0m", nil},
// merge
{"merge_conflict", []string{"--config=NONE"}, "\x1b[31m \ue0a0 main|MERGING|CONFLICT *↕ ↑[1] ↓[1]\x1b[0m", nil},
{"merge", []string{"--config=NONE"}, "\x1b[35m \ue0a0 main|MERGING *↕ ↑[1] ↓[1]\x1b[0m", nil},
// cherry pick
{"cherry_pick_conflict", []string{"--config=NONE"}, "\x1b[31m \ue0a0 main|CHERRY-PICKING|CONFLICT *↕ ↑[1] ↓[1]\x1b[0m", nil},
{"cherry_pick", []string{"--config=NONE"}, "\x1b[35m \ue0a0 main|CHERRY-PICKING *↕ ↑[1] ↓[1]\x1b[0m", nil},
// revert
{"revert_conflict", []string{"--config=NONE"}, "\x1b[31m \ue0a0 main|REVERTING|CONFLICT *↕ ↑[2] ↓[1]\x1b[0m", nil},
{"revert", []string{"--config=NONE"}, "\x1b[31m \ue0a0 main|REVERTING *↕ ↑[2] ↓[1]\x1b[0m", nil},
// bisect
{"bisect", []string{"--config=NONE"}, "\x1b[34m \ue0a0 main|BISECTING ↓[1]\x1b[0m", nil},

// formatting
{"clean", []string{"--config=NONE", "--color-enabled=false"}, " \ue0a0 main", nil},
{"clean", []string{"--config=NONE", "--color-enabled=false", "--prompt-prefix= start "}, " start main", nil},
{"clean", []string{"--config=NONE", "--color-enabled=false", "--prompt-suffix= stop"}, " \ue0a0 main stop", nil},
{"conflict_ahead", []string{"--config=NONE", "--color-enabled=false", "--ahead-format=ahead by %d"}, " \ue0a0 main ahead by 1", nil},
{"conflict_behind", []string{"--config=NONE", "--color-enabled=false", "--behind-format=behind by %d"}, " \ue0a0 main behind by 1", nil},
{"conflict_diverged", []string{"--config=NONE", "--color-enabled=false", "--diverged-format=ahead by %d behind by %d"}, " \ue0a0 main ahead by 1 behind by 1", nil},
{"no_upstream_remote", []string{"--config=NONE", "--color-enabled=false", "--no-upstream-remote-format= upstream=[repo: %s branch: %s]"}, " \ue0a0 main upstream=[repo: mikesmithgh/test branch: main]", nil},

// color overrides
{"clean", []string{"--config=../configs/color_overrides.toml"}, "\x1b[38;2;230;238;4m \ue0a0 main\x1b[0m", nil},
{"no_upstream", []string{"--config=../configs/color_overrides.toml"}, "\x1b[30m\x1b[47m \ue0a0 main\x1b[0m", nil},
{"dirty", []string{"--config=../configs/color_overrides.toml"}, "\x1b[48;2;179;5;89m \ue0a0 main *\x1b[0m", nil},
{"conflict_ahead", []string{"--config=../configs/color_overrides.toml"}, "\x1b[38;2;252;183;40m \ue0a0 main ↑[1]\x1b[0m", nil},
{"untracked", []string{"--config=../configs/color_overrides.toml"}, "\x1b[38;2;255;0;0m\x1b[48;2;22;242;170m \ue0a0 main *\x1b[0m", nil},
{"bisect", []string{}, "\x1b[48;2;204;204;255m\x1b[35m \ue0a0 main|BISECTING ↓[1]\x1b[0m", []string{"BGPS_CONFIG=../configs/color_overrides.toml"}},

// config errors
{"clean", []string{"--config=/fromparam/does/not/exist"}, "\x1b[31m bgps error(read config): open /fromparam/does/not/exist: no such file or directory\x1b[0m", nil},
{"configs", []string{}, "\x1b[31m bgps error(read config): open /fromenvvar/does/not/exist: no such file or directory\x1b[0m", []string{"BGPS_CONFIG=/fromenvvar/does/not/exist"}},
{"configs", []string{"--config=invalid_syntax.toml"}, "\x1b[31m bgps error(unmarshal config): toml: expected character =\x1b[0m", nil},
{"configs", []string{}, "\x1b[31m bgps error(unmarshal config): toml: expected character =\x1b[0m", []string{"BGPS_CONFIG=invalid_syntax.toml"}},

{"norepo", []string{"--config=NONE"}, "", nil},
}

for _, test := range tests {
cmd := exec.Command(builtBinaryPath, test.input...)
cmd.Dir = filepath.Join(tmpDir, "testdata", test.dir)
if test.environ != nil {
cmd.Env = os.Environ()
cmd.Env = append(cmd.Env, test.environ...)
}
result, err := cmd.CombinedOutput()
if err != nil {
t.Errorf("Unexpected error: %s", err)
}
actual := string(result)
if actual != test.expected {
t.Errorf("in directory %s, %s != %s\nexpected:\n%q, \ngot:\n%q", test.dir, test.expected, actual, test.expected, actual)
}
}
}
Loading