@@ -63,7 +63,7 @@ type FileEntry struct {
6363type Container interface {
6464 Create () common.Executor
6565 Copy (destPath string , files ... * FileEntry ) common.Executor
66- CopyDir (destPath string , srcPath string ) common.Executor
66+ CopyDir (destPath string , srcPath string , useGitIgnore bool ) common.Executor
6767 Pull (forcePull bool ) common.Executor
6868 Start (attach bool ) common.Executor
6969 Exec (command []string , env map [string ]string ) common.Executor
@@ -136,13 +136,13 @@ func (cr *containerReference) Copy(destPath string, files ...*FileEntry) common.
136136 ).IfNot (common .Dryrun )
137137}
138138
139- func (cr * containerReference ) CopyDir (destPath string , srcPath string ) common.Executor {
139+ func (cr * containerReference ) CopyDir (destPath string , srcPath string , useGitIgnore bool ) common.Executor {
140140 return common .NewPipelineExecutor (
141141 common .NewInfoExecutor ("%sdocker cp src=%s dst=%s" , logPrefix , srcPath , destPath ),
142142 cr .connect (),
143143 cr .find (),
144144 cr .exec ([]string {"mkdir" , "-p" , destPath }, nil ),
145- cr .copyDir (destPath , srcPath ),
145+ cr .copyDir (destPath , srcPath , useGitIgnore ),
146146 ).IfNot (common .Dryrun )
147147}
148148
@@ -448,7 +448,7 @@ func (cr *containerReference) exec(cmd []string, env map[string]string) common.E
448448}
449449
450450// nolint: gocyclo
451- func (cr * containerReference ) copyDir (dstPath string , srcPath string ) common.Executor {
451+ func (cr * containerReference ) copyDir (dstPath string , srcPath string , useGitIgnore bool ) common.Executor {
452452 return func (ctx context.Context ) error {
453453 logger := common .Logger (ctx )
454454 tarFile , err := ioutil .TempFile ("" , "act" )
@@ -466,12 +466,15 @@ func (cr *containerReference) copyDir(dstPath string, srcPath string) common.Exe
466466 }
467467 log .Debugf ("Stripping prefix:%s src:%s" , srcPrefix , srcPath )
468468
469- ps , err := gitignore .ReadPatterns (polyfill .New (osfs .New (srcPath )), nil )
470- if err != nil {
471- log .Debugf ("Error loading .gitignore: %v" , err )
472- }
469+ var ignorer gitignore.Matcher
470+ if useGitIgnore {
471+ ps , err := gitignore .ReadPatterns (polyfill .New (osfs .New (srcPath )), nil )
472+ if err != nil {
473+ log .Debugf ("Error loading .gitignore: %v" , err )
474+ }
473475
474- ignorer := gitignore .NewMatcher (ps )
476+ ignorer = gitignore .NewMatcher (ps )
477+ }
475478
476479 err = filepath .Walk (srcPath , func (file string , fi os.FileInfo , err error ) error {
477480 if err != nil {
@@ -480,7 +483,7 @@ func (cr *containerReference) copyDir(dstPath string, srcPath string) common.Exe
480483
481484 sansPrefix := strings .TrimPrefix (file , srcPrefix )
482485 split := strings .Split (sansPrefix , string (filepath .Separator ))
483- if ignorer .Match (split , fi .IsDir ()) {
486+ if ignorer != nil && ignorer .Match (split , fi .IsDir ()) {
484487 if fi .IsDir () {
485488 return filepath .SkipDir
486489 }
0 commit comments