Skip to content

Commit ed1af3d

Browse files
committed
fix for windows path
1 parent f9b3348 commit ed1af3d

File tree

1 file changed

+13
-18
lines changed

1 file changed

+13
-18
lines changed

internal/exec/go_getter_utils.go

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ func IsValidScheme(scheme string) bool {
7070
// do a git-based clone with a token.
7171
type CustomGitHubDetector struct {
7272
AtmosConfig schema.AtmosConfiguration
73+
source string
7374
}
7475

7576
// Detect implements the getter.Detector interface for go-getter v1.
@@ -99,11 +100,10 @@ func (d *CustomGitHubDetector) Detect(src, _ string) (string, bool, error) {
99100
return "", false, fmt.Errorf("invalid GitHub URL %q", parsedURL.Path)
100101
}
101102

102-
if !strings.Contains(parsedURL.Path, "//") {
103-
// If it ends with .git treat it as wanting the entire repo
104-
if strings.HasSuffix(parsedURL.Path, ".git") ||
105-
len(parts) == 3 { // means /owner/repo only
106-
u.LogDebug(d.AtmosConfig, "Detected top-level repo with no subdir: appending '//.\n")
103+
if !strings.Contains(d.source, "//") {
104+
// means user typed something like "github.com/org/repo.git" with NO subdir
105+
if strings.HasSuffix(parsedURL.Path, ".git") || len(parts) == 3 {
106+
u.LogDebug(d.AtmosConfig, "Detected top-level repo with no subdir: appending '//.'\n")
107107
parsedURL.Path = parsedURL.Path + "//."
108108
}
109109
}
@@ -148,19 +148,10 @@ func (d *CustomGitHubDetector) Detect(src, _ string) (string, bool, error) {
148148

149149
// RegisterCustomDetectors prepends the custom detector so it runs before
150150
// the built-in ones. Any code that calls go-getter should invoke this.
151-
func RegisterCustomDetectors(atmosConfig schema.AtmosConfiguration) {
151+
func RegisterCustomDetectors(atmosConfig schema.AtmosConfiguration, source string) {
152152
getter.Detectors = append(
153153
[]getter.Detector{
154-
&CustomGitHubDetector{AtmosConfig: atmosConfig},
155-
},
156-
getter.Detectors...,
157-
)
158-
}
159-
160-
func RegisterCustomGetters(atmosConfig schema.AtmosConfiguration) {
161-
getter.Detectors = append(
162-
[]getter.Detector{
163-
&CustomGitHubDetector{AtmosConfig: atmosConfig},
154+
&CustomGitHubDetector{AtmosConfig: atmosConfig, source: source},
164155
},
165156
getter.Detectors...,
166157
)
@@ -176,8 +167,12 @@ func GoGetterGet(
176167
) error {
177168
ctx, cancel := context.WithTimeout(context.Background(), timeout)
178169
defer cancel()
179-
// Register custom detectors
180-
RegisterCustomDetectors(atmosConfig)
170+
171+
// Register custom detectors, passing the original `src` to the CustomGitHubDetector.
172+
// go-getter typically strips subdirectories before calling the detector, so the
173+
// unaltered source is needed to identify whether a top-level repository or a
174+
// subdirectory was specified (e.g., for appending "//." only when no subdir is present).
175+
RegisterCustomDetectors(atmosConfig, src)
181176

182177
client := &getter.Client{
183178
Ctx: ctx,

0 commit comments

Comments
 (0)