-
Notifications
You must be signed in to change notification settings - Fork 702
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
AddWithOptions(All:true) doesn't respect .gitignore #597
Comments
Have fixed the
I hadn't attached the screenshot from the execution, here it is |
I have a gitignore as follows $ cat .gitignore
# Local .terraform directories
.terraform/
# .tfplan files
*.tfplan
*.tfplan.* I'm not seeing the gitignore file being used at all in either In In so once again the I'm now stepping through my |
Adding my ignore patterns to the Worktree explicitly before calling // Add the ignore patterns that aren't benig read from the .gitignore file
w.Excludes = append(w.Excludes, gitignore.ParsePattern(".terraform/", nil))
w.Excludes = append(w.Excludes, gitignore.ParsePattern("*.tfplan", nil))
w.Excludes = append(w.Excludes, gitignore.ParsePattern("*.tfplan.*", nil)) edit: I also have the set Which is pretty lame, it should really be reading my gitignore file. |
Here is a little snippet that parses an existing func AddGitignoreToWorktree(wt *git.Worktree, repositoryPath string) {
readFile, err := os.Open(filepath.Join(repositoryPath, ".gitignore"))
defer readFile.Close()
if err != nil {
fmt.Println("Failed to read .gitignore: %s", err.Error())
return
}
fileScanner := bufio.NewScanner(readFile)
fileScanner.Split(bufio.ScanLines)
for fileScanner.Scan() {
ignorePattern := fileScanner.Text()
fmt.Println("add %s from .gitignore to ignore list", ignorePattern)
wt.Excludes = append(wt.Excludes, gitignore.ParsePattern(ignorePattern, nil))
}
} Use it just before calling AddGitignoreToWorktree(worktree, repo.Path())
fmt.Println(fmt.Sprint(worktree.Status()))
if err = worktree.AddWithOptions(&git.AddOptions{All: true}); err != nil {
return "", err
} Is this behavior intentional or are there contributions accepted to fix it? Maybe with a new parameter? git.AddOptions{
All: true,
ExcludeGitignore: true, // defaults to false?
} |
Here is the repo I'll be using as an example,
Here's the code that I'm running to test the AddWithOptions(All:true)
After running
main.go
this is what I get , even though the worker tree is empty (nil output in the first screenshot)The gitignore contains this,
Is this expected behavior? How do I force AddWithOptions(all:true) to respect .gigignore?
The text was updated successfully, but these errors were encountered: