Skip to content

Commit

Permalink
pkg/diff: respect global .gitignore
Browse files Browse the repository at this point in the history
Respect patterns from ~/.gitignore or core.excludesFile if present.
This avoids the "current git tree is dirty" in some circumstances.

Fixes joelanford#20

Signed-off-by: Lorenz Bauer <lmb@isovalent.com>
  • Loading branch information
lmb committed Jul 5, 2023
1 parent 7037613 commit c4100a4
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pkg/diff/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (

"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing"
"github.com/go-git/go-git/v5/plumbing/format/gitignore"
"golang.org/x/exp/apidiff"
"golang.org/x/tools/go/packages"

Expand Down Expand Up @@ -57,6 +58,11 @@ func Run(opts Options) (*Diff, error) {
return nil, fmt.Errorf("failed to set worktree filesystem interface: %v", err)
}

wt.Excludes, err = gitignore.LoadGlobalPatterns(wt.Filesystem)
if err != nil {
return nil, fmt.Errorf("failed to load global gitignore: %v", err)
}

if stat, err := wt.Status(); err != nil {
return nil, fmt.Errorf("failed to get git status: %w", err)
} else if !stat.IsClean() {
Expand Down

0 comments on commit c4100a4

Please sign in to comment.