Commit d6663a0512

d6663a051268e7f1016bf0adcfb81b5cd0934396

parent: 583b480f3a

Verified · cmc

cmc <hello@cleberg.net> · 2026-10-02 03:16 UTC

cli: send the inferred repository as here= in --term

Ref #317

Layout: unified · split

cmd/gitbay/ssh.go +7 −3
@@ -119,8 +119,9 @@ var noColor bool
119// output stays the rows stock ssh prints, and when GITBAY_TERM is "off", 119// output stays the rows stock ssh prints, and when GITBAY_TERM is "off",
120// for an instance older than --term. GITBAY_TERM=basic sends the width 120// for an instance older than --term. GITBAY_TERM=basic sends the width
121// and colour only, for an instance older than truecolor and links, which 121// and colour only, for an instance older than truecolor and links, which
122// turns any other option into plain output. 122// turns any other option into plain output. here is the repository
123func termValue(isTerminal bool, cols int, env func(string) string) string { 123// inferred from the clone, for suggested commands to leave out.
124func termValue(isTerminal bool, cols int, here string, env func(string) string) string {
124 if !isTerminal || cols < 40 || env("GITBAY_TERM") == "off" { 125 if !isTerminal || cols < 40 || env("GITBAY_TERM") == "off" {
125 return "" 126 return ""
126 } 127 }
@@ -138,6 +139,9 @@ func termValue(isTerminal bool, cols int, env func(string) string) string {
138 if linksWanted(env) { 139 if linksWanted(env) {
139 v += ",links" 140 v += ",links"
140 } 141 }
142 if here != "" {
143 v += ",here=" + here
144 }
141 return v 145 return v
142} 146}
143 147
@@ -235,7 +239,7 @@ func runSSHPaged(t target, serverArgv []string, stdin io.Reader, page bool) int
235 if isTTY { 239 if isTTY {
236 cols, _, _ = term.GetSize(fd) 240 cols, _, _ = term.GetSize(fd)
237 } 241 }
238 if v := termValue(isTTY, cols, os.Getenv); v != "" && !slices.Contains(serverArgv, "--json") { 242 if v := termValue(isTTY, cols, t.repo, os.Getenv); v != "" && !slices.Contains(serverArgv, "--json") {
239 serverArgv = append([]string{"--term=" + v}, serverArgv...) 243 serverArgv = append([]string{"--term=" + v}, serverArgv...)
240 } 244 }
241 245
cmd/gitbay/term_test.go +14 −1
@@ -37,13 +37,26 @@ func TestTermValue(t *testing.T) {
37 } 37 }
38 for _, c := range cases { 38 for _, c := range cases {
39 noColor = c.noColor 39 noColor = c.noColor
40 if got := termValue(c.tty, c.cols, env(c.env)); got != c.want { 40 if got := termValue(c.tty, c.cols, "", env(c.env)); got != c.want {
41 t.Errorf("%+v: got %q", c, got) 41 t.Errorf("%+v: got %q", c, got)
42 } 42 }
43 } 43 }
44 noColor = false 44 noColor = false
45} 45}
46 46
47func TestTermValueHere(t *testing.T) {
48 env := func(string) string { return "" }
49 if got, want := termValue(true, 100, "krz/gitbay", env), "100,color,here=krz/gitbay"; got != want {
50 t.Errorf("got %q, want %q", got, want)
51 }
52 if got := termValue(true, 100, "", env); strings.Contains(got, "here=") {
53 t.Errorf("here= without a repository: %q", got)
54 }
55 if got := termValue(false, 100, "krz/gitbay", env); got != "" {
56 t.Errorf("piped: %q", got)
57 }
58}
59
47func TestStripNoColor(t *testing.T) { 60func TestStripNoColor(t *testing.T) {
48 args, ok := stripNoColor([]string{"gitbay", "issue", "list", "--no-color", "--state", "all"}) 61 args, ok := stripNoColor([]string{"gitbay", "issue", "list", "--no-color", "--state", "all"})
49 if !ok || len(args) != 5 || args[3] != "--state" { 62 if !ok || len(args) != 5 || args[3] != "--state" {