Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: relative paths in sparse cloning #5691

Merged
merged 1 commit into from
Jul 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions cmd/testworkflow-toolkit/commands/clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ import (
"path/filepath"
"strings"

"github.com/otiai10/copy"

"github.com/kballard/go-shellquote"
"github.com/otiai10/copy"
"github.com/spf13/cobra"

"github.com/kubeshop/testkube/pkg/testworkflows/testworkflowprocessor/constants"
Expand All @@ -18,7 +17,7 @@ import (

func NewCloneCmd() *cobra.Command {
var (
paths []string
rawPaths []string
username string
token string
sshKey string
Expand All @@ -40,6 +39,15 @@ func NewCloneCmd() *cobra.Command {
// Disable interactivity
os.Setenv("GIT_TERMINAL_PROMPT", "0")

// Clean paths for sparse checkout to make them more compliant with Git requirements
paths := make([]string, 0)
for _, p := range rawPaths {
p = filepath.Clean(p)
if p != "" && p != "." {
paths = append(paths, p)
}
}

authArgs := make([]string, 0)

if authType == "header" {
Expand Down Expand Up @@ -105,6 +113,7 @@ func NewCloneCmd() *cobra.Command {
}

// Copy files to the expected directory. Ignore errors, only inform warn about them.
fmt.Printf("Moving the contents to %s...\n", destinationPath)
err = copy.Copy(outputPath, destinationPath, copy.Options{
OnError: func(src, dest string, err error) error {
if err != nil {
Expand All @@ -118,10 +127,12 @@ func NewCloneCmd() *cobra.Command {
},
})
ui.ExitOnError("copying files to destination", err)
err = os.RemoveAll(outputPath)
ui.ExitOnError("deleting the temporary directory", err)
},
}

cmd.Flags().StringSliceVarP(&paths, "paths", "p", nil, "paths for sparse checkout")
cmd.Flags().StringSliceVarP(&rawPaths, "paths", "p", nil, "paths for sparse checkout")
cmd.Flags().StringVarP(&username, "username", "u", "", "")
cmd.Flags().StringVarP(&token, "token", "t", "", "")
cmd.Flags().StringVarP(&sshKey, "sshKey", "s", "", "")
Expand Down
Loading