Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gitignore #865

Closed
mac2000 opened this issue Oct 25, 2022 · 2 comments · Fixed by #1033
Closed

gitignore #865

mac2000 opened this issue Oct 25, 2022 · 2 comments · Fixed by #1033

Comments

@mac2000
Copy link
Contributor

mac2000 commented Oct 25, 2022

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Description

gitignore support

Problem to be Addressed

Scanning of filesystem may become a challenging task because there are many folders which are not expected to be scanned, especially folders like node_modules which can contain quadrillion of files

Description of the Preferred Solution

Whenever we are going to scan file or dig into directory we should traverse directories tree to see if there is gitignore somewhere and check if that file or directory isn't there

Something like this one (should be optimized, but describes the idea):

package main

import (
	"fmt"
	"log"
	"os"
	"path/filepath"

	ignore "github.com/sabhiram/go-gitignore"
)

func main() {
	// recursive iteration over `os.Args[1]` path
	filepath.Walk(os.Args[1], func(path string, info os.FileInfo, err error) error {
		if err != nil {
			log.Println(err)
		}

		// path == "/Users/mac/Desktop/demo/obj/Debug/net6.0/logging.AssemblyInfo.cs"
		// info.Name() == "logging.AssemblyInfo.cs"

		// inner, walk up till root or found gitignore
		var gitignore *ignore.GitIgnore
		parent := path
		for {
			gitignore, _ = ignore.CompileIgnoreFile(filepath.Join(parent, ".gitignore"))
			if gitignore != nil {
				// gitignore found, breaking loop
				break
			}
			if parent == filepath.Dir(parent) {
				// we are at root and there is no more parents, breaking loop
				break
			} else {
				parent = filepath.Dir(parent)
			}
		}

		ignored := false
		if gitignore != nil {
			ignored = gitignore.MatchesPath(path)
		}
		fmt.Printf("%v %s\n", ignored, path)
		return nil
	})
}

Additional Context

image

References

@gukoff
Copy link

gukoff commented Aug 17, 2023

@dustin-decker @mac2000

How does this feature work now?

Should one explicitly pass the .gitignore file to the --exclude-paths option?
If yes:

  • Are they fully compatible?
  • Can one pas multiple .gitignore files? What if they are in the nested folders in the repository (and their paths are relative to this nested folder)?

@mac2000
Copy link
Contributor Author

mac2000 commented Aug 17, 2023

@gukoff take a closer look at #1033 pull request

at the very end issue was solved without introducing new concept of gitignore files and instead by

bringing missing exclude paths option to git scan

plus small fix for empty lines that prevent's skipping files with space in name

so technically in the first place it was the fix for #536 and by consequence it also solved this issue as well

hope that helps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
2 participants