From 1057f75af96dd01f76e2f1a3e0203306e85bd080 Mon Sep 17 00:00:00 2001 From: Jared Bydeley Date: Mon, 23 Nov 2015 22:46:26 -0500 Subject: [PATCH 1/3] Fixed import path issue on Windows --- cobra/cmd/helpers.go | 2 +- cobra/cmd/helpers_test.go | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/cobra/cmd/helpers.go b/cobra/cmd/helpers.go index 3f6357f0..d5c276f9 100644 --- a/cobra/cmd/helpers.go +++ b/cobra/cmd/helpers.go @@ -104,7 +104,7 @@ func guessImportPath() string { er("Cobra only supports project within $GOPATH") } - return filepath.Clean(strings.TrimPrefix(projectPath, getSrcPath())) + return filepath.ToSlash(filepath.Clean(strings.TrimPrefix(projectPath, getSrcPath()))) } func getSrcPath() string { diff --git a/cobra/cmd/helpers_test.go b/cobra/cmd/helpers_test.go index 564ddbe5..c3f990bb 100644 --- a/cobra/cmd/helpers_test.go +++ b/cobra/cmd/helpers_test.go @@ -3,6 +3,7 @@ package cmd import ( "fmt" "os" + "path/filepath" "testing" ) @@ -28,12 +29,14 @@ func reset() { } func TestProjectPath(t *testing.T) { - checkGuess(t, "", "github.com/spf13/hugo", getSrcPath()+"github.com/spf13/hugo") - checkGuess(t, "", "spf13/hugo", getSrcPath()+"github.com/spf13/hugo") - checkGuess(t, "", "/bar/foo", "/bar/foo") - checkGuess(t, "/bar/foo", "baz", "/bar/foo/baz") - checkGuess(t, "/bar/foo/cmd", "", "/bar/foo") - checkGuess(t, "/bar/foo/command", "", "/bar/foo") - checkGuess(t, "/bar/foo/commands", "", "/bar/foo") - checkGuess(t, "github.com/spf13/hugo/../hugo", "", "github.com/spf13/hugo") + wd, _ := os.Getwd() + + checkGuess(t, "", "github.com/spf13/hugo", filepath.Join(wd, "github.com", "spf13", "hugo")) + checkGuess(t, "", "spf13/hugo", filepath.Join(wd, "spf13", "hugo")) + checkGuess(t, "", "/bar/foo", filepath.Join(wd, "bar", "foo")) + checkGuess(t, "/bar/foo", "baz", filepath.Join("/", "bar", "foo", "baz")) + checkGuess(t, "/bar/foo/cmd", "", filepath.Join("/", "bar", "foo")) + checkGuess(t, "/bar/foo/command", "", filepath.Join("/", "bar", "foo")) + checkGuess(t, "/bar/foo/commands", "", filepath.Join("/", "bar", "foo")) + checkGuess(t, "github.com/spf13/hugo/../hugo", "", filepath.Join("github.com", "spf13", "hugo")) } From e97dbc5a21dc64e220a960be4ed9cabfa2c9941d Mon Sep 17 00:00:00 2001 From: Jared Bydeley Date: Mon, 23 Nov 2015 23:19:22 -0500 Subject: [PATCH 2/3] Fixed tests for how they are run --- cobra/cmd/helpers_test.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/cobra/cmd/helpers_test.go b/cobra/cmd/helpers_test.go index c3f990bb..dc9b3f3a 100644 --- a/cobra/cmd/helpers_test.go +++ b/cobra/cmd/helpers_test.go @@ -29,11 +29,9 @@ func reset() { } func TestProjectPath(t *testing.T) { - wd, _ := os.Getwd() - - checkGuess(t, "", "github.com/spf13/hugo", filepath.Join(wd, "github.com", "spf13", "hugo")) - checkGuess(t, "", "spf13/hugo", filepath.Join(wd, "spf13", "hugo")) - checkGuess(t, "", "/bar/foo", filepath.Join(wd, "bar", "foo")) + checkGuess(t, "", filepath.Join("github.com", "spf13", "hugo"), filepath.Join(getSrcPath(), "github.com", "spf13", "hugo")) + checkGuess(t, "", filepath.Join("spf13", "hugo"), filepath.Join(getSrcPath(), "github.com", "spf13", "hugo")) + checkGuess(t, "", filepath.Join("/", "bar", "foo"), filepath.Join(getSrcPath(), "bar", "foo")) checkGuess(t, "/bar/foo", "baz", filepath.Join("/", "bar", "foo", "baz")) checkGuess(t, "/bar/foo/cmd", "", filepath.Join("/", "bar", "foo")) checkGuess(t, "/bar/foo/command", "", filepath.Join("/", "bar", "foo")) From 8ec63a6ebe426a1fbfcfb9607f166d84a6a1526c Mon Sep 17 00:00:00 2001 From: Jared Bydeley Date: Mon, 23 Nov 2015 23:34:19 -0500 Subject: [PATCH 3/3] Ugly fix for filepath.IsAbs not playing nicely with windows --- cobra/cmd/helpers.go | 2 +- cobra/cmd/helpers_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cobra/cmd/helpers.go b/cobra/cmd/helpers.go index d5c276f9..8730062a 100644 --- a/cobra/cmd/helpers.go +++ b/cobra/cmd/helpers.go @@ -143,7 +143,7 @@ func guessProjectPath() { srcPath := getSrcPath() // if provided, inspect for logical locations if strings.ContainsRune(inputPath, os.PathSeparator) { - if filepath.IsAbs(inputPath) { + if filepath.IsAbs(inputPath) || filepath.HasPrefix(inputPath, string(os.PathSeparator)) { // if Absolute, use it projectPath = filepath.Clean(inputPath) return diff --git a/cobra/cmd/helpers_test.go b/cobra/cmd/helpers_test.go index dc9b3f3a..bd0f7595 100644 --- a/cobra/cmd/helpers_test.go +++ b/cobra/cmd/helpers_test.go @@ -31,7 +31,7 @@ func reset() { func TestProjectPath(t *testing.T) { checkGuess(t, "", filepath.Join("github.com", "spf13", "hugo"), filepath.Join(getSrcPath(), "github.com", "spf13", "hugo")) checkGuess(t, "", filepath.Join("spf13", "hugo"), filepath.Join(getSrcPath(), "github.com", "spf13", "hugo")) - checkGuess(t, "", filepath.Join("/", "bar", "foo"), filepath.Join(getSrcPath(), "bar", "foo")) + checkGuess(t, "", filepath.Join("/", "bar", "foo"), filepath.Join("/", "bar", "foo")) checkGuess(t, "/bar/foo", "baz", filepath.Join("/", "bar", "foo", "baz")) checkGuess(t, "/bar/foo/cmd", "", filepath.Join("/", "bar", "foo")) checkGuess(t, "/bar/foo/command", "", filepath.Join("/", "bar", "foo"))