mirror of
https://code.forgejo.org/forgejo/runner.git
synced 2025-08-11 17:50:58 +00:00
Improved gitignore handling (#163)
This commit is contained in:
parent
25134089ee
commit
249ebdb066
1 changed files with 15 additions and 6 deletions
|
@ -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…
Add table
Add a link
Reference in a new issue