From 36546338c10c7357baf58c374be304f1bde2732c Mon Sep 17 00:00:00 2001 From: Christian Rebischke Date: Sat, 14 Nov 2020 22:42:04 +0100 Subject: [PATCH] transform windows filepaths to linux filepaths I hope this will make this code OS independent. --- .github/workflows/build.yml | 2 +- gitignore.go | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f651fca..4a78a5e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -5,7 +5,7 @@ jobs: strategy: matrix: go-version: [1.13.x, 1.14.x, 1.15.x] - os: [ubuntu-latest] + os: [ubuntu-latest, macos-latest, windows-latest ] runs-on: ${{ matrix.os }} steps: - name: Install Go diff --git a/gitignore.go b/gitignore.go index f95a35b..2b08d4e 100644 --- a/gitignore.go +++ b/gitignore.go @@ -71,6 +71,7 @@ import ( "bufio" "bytes" "io" + "path/filepath" "regexp" "strings" ) @@ -85,6 +86,8 @@ type gitIgnorePattern struct { func GitIgnore(patterns []string, name string) (ignore bool, err error) { for _, pattern := range patterns { p := parsePattern(pattern) + // Convert Windows paths to Unix paths + name = filepath.ToSlash(name) match, err := regexp.MatchString(p.Regex, name) if err != nil { return ignore, err @@ -113,6 +116,8 @@ func ReadGitIgnore(content io.Reader, name string) (ignore bool, err error) { continue } p := parsePattern(pattern) + // Convert Windows paths to Unix paths + name = filepath.ToSlash(name) match, err := regexp.MatchString(p.Regex, name) if err != nil { return ignore, err