Skip to content

Commit

Permalink
fix: path handler
Browse files Browse the repository at this point in the history
  • Loading branch information
axetroy committed Dec 4, 2020
1 parent a94f18f commit 58d7a2d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 16 deletions.
20 changes: 7 additions & 13 deletions internal/client/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ import (
"io"
"io/ioutil"
"os"
"path"
"path/filepath"
"regexp"
"runtime"
"sort"
"strings"

Expand All @@ -19,8 +18,7 @@ import (
)

var (
versionRegexp = regexp.MustCompile(`^v`)
winAbsolutePathRegegp = regexp.MustCompile(`^(?i)[a-z]:.+`)
versionRegexp = regexp.MustCompile(`^v`)
)

type Tag struct {
Expand All @@ -40,12 +38,8 @@ func NewGitClient(dir string) (*GitClient, error) {
return nil, errors.WithStack(err)
}

if runtime.GOOS == "windows" {
if !winAbsolutePathRegegp.MatchString(dir) {
dir = path.Join(cwd, dir)
}
} else if !path.IsAbs(dir) {
dir = path.Join(cwd, dir)
if !filepath.IsAbs(dir) {
dir = filepath.Join(cwd, dir)
}

files, err := ioutil.ReadDir(dir)
Expand All @@ -60,15 +54,15 @@ func NewGitClient(dir string) (*GitClient, error) {
isProjectDir = true
} else {
// git submodule
content, err := ioutil.ReadFile(path.Join(dir, file.Name()))
content, err := ioutil.ReadFile(filepath.Join(dir, file.Name()))

if err != nil {
return nil, errors.WithStack(err)
}

matcher := regexp.MustCompile(`gitdir: (.*)`).FindStringSubmatch(string(content))

subModuleGitDir := path.Join(dir, matcher[1])
subModuleGitDir := filepath.Join(dir, matcher[1])

dir = subModuleGitDir
}
Expand All @@ -77,7 +71,7 @@ func NewGitClient(dir string) (*GitClient, error) {
}

if isProjectDir {
dir = path.Join(dir, ".git")
dir = filepath.Join(dir, ".git")
}

r, err := git.PlainOpen(dir)
Expand Down
6 changes: 3 additions & 3 deletions whatchanged.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"io"
"os"
"path"
"path/filepath"
"regexp"

parser "github.com/axetroy/whatchanged/1_parser"
Expand Down Expand Up @@ -53,8 +53,8 @@ func Generate(project string, w io.Writer, options *option.Options) error {
return errors.WithStack(err)
}

if !path.IsAbs(options.TemplateFile) {
options.TemplateFile = path.Join(cwd, options.TemplateFile)
if !filepath.IsAbs(options.TemplateFile) {
options.TemplateFile = filepath.Join(cwd, options.TemplateFile)
}
}

Expand Down

0 comments on commit 58d7a2d

Please sign in to comment.