Skip to content

Commit

Permalink
Handle trailing slash in remote URL (#223)
Browse files Browse the repository at this point in the history
  • Loading branch information
mlange-42 authored Feb 10, 2025
1 parent 16b8b5d commit 724e622
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
### Other

* Internal: splits up the `Processor` mega-struct (#218, #219)
* Command `init` supports remote repos cloned with SSL (#221)
* Command `init` supports remote repos cloned with SSL (#221, #223)

## [[v0.11.0]](https://github.com/mlange-42/modo/compare/v0.10.1...v0.11.0)

Expand Down
5 changes: 3 additions & 2 deletions internal/document/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func GetGitOrigin(outDir string) (*GitInfo, error) {
if !ok {
fmt.Printf("WARNING: No Git repository or no remote 'origin' found.\n Using dummy %s\n", url)
}
url, err := getRepoUrl(url)
url, err := getRepoURL(url)
if err != nil {
url = "https://github.com/your/package"
fmt.Printf("WARNING: Git remote 'origin' could not be parsed.\n Using dummy %s\n", url)
Expand All @@ -188,7 +188,8 @@ func GetGitOrigin(outDir string) (*GitInfo, error) {
}, nil
}

func getRepoUrl(url string) (string, error) {
func getRepoURL(url string) (string, error) {
url = strings.TrimSuffix(url, "/")
if strings.HasPrefix(url, "http://") || strings.HasPrefix(url, "https://") {
return strings.TrimSuffix(url, ".git"), nil
}
Expand Down
8 changes: 6 additions & 2 deletions internal/document/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,15 @@ func TestGetGitOrigin(t *testing.T) {
}

func TestGetRepoUrl(t *testing.T) {
url, err := getRepoUrl("https://github.com/mlange-42/modo.git")
url, err := getRepoURL("https://github.com/mlange-42/modo.git")
assert.Nil(t, err)
assert.Equal(t, "https://github.com/mlange-42/modo", url)

url, err = getRepoUrl("git@github.com:mlange-42/modo")
url, err = getRepoURL("https://github.com/mlange-42/modo.git/")
assert.Nil(t, err)
assert.Equal(t, "https://github.com/mlange-42/modo", url)

url, err = getRepoURL("git@github.com:mlange-42/modo")
assert.Nil(t, err)
assert.Equal(t, "https://github.com/mlange-42/modo", url)
}
Expand Down

0 comments on commit 724e622

Please sign in to comment.