Skip to content

Commit a3ee88d

Browse files
committed
show basic git status next to branches
1 parent 70b954a commit a3ee88d

File tree

4 files changed

+245
-15
lines changed

4 files changed

+245
-15
lines changed

cmd/git-linear/branch.go

+40-6
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ import (
1212
"syscall"
1313

1414
"github.com/charmbracelet/glamour"
15+
"github.com/fatih/color"
16+
"github.com/go-git/go-git/v5"
17+
"github.com/go-git/go-git/v5/plumbing"
1518
)
1619

1720
func branch() error {
@@ -103,16 +106,47 @@ func branch() error {
103106
return err
104107
}
105108

109+
cwd, err := os.Getwd()
110+
if err != nil {
111+
return err
112+
}
113+
repo, err := git.PlainOpen(cwd)
114+
if err != nil {
115+
return err
116+
}
117+
118+
const stateHeader = "STATE "
106119
io.WriteString(stdin, fmt.Sprint(
107-
"ID", "\t",
108-
"STATE", "\t",
109-
"BRANCH", "\000",
120+
"ID",
121+
"\t",
122+
stateHeader,
123+
"\t",
124+
" BRANCH",
125+
"\000",
110126
))
111127
for _, node := range resp.Data.Viewer.AssignedIssues.Nodes {
128+
129+
var state string
130+
if len(node.State.Name) > len(stateHeader) {
131+
state = node.State.Name[:len(stateHeader)]
132+
} else {
133+
state = node.State.Name
134+
}
135+
136+
ref, _ := repo.Storer.Reference(plumbing.NewBranchReferenceName(node.BranchName))
137+
var indicator string
138+
if ref != nil {
139+
indicator = color.GreenString("∃ ")
140+
} else {
141+
indicator = " "
142+
}
112143
io.WriteString(stdin, fmt.Sprint(
113-
node.Identifier, "\t",
114-
node.State.Name, "\t",
115-
node.BranchName, "\000",
144+
node.Identifier,
145+
"\t",
146+
state,
147+
"\t",
148+
indicator, node.BranchName,
149+
"\000",
116150
))
117151
}
118152
stdin.Close()

go.mod

+22-3
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,43 @@ require (
88
)
99

1010
require (
11+
github.com/Microsoft/go-winio v0.5.2 // indirect
12+
github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8 // indirect
13+
github.com/acomagu/bufpipe v1.0.4 // indirect
1114
github.com/alecthomas/chroma v0.10.0 // indirect
1215
github.com/aymanbagabas/go-osc52 v1.0.3 // indirect
1316
github.com/aymerick/douceur v0.2.0 // indirect
17+
github.com/cloudflare/circl v1.1.0 // indirect
1418
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
1519
github.com/dlclark/regexp2 v1.4.0 // indirect
20+
github.com/emirpasic/gods v1.18.1 // indirect
21+
github.com/fatih/color v1.15.0 // indirect
22+
github.com/go-git/gcfg v1.5.0 // indirect
23+
github.com/go-git/go-billy/v5 v5.4.1 // indirect
24+
github.com/go-git/go-git/v5 v5.6.1 // indirect
1625
github.com/gorilla/css v1.0.0 // indirect
26+
github.com/imdario/mergo v0.3.13 // indirect
27+
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
28+
github.com/kevinburke/ssh_config v1.2.0 // indirect
1729
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
18-
github.com/mattn/go-isatty v0.0.16 // indirect
30+
github.com/mattn/go-colorable v0.1.13 // indirect
31+
github.com/mattn/go-isatty v0.0.17 // indirect
1932
github.com/mattn/go-runewidth v0.0.14 // indirect
2033
github.com/microcosm-cc/bluemonday v1.0.21 // indirect
2134
github.com/muesli/reflow v0.3.0 // indirect
2235
github.com/muesli/termenv v0.13.0 // indirect
2336
github.com/olekukonko/tablewriter v0.0.5 // indirect
37+
github.com/pjbgf/sha1cd v0.3.0 // indirect
2438
github.com/rivo/uniseg v0.2.0 // indirect
2539
github.com/russross/blackfriday/v2 v2.1.0 // indirect
40+
github.com/sergi/go-diff v1.1.0 // indirect
41+
github.com/skeema/knownhosts v1.1.0 // indirect
42+
github.com/xanzy/ssh-agent v0.3.3 // indirect
2643
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
2744
github.com/yuin/goldmark v1.5.2 // indirect
2845
github.com/yuin/goldmark-emoji v1.0.1 // indirect
29-
golang.org/x/net v0.0.0-20221002022538-bcab6841153b // indirect
30-
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab // indirect
46+
golang.org/x/crypto v0.6.0 // indirect
47+
golang.org/x/net v0.7.0 // indirect
48+
golang.org/x/sys v0.6.0 // indirect
49+
gopkg.in/warnings.v0 v0.1.2 // indirect
3150
)

0 commit comments

Comments
 (0)