From 04b442d4199a9e2edb23d1f55516d2aac6d1b921 Mon Sep 17 00:00:00 2001 From: James Bardin Date: Fri, 9 Aug 2024 13:54:13 -0400 Subject: [PATCH] allow slashes in git url parameters Git url refs often contain slashes, which were incorrectly being split and appended to the path as a go-getter subdir. --- internal/command/hook_module_install.go | 4 +++- internal/getmodules/moduleaddrs/detect_git.go | 3 +++ internal/getmodules/moduleaddrs/detect_git_test.go | 4 ++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/internal/command/hook_module_install.go b/internal/command/hook_module_install.go index 9971cfbd32..4046c7ce5b 100644 --- a/internal/command/hook_module_install.go +++ b/internal/command/hook_module_install.go @@ -42,7 +42,9 @@ func (h uiModuleInstallHooks) Install(modulePath string, v *version.Version, loc func (h uiModuleInstallHooks) log(message string) { switch h.View.(type) { case view: - h.View.Log(message) + // there is no unformatted option for the View interface, so we need to + // pass message as a parameter to avoid double escaping % characters + h.View.Log("%s", message) default: h.Ui.Info(message) } diff --git a/internal/getmodules/moduleaddrs/detect_git.go b/internal/getmodules/moduleaddrs/detect_git.go index 353072eb03..21e9a6f7c1 100644 --- a/internal/getmodules/moduleaddrs/detect_git.go +++ b/internal/getmodules/moduleaddrs/detect_git.go @@ -40,6 +40,8 @@ func detectGitHub(src string) (string, bool, error) { } if strings.HasPrefix(src, "github.com/") { + src, rawQuery, _ := strings.Cut(src, "?") + parts := strings.Split(src, "/") if len(parts) < 3 { return "", false, fmt.Errorf( @@ -51,6 +53,7 @@ func detectGitHub(src string) (string, bool, error) { if err != nil { return "", true, fmt.Errorf("error parsing GitHub URL: %s", err) } + url.RawQuery = rawQuery if !strings.HasSuffix(url.Path, ".git") { url.Path += ".git" diff --git a/internal/getmodules/moduleaddrs/detect_git_test.go b/internal/getmodules/moduleaddrs/detect_git_test.go index f1a4ba6781..d78a3a0e23 100644 --- a/internal/getmodules/moduleaddrs/detect_git_test.go +++ b/internal/getmodules/moduleaddrs/detect_git_test.go @@ -74,6 +74,10 @@ func TestDetectGitHub(t *testing.T) { "github.com/hashicorp/foo.git?foo=bar", "git::https://github.com/hashicorp/foo.git?foo=bar", }, + { + "github.com/hashicorp/foo.git?foo=bar/baz", + "git::https://github.com/hashicorp/foo.git?foo=bar/baz", + }, }) }