Skip to content

Commit

Permalink
Fix parsing of repos with .git (#1398)
Browse files Browse the repository at this point in the history
  • Loading branch information
natasha41575 committed Jan 28, 2021
1 parent 23b736d commit 8a1032f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
9 changes: 9 additions & 0 deletions internal/cmdget/cmdget_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,15 @@ func TestCmd_fail(t *testing.T) {
assert.Contains(t, err.Error(), "failed to lookup master(or main) branch")
}

// TestCmd_git tests that if a package path contains .git, it is still parsed correctly
func TestCmd_git(t *testing.T) {
r := cmdget.NewRunner("kpt")
r.Command.SetArgs([]string{"https://github.com/GoogleContainerTools/kpt/.github/workflows", "./"})
err := r.Command.Execute()
assert.NoError(t, err)
assert.NoError(t, os.RemoveAll("workflows"))
}

// NoOpRunE is a noop function to replace the run function of a command. Useful for testing argument parsing.
var NoOpRunE = func(cmd *cobra.Command, args []string) error { return nil }

Expand Down
7 changes: 5 additions & 2 deletions internal/util/parse/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,14 @@ func GitParseArgs(args []string) (Target, error) {
return g, nil
}

// Simple parsing if contains .git
if strings.Contains(args[0], ".git") {
// Simple parsing if repo name ends in .git
if strings.Contains(args[0], ".git/") ||
strings.HasSuffix(args[0], ".git") {

var repo, dir, version string
parts := strings.Split(args[0], ".git")
repo = strings.TrimSuffix(parts[0], "/")

switch {
case len(parts) == 1:
// do nothing
Expand Down

0 comments on commit 8a1032f

Please sign in to comment.