Skip to content
This repository has been archived by the owner on Oct 10, 2023. It is now read-only.

fix: prevent skipping current folder if only a single file needs to be ignored (#99) #100

Merged
merged 1 commit into from
Jul 4, 2022

Conversation

lstocchi
Copy link
Collaborator

@lstocchi lstocchi commented Jul 1, 2022

This fixes #99

The problem was that if a single file matched a rule in gitignore, the whole folder was skipped. So if the file was in the root, no component were detected as only the files discovered until that moment would be used.

E.g I have this treeview

root 
 | -  .classpath (file)
 | -  .settings  (file)
 | -  src/  (folder)
 | -  test/ (folder)

The gitignore is like

.classpath
....

When Alizer walks on the .classpath file, it matches the rule in gitignore and all folder is skipped.
Code in path lib which caused the misbehaviour

for _, name := range names {
		filename := Join(path, name)
		fileInfo, err := lstat(filename)
		err = walk(filename, fileInfo, walkFn) -> here i returned a skipDir even if it was a file
		if err != nil {
			if !fileInfo.IsDir() || err != SkipDir { --> it failed here
				return err
			}
		}		
	}

With this patch it skips items in the right way. Returns nil if it's a file or skipDir if it's a directory.

…e ignored (redhat-developer#99)

Signed-off-by: Luca Stocchi <lstocchi@redhat.com>
@lstocchi lstocchi requested a review from jeffmaury July 1, 2022 13:01
Copy link
Member

@jeffmaury jeffmaury left a comment

Choose a reason for hiding this comment

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

LGTM

@lstocchi lstocchi merged commit 9dc18c7 into redhat-developer:main Jul 4, 2022
@lstocchi lstocchi deleted the i99 branch July 4, 2022 14:28
@lstocchi
Copy link
Collaborator Author

lstocchi commented Jul 4, 2022

@yangcao77, @kadel , @feloy FYI this solves an important bug on project that have a .gitignore file in them.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Golang impl read .gitignore file incorrectly
2 participants