Skip to content

Commit

Permalink
Merge pull request #123 from kcl-lang/fix-git-download-failure
Browse files Browse the repository at this point in the history
fix: fix git downloading failure
  • Loading branch information
He1pa authored Jan 7, 2025
2 parents 04f9c8d + dfa377a commit 3028afc
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pkg/source/getter.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"os"
"os/signal"
"path/filepath"
"sync"

"github.com/hashicorp/go-getter"
Expand All @@ -24,6 +25,13 @@ func ReadThroughGetter(src string, opts ...getter.ClientOption) (string, string,
if err != nil {
return "", tmpDir, fmt.Errorf("error creating temp file: %v", err)
}

// go-getter should download the source code to a directory which not exists.
// if the path exists, it will return an error.
if IsGit(src) || IsVCSDomain(src) {
tmpDir = filepath.Join(tmpDir, "git")
}

// Getter context
ctx, cancel := context.WithCancel(context.Background())
// Build the client
Expand Down
26 changes: 26 additions & 0 deletions pkg/source/getter_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package source

import (
"os"
"path/filepath"
"testing"
)

func TestReadThroughGetter(t *testing.T) {
tmpDir, _, err := ReadThroughGetter("git::https://github.com/kcl-lang/flask-demo-kcl-manifests.git")
if err != nil {
t.Errorf("TestReadThroughGetter() error = %v", err)
return
}

// Check if tmpDir exists
if _, err := os.Stat(tmpDir); os.IsNotExist(err) {
t.Errorf("TestReadThroughGetter() tmpDir does not exist")
}

// Check if kcl.mod file exists in tmpDir
kclModPath := filepath.Join(tmpDir, "kcl.mod")
if _, err := os.Stat(kclModPath); os.IsNotExist(err) {
t.Errorf("TestReadThroughGetter() kcl.mod file does not exist in tmpDir")
}
}

0 comments on commit 3028afc

Please sign in to comment.