BlueGit

timfa bluegit

Merged

Release: SSH-clone-URL korte vorm

!88 · merged 3 weeks ago

timfa wants to merge 2 commits from stage into master

Pipeline

#348 Passed
Stage: build

Reviews

  • No reviews yet.

Merged by timfa on 26 October 2026 1050ba1c

Overview Commits 2 Pipelines 1 Changes 4

Changes

4 files changed +25 −5
docs/INGRESS.md +1 −1
@@ -61,4 +61,4 @@ stream {
61 61 }
62 62 ```
63 63
64 De clone-URL op de website is dan `ssh://git@git.timfalken.com:22/eigenaar/naam.git`. Op de mini-PC blijft git-SSH op poort 2222 luisteren, naast de SSH van Arch.
64 De clone-URL op de website is dan `git@git.timfalken.com:eigenaar/naam.git` (de korte vorm, zoals GitHub). Bij een andere publieke poort wordt het `ssh://git@host:poort/eigenaar/naam.git`. Op de mini-PC blijft git-SSH op poort 2222 luisteren, naast de SSH van Arch.
@@ -61,4 +61,4 @@ stream {
61}
61}
62```
62```
63
63
64De clone-URL op de website is dan `ssh://git@git.timfalken.com:22/eigenaar/naam.git`. Op de mini-PC blijft git-SSH op poort 2222 luisteren, naast de SSH van Arch.
64De clone-URL op de website is dan `git@git.timfalken.com:eigenaar/naam.git` (de korte vorm, zoals GitHub). Bij een andere publieke poort wordt het `ssh://git@host:poort/eigenaar/naam.git`. Op de mini-PC blijft git-SSH op poort 2222 luisteren, naast de SSH van Arch.
internal/config/config.go +5 −0
@@ -308,6 +308,7 @@ func (c Config) SSHPublicPort() int {
308 308 }
309 309
310 310 // CloneSSH is de URL die een gebruiker kloont. Leeg als SSH uit staat.
311 // Poort 22 geeft git@host:pad.git, een andere poort ssh://git@host:poort/pad.git.
311 312 func (c Config) CloneSSH(repoPath string) string {
312 313 if !c.SSH.Enabled {
313 314 return ""
@@ -316,6 +317,10 @@ func (c Config) CloneSSH(repoPath string) string {
316 317 if strings.Contains(host, ":") && !strings.HasPrefix(host, "[") {
317 318 host = "[" + host + "]"
318 319 }
320 if c.SSHPublicPort() == 22 {
321 // Korte scp-vorm, zoals GitHub en GitLab. Die kent geen poort.
322 return fmt.Sprintf("git@%s:%s.git", host, repoPath)
323 }
319 324 return fmt.Sprintf("ssh://git@%s:%d/%s.git", host, c.SSHPublicPort(), repoPath)
320 325 }
321 326
@@ -308,6 +308,7 @@ func (c Config) SSHPublicPort() int {
308}
308}
309
309
310// CloneSSH is de URL die een gebruiker kloont. Leeg als SSH uit staat.
310// CloneSSH is de URL die een gebruiker kloont. Leeg als SSH uit staat.
311// Poort 22 geeft git@host:pad.git, een andere poort ssh://git@host:poort/pad.git.
311func (c Config) CloneSSH(repoPath string) string {
312func (c Config) CloneSSH(repoPath string) string {
312 if !c.SSH.Enabled {
313 if !c.SSH.Enabled {
313 return ""
314 return ""
@@ -316,6 +317,10 @@ func (c Config) CloneSSH(repoPath string) string {
316 if strings.Contains(host, ":") && !strings.HasPrefix(host, "[") {
317 if strings.Contains(host, ":") && !strings.HasPrefix(host, "[") {
317 host = "[" + host + "]"
318 host = "[" + host + "]"
318 }
319 }
320 if c.SSHPublicPort() == 22 {
321 // Korte scp-vorm, zoals GitHub en GitLab. Die kent geen poort.
322 return fmt.Sprintf("git@%s:%s.git", host, repoPath)
323 }
319 return fmt.Sprintf("ssh://git@%s:%d/%s.git", host, c.SSHPublicPort(), repoPath)
324 return fmt.Sprintf("ssh://git@%s:%d/%s.git", host, c.SSHPublicPort(), repoPath)
320}
325}
321
326
internal/config/config_test.go +16 −1
@@ -152,7 +152,7 @@ ssh:
152 152 if err != nil {
153 153 t.Fatal(err)
154 154 }
155 if cfg.CloneSSH("tim/demo") != "ssh://git@git.timfalken.com:22/tim/demo.git" {
155 if cfg.CloneSSH("tim/demo") != "git@git.timfalken.com:tim/demo.git" {
156 156 t.Fatal(cfg.CloneSSH("tim/demo"))
157 157 }
158 158 if cfg.ProxySet() == nil || cfg.Listen != "0.0.0.0:8080" {
@@ -196,3 +196,18 @@ func TestBadProxyRejected(t *testing.T) {
196 196 t.Fatalf("verwacht weigering van een poort in de host, kreeg %v", err)
197 197 }
198 198 }
199
200 func TestCloneSSHForms(t *testing.T) {
201 c := Config{SSH: SSH{Enabled: true, PublicHost: "git.example.test", PublicPort: 22}}
202 if got := c.CloneSSH("tim/demo"); got != "git@git.example.test:tim/demo.git" {
203 t.Fatal(got)
204 }
205 c.SSH.PublicPort = 2222
206 if got := c.CloneSSH("tim/demo"); got != "ssh://git@git.example.test:2222/tim/demo.git" {
207 t.Fatal(got)
208 }
209 c.SSH.PublicHost, c.SSH.PublicPort = "::1", 22
210 if got := c.CloneSSH("tim/demo"); got != "git@[::1]:tim/demo.git" {
211 t.Fatal(got)
212 }
213 }
@@ -152,7 +152,7 @@ ssh:
152 if err != nil {
152 if err != nil {
153 t.Fatal(err)
153 t.Fatal(err)
154 }
154 }
155 if cfg.CloneSSH("tim/demo") != "ssh://git@git.timfalken.com:22/tim/demo.git" {
155 if cfg.CloneSSH("tim/demo") != "git@git.timfalken.com:tim/demo.git" {
156 t.Fatal(cfg.CloneSSH("tim/demo"))
156 t.Fatal(cfg.CloneSSH("tim/demo"))
157 }
157 }
158 if cfg.ProxySet() == nil || cfg.Listen != "0.0.0.0:8080" {
158 if cfg.ProxySet() == nil || cfg.Listen != "0.0.0.0:8080" {
@@ -196,3 +196,18 @@ func TestBadProxyRejected(t *testing.T) {
196 t.Fatalf("verwacht weigering van een poort in de host, kreeg %v", err)
196 t.Fatalf("verwacht weigering van een poort in de host, kreeg %v", err)
197 }
197 }
198}
198}
199
200func TestCloneSSHForms(t *testing.T) {
201 c := Config{SSH: SSH{Enabled: true, PublicHost: "git.example.test", PublicPort: 22}}
202 if got := c.CloneSSH("tim/demo"); got != "git@git.example.test:tim/demo.git" {
203 t.Fatal(got)
204 }
205 c.SSH.PublicPort = 2222
206 if got := c.CloneSSH("tim/demo"); got != "ssh://git@git.example.test:2222/tim/demo.git" {
207 t.Fatal(got)
208 }
209 c.SSH.PublicHost, c.SSH.PublicPort = "::1", 22
210 if got := c.CloneSSH("tim/demo"); got != "git@[::1]:tim/demo.git" {
211 t.Fatal(got)
212 }
213}
internal/server/server_test.go +3 −3
@@ -79,13 +79,13 @@ func TestWebRepoPushAndSecretBoundary(t *testing.T) {
79 79 if !strings.Contains(body, "tim/demo") {
80 80 t.Fatalf("repo pagina:\n%s", body)
81 81 }
82 if !strings.Contains(body, "ssh://git@git.timfalken.com:22/tim/demo.git") {
82 if !strings.Contains(body, "git@git.timfalken.com:tim/demo.git") {
83 83 t.Fatalf("clone-URL hoort de publieke SSH-poort te tonen:\n%s", body)
84 84 }
85 85 if strings.Contains(body, ":2222/") {
86 86 t.Fatalf("clone-URL toont de bindpoort:\n%s", body)
87 87 }
88 sshURL := "ssh://git@git.timfalken.com:22/tim/demo.git"
88 sshURL := "git@git.timfalken.com:tim/demo.git"
89 89 httpURL := "http://127.0.0.1:9/tim/demo.git"
90 90 assertCloneMenu(t, body, "overzicht", sshURL, httpURL)
91 91 res, err = client.Get(ts.URL + "/tim/demo/-/tree")
@@ -543,7 +543,7 @@ func TestProjectOverviewAndFiles(t *testing.T) {
543 543 "/-/tree/crates?rev=master",
544 544 "/-/tree/src?rev=master",
545 545 "Simulatie",
546 "ssh://git@git.timfalken.com:22/tim/legacy-cycles.git",
546 "git@git.timfalken.com:tim/legacy-cycles.git",
547 547 } {
548 548 if !strings.Contains(body, want) {
549 549 t.Fatalf("overzicht mist %q\n%s", want, body)
@@ -79,13 +79,13 @@ func TestWebRepoPushAndSecretBoundary(t *testing.T) {
79 if !strings.Contains(body, "tim/demo") {
79 if !strings.Contains(body, "tim/demo") {
80 t.Fatalf("repo pagina:\n%s", body)
80 t.Fatalf("repo pagina:\n%s", body)
81 }
81 }
82 if !strings.Contains(body, "ssh://git@git.timfalken.com:22/tim/demo.git") {
82 if !strings.Contains(body, "git@git.timfalken.com:tim/demo.git") {
83 t.Fatalf("clone-URL hoort de publieke SSH-poort te tonen:\n%s", body)
83 t.Fatalf("clone-URL hoort de publieke SSH-poort te tonen:\n%s", body)
84 }
84 }
85 if strings.Contains(body, ":2222/") {
85 if strings.Contains(body, ":2222/") {
86 t.Fatalf("clone-URL toont de bindpoort:\n%s", body)
86 t.Fatalf("clone-URL toont de bindpoort:\n%s", body)
87 }
87 }
88 sshURL := "ssh://git@git.timfalken.com:22/tim/demo.git"
88 sshURL := "git@git.timfalken.com:tim/demo.git"
89 httpURL := "http://127.0.0.1:9/tim/demo.git"
89 httpURL := "http://127.0.0.1:9/tim/demo.git"
90 assertCloneMenu(t, body, "overzicht", sshURL, httpURL)
90 assertCloneMenu(t, body, "overzicht", sshURL, httpURL)
91 res, err = client.Get(ts.URL + "/tim/demo/-/tree")
91 res, err = client.Get(ts.URL + "/tim/demo/-/tree")
@@ -543,7 +543,7 @@ func TestProjectOverviewAndFiles(t *testing.T) {
543 "/-/tree/crates?rev=master",
543 "/-/tree/crates?rev=master",
544 "/-/tree/src?rev=master",
544 "/-/tree/src?rev=master",
545 "Simulatie",
545 "Simulatie",
546 "ssh://git@git.timfalken.com:22/tim/legacy-cycles.git",
546 "git@git.timfalken.com:tim/legacy-cycles.git",
547 } {
547 } {
548 if !strings.Contains(body, want) {
548 if !strings.Contains(body, want) {
549 t.Fatalf("overzicht mist %q\n%s", want, body)
549 t.Fatalf("overzicht mist %q\n%s", want, body)