Skip to content

Commit

Permalink
Respect .chezmoiignore in Entry.Evaluate
Browse files Browse the repository at this point in the history
  • Loading branch information
twpayne committed Jan 12, 2019
1 parent 4b7c9c8 commit 4612ada
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/chezmoi/chezmoi.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type templateFuncError struct {
type Entry interface {
Apply(fs vfs.FS, targetDir string, ignore func(string) bool, umask os.FileMode, mutator Mutator) error
ConcreteValue(targetDir, sourceDir string, recursive bool) (interface{}, error)
Evaluate() error
Evaluate(ignore func(string) bool) error
SourceName() string
TargetName() string
archive(w *tar.Writer, headerTemplate *tar.Header, umask os.FileMode) error
Expand Down
7 changes: 5 additions & 2 deletions lib/chezmoi/dir.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,12 @@ func (d *Dir) ConcreteValue(targetDir, sourceDir string, recursive bool) (interf
}

// Evaluate evaluates all entries in d.
func (d *Dir) Evaluate() error {
func (d *Dir) Evaluate(ignore func(string) bool) error {
if ignore(d.targetName) {
return nil
}
for _, entryName := range sortedEntryNames(d.Entries) {
if err := d.Entries[entryName].Evaluate(); err != nil {
if err := d.Entries[entryName].Evaluate(ignore); err != nil {
return err
}
}
Expand Down
5 changes: 4 additions & 1 deletion lib/chezmoi/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,10 @@ func (f *File) ConcreteValue(targetDir, sourceDir string, recursive bool) (inter
}

// Evaluate evaluates f's contents.
func (f *File) Evaluate() error {
func (f *File) Evaluate(ignore func(string) bool) error {
if ignore(f.targetName) {
return nil
}
_, err := f.Contents()
return err
}
Expand Down
5 changes: 4 additions & 1 deletion lib/chezmoi/symlink.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ func (s *Symlink) ConcreteValue(targetDir, sourceDir string, recursive bool) (in
}

// Evaluate evaluates s's target.
func (s *Symlink) Evaluate() error {
func (s *Symlink) Evaluate(ignore func(string) bool) error {
if ignore(s.targetName) {
return nil
}
_, err := s.Linkname()
return err
}
Expand Down
2 changes: 1 addition & 1 deletion lib/chezmoi/target_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ func (ts *TargetState) ConcreteValue(recursive bool) (interface{}, error) {
// Evaluate evaluates all of the entries in ts.
func (ts *TargetState) Evaluate() error {
for _, entryName := range sortedEntryNames(ts.Entries) {
if err := ts.Entries[entryName].Evaluate(); err != nil {
if err := ts.Entries[entryName].Evaluate(ts.TargetIgnore.Match); err != nil {
return err
}
}
Expand Down

0 comments on commit 4612ada

Please sign in to comment.