Skip to content

Commit 43647d3

Browse files
committed
Strip tilde from Sourcehut usernames in output dir
1 parent 5c1d87b commit 43647d3

File tree

3 files changed

+67
-1
lines changed

3 files changed

+67
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,17 @@ All notable changes to this project will be documented in this file.
33

44
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55

6-
## [1.11.6] - unreleased
6+
## [1.11.6] - 11/6/25
77
### Added
88
- Sourcehut as a new SCM provider; thanks @shabbyrobe
99
### Changed
1010
### Deprecated
1111
### Removed
1212
### Fixed
1313
### Security
14+
- Bump gitlab.com/gitlab-org/api/client-go from 0.150.0 to 0.157.1 (#592)
15+
- Bump code.gitea.io/sdk/gitea from 0.22.0 to 0.22.1 (#591)
16+
- Bump golang.org/x/oauth2 from 0.31.0 to 0.32.0 (#590)
1417

1518
## [1.11.5] - 10/30/25
1619
### Added

cmd/clone.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1314,6 +1314,11 @@ func setOutputDirName(argz []string) {
13141314

13151315
outputDirName = strings.ToLower(argz[0])
13161316

1317+
// Strip ~ prefix for sourcehut usernames to avoid shell expansion issues
1318+
if os.Getenv("GHORG_SCM_TYPE") == "sourcehut" {
1319+
outputDirName = strings.TrimPrefix(outputDirName, "~")
1320+
}
1321+
13171322
if os.Getenv("GHORG_PRESERVE_SCM_HOSTNAME") != "true" {
13181323
// If all-group is used set the parent folder to the name of the baseurl
13191324
if argz[0] == "all-groups" && os.Getenv("GHORG_SCM_BASE_URL") != "" {

cmd/clone_test.go

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,64 @@ func TestShouldNotChangeNonLettersString(t *testing.T) {
5858
}
5959
}
6060

61+
func TestSourcehutStripsTildePrefix(t *testing.T) {
62+
defer UnsetEnv("GHORG_")()
63+
64+
usernameWithTilde := "~gabrie30"
65+
os.Setenv("GHORG_SCM_TYPE", "sourcehut")
66+
defer setOutputDirName([]string{""})
67+
setOutputDirName([]string{usernameWithTilde})
68+
69+
expected := "gabrie30"
70+
if outputDirName != expected {
71+
t.Errorf("Wrong folder name for sourcehut with tilde, expected: %s, got: %s", expected, outputDirName)
72+
}
73+
}
74+
75+
func TestSourcehutWithoutTildePrefix(t *testing.T) {
76+
defer UnsetEnv("GHORG_")()
77+
78+
usernameWithoutTilde := "gabrie30"
79+
os.Setenv("GHORG_SCM_TYPE", "sourcehut")
80+
defer setOutputDirName([]string{""})
81+
setOutputDirName([]string{usernameWithoutTilde})
82+
83+
expected := "gabrie30"
84+
if outputDirName != expected {
85+
t.Errorf("Wrong folder name for sourcehut without tilde, expected: %s, got: %s", expected, outputDirName)
86+
}
87+
}
88+
89+
func TestSourcehutStripsTildePrefixUppercase(t *testing.T) {
90+
defer UnsetEnv("GHORG_")()
91+
92+
usernameWithTilde := "~Gabrie30"
93+
os.Setenv("GHORG_SCM_TYPE", "sourcehut")
94+
defer setOutputDirName([]string{""})
95+
setOutputDirName([]string{usernameWithTilde})
96+
97+
// Should be lowercased AND have tilde stripped
98+
expected := "gabrie30"
99+
if outputDirName != expected {
100+
t.Errorf("Wrong folder name for sourcehut with uppercase and tilde, expected: %s, got: %s", expected, outputDirName)
101+
}
102+
}
103+
104+
func TestNonSourcehutPreservesTilde(t *testing.T) {
105+
defer UnsetEnv("GHORG_")()
106+
107+
usernameWithTilde := "~user123"
108+
os.Setenv("GHORG_SCM_TYPE", "github")
109+
defer setOutputDirName([]string{""})
110+
setOutputDirName([]string{usernameWithTilde})
111+
112+
// For non-sourcehut SCMs, tilde should be preserved (even though it's unusual)
113+
expected := "~user123"
114+
if outputDirName != expected {
115+
t.Errorf("Wrong folder name for github with tilde, expected: %s, got: %s", expected, outputDirName)
116+
}
117+
}
118+
61119
type MockGitClient struct{}
62120

63121
func NewMockGit() MockGitClient {

0 commit comments

Comments
 (0)