Improved gitignore handling (#163)
This commit is contained in:
parent
4a4bd36cf6
commit
bf3824cc10
2 changed files with 16 additions and 7 deletions
2
go.mod
2
go.mod
|
@ -44,7 +44,7 @@ require (
|
||||||
gopkg.in/godo.v2 v2.0.9
|
gopkg.in/godo.v2 v2.0.9
|
||||||
gopkg.in/ini.v1 v1.41.0 // indirect
|
gopkg.in/ini.v1 v1.41.0 // indirect
|
||||||
gopkg.in/sourcemap.v1 v1.0.5 // indirect
|
gopkg.in/sourcemap.v1 v1.0.5 // indirect
|
||||||
gopkg.in/src-d/go-billy.v4 v4.3.0 // indirect
|
gopkg.in/src-d/go-billy.v4 v4.3.0
|
||||||
gopkg.in/src-d/go-git-fixtures.v3 v3.3.0 // indirect
|
gopkg.in/src-d/go-git-fixtures.v3 v3.3.0 // indirect
|
||||||
gopkg.in/src-d/go-git.v4 v4.9.1
|
gopkg.in/src-d/go-git.v4 v4.9.1
|
||||||
gopkg.in/yaml.v3 v3.0.0-20200121175148-a6ecf24a6d71
|
gopkg.in/yaml.v3 v3.0.0-20200121175148-a6ecf24a6d71
|
||||||
|
|
|
@ -5,6 +5,9 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"gopkg.in/src-d/go-billy.v4/helper/polyfill"
|
||||||
|
"gopkg.in/src-d/go-billy.v4/osfs"
|
||||||
|
"gopkg.in/src-d/go-git.v4/plumbing/format/gitignore"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
@ -16,7 +19,6 @@ import (
|
||||||
"github.com/docker/docker/api/types/mount"
|
"github.com/docker/docker/api/types/mount"
|
||||||
"github.com/docker/docker/client"
|
"github.com/docker/docker/client"
|
||||||
"github.com/docker/docker/pkg/stdcopy"
|
"github.com/docker/docker/pkg/stdcopy"
|
||||||
gitignore "github.com/monochromegane/go-gitignore"
|
|
||||||
"github.com/nektos/act/pkg/common"
|
"github.com/nektos/act/pkg/common"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
@ -325,22 +327,29 @@ func (cr *containerReference) copyDir(dstPath string, srcPath string) common.Exe
|
||||||
}
|
}
|
||||||
log.Debugf("Stripping prefix:%s src:%s", srcPrefix, srcPath)
|
log.Debugf("Stripping prefix:%s src:%s", srcPrefix, srcPath)
|
||||||
|
|
||||||
gitignore, err := gitignore.NewGitIgnore(filepath.Join(srcPath, ".gitignore"))
|
ps, err := gitignore.ReadPatterns(polyfill.New(osfs.New(srcPath)), nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Debugf("Error loading .gitignore: %v", err)
|
log.Debugf("Error loading .gitignore: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ignorer := gitignore.NewMatcher(ps)
|
||||||
|
|
||||||
err = filepath.Walk(srcPath, func(file string, fi os.FileInfo, err error) error {
|
err = filepath.Walk(srcPath, func(file string, fi os.FileInfo, err error) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// return on non-regular files (thanks to [kumo](https://medium.com/@komuw/just-like-you-did-fbdd7df829d3) for this suggested update)
|
sansPrefix := strings.TrimPrefix(file, srcPrefix)
|
||||||
if !fi.Mode().IsRegular() {
|
split := strings.Split(sansPrefix, string(filepath.Separator))
|
||||||
|
if ignorer.Match(split, fi.IsDir()) {
|
||||||
|
if fi.IsDir() {
|
||||||
|
return filepath.SkipDir
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if gitignore != nil && gitignore.Match(file, fi.IsDir()) {
|
// return on non-regular files (thanks to [kumo](https://medium.com/@komuw/just-like-you-did-fbdd7df829d3) for this suggested update)
|
||||||
|
if !fi.Mode().IsRegular() {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -351,7 +360,7 @@ func (cr *containerReference) copyDir(dstPath string, srcPath string) common.Exe
|
||||||
}
|
}
|
||||||
|
|
||||||
// update the name to correctly reflect the desired destination when untaring
|
// update the name to correctly reflect the desired destination when untaring
|
||||||
header.Name = strings.TrimPrefix(file, srcPrefix)
|
header.Name = sansPrefix
|
||||||
header.Mode = int64(fi.Mode())
|
header.Mode = int64(fi.Mode())
|
||||||
header.ModTime = fi.ModTime()
|
header.ModTime = fi.ModTime()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue