Skip to content

pkg/diff: respect global .gitignore#25

Merged
joelanford merged 1 commit intojoelanford:mainfrom
lmb:support-global-gitignore
Aug 28, 2023
Merged

pkg/diff: respect global .gitignore#25
joelanford merged 1 commit intojoelanford:mainfrom
lmb:support-global-gitignore

Conversation

@lmb
Copy link
Contributor

@lmb lmb commented Jul 5, 2023

Respect patterns from ~/.gitignore or core.excludesFile if present. This avoids the "current git tree is dirty" in some circumstances.

Fixes #20

@lmb
Copy link
Contributor Author

lmb commented Jul 24, 2023

@joelanford can you take a look at the PR? Thanks!

pkg/diff/run.go Outdated
Comment on lines +61 to +77
wt.Excludes, err = gitignore.LoadGlobalPatterns(wt.Filesystem)
if err != nil {
return nil, fmt.Errorf("failed to load global gitignore: %v", err)
}

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few things:

  1. We should append to wt.Excludes, not override it.
  2. The filesystem passed in should be the OS root (not the repo path)

See the following for an example: https://github.com/apache/skywalking-eyes/blob/5dfa68f93380a5e57259faaf95088b7f133b5778/pkg/header/check.go#L84-L94

Respect patterns from ~/.gitignore, /etc/gitconfig 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>
@lmb lmb force-pushed the support-global-gitignore branch from c4100a4 to bc12a29 Compare July 31, 2023 09:22
@lmb lmb requested a review from joelanford July 31, 2023 09:23
@joelanford
Copy link
Owner

Looks great! Thanks!

@joelanford joelanford merged commit 9f8ae1c into joelanford:main Aug 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

git operation not respecting gitignore

2 participants