Ugly fix for filepath.IsAbs not playing nicely with windows

This commit is contained in:
Jared Bydeley 2015-11-23 23:34:19 -05:00
parent e97dbc5a21
commit 8ec63a6ebe
2 changed files with 2 additions and 2 deletions

View file

@ -143,7 +143,7 @@ func guessProjectPath() {
srcPath := getSrcPath() srcPath := getSrcPath()
// if provided, inspect for logical locations // if provided, inspect for logical locations
if strings.ContainsRune(inputPath, os.PathSeparator) { if strings.ContainsRune(inputPath, os.PathSeparator) {
if filepath.IsAbs(inputPath) { if filepath.IsAbs(inputPath) || filepath.HasPrefix(inputPath, string(os.PathSeparator)) {
// if Absolute, use it // if Absolute, use it
projectPath = filepath.Clean(inputPath) projectPath = filepath.Clean(inputPath)
return return

View file

@ -31,7 +31,7 @@ func reset() {
func TestProjectPath(t *testing.T) { func TestProjectPath(t *testing.T) {
checkGuess(t, "", filepath.Join("github.com", "spf13", "hugo"), filepath.Join(getSrcPath(), "github.com", "spf13", "hugo")) 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("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", "baz", filepath.Join("/", "bar", "foo", "baz"))
checkGuess(t, "/bar/foo/cmd", "", filepath.Join("/", "bar", "foo")) checkGuess(t, "/bar/foo/cmd", "", filepath.Join("/", "bar", "foo"))
checkGuess(t, "/bar/foo/command", "", filepath.Join("/", "bar", "foo")) checkGuess(t, "/bar/foo/command", "", filepath.Join("/", "bar", "foo"))