mirror of
https://github.com/grdl/git-get.git
synced 2026-02-10 10:14:25 +00:00
Load gitignore patterns also from files declared in excludesfile
This commit is contained in:
1
go.mod
1
go.mod
@@ -3,6 +3,7 @@ module git-get
|
|||||||
go 1.14
|
go 1.14
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
github.com/go-git/go-billy/v5 v5.0.0
|
||||||
github.com/go-git/go-git/v5 v5.1.0
|
github.com/go-git/go-git/v5 v5.1.0
|
||||||
github.com/karrick/godirwalk v1.15.6
|
github.com/karrick/godirwalk v1.15.6
|
||||||
github.com/mitchellh/go-homedir v1.1.0
|
github.com/mitchellh/go-homedir v1.1.0
|
||||||
|
|||||||
@@ -4,6 +4,10 @@ import (
|
|||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/go-git/go-billy/v5/osfs"
|
||||||
|
|
||||||
|
"github.com/go-git/go-git/v5/plumbing/format/gitignore"
|
||||||
|
|
||||||
"github.com/go-git/go-git/v5"
|
"github.com/go-git/go-git/v5"
|
||||||
"github.com/go-git/go-git/v5/plumbing"
|
"github.com/go-git/go-git/v5/plumbing"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
@@ -28,6 +32,21 @@ func (r *Repo) LoadStatus() error {
|
|||||||
return errors.Wrap(err, "Failed getting worktree")
|
return errors.Wrap(err, "Failed getting worktree")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// worktree.Status doesn't load gitignore patterns that may be defined outside of .gitignore file using excludesfile
|
||||||
|
// We need to load them explicitly here
|
||||||
|
// TODO: variables are not expanded so if excludesfile is declared like "~/gitignore_global" or "$HOME/gitignore_global", this will fail to open it
|
||||||
|
globalPatterns, err := gitignore.LoadGlobalPatterns(osfs.New(""))
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "Failed loading global gitignore patterns")
|
||||||
|
}
|
||||||
|
wt.Excludes = append(wt.Excludes, globalPatterns...)
|
||||||
|
|
||||||
|
systemPatterns, err := gitignore.LoadSystemPatterns(osfs.New(""))
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "Failed loading system gitignore patterns")
|
||||||
|
}
|
||||||
|
wt.Excludes = append(wt.Excludes, systemPatterns...)
|
||||||
|
|
||||||
status, err := wt.Status()
|
status, err := wt.Status()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "Failed getting worktree status")
|
return errors.Wrap(err, "Failed getting worktree status")
|
||||||
|
|||||||
@@ -146,3 +146,5 @@ func TestStatus(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: test branch status when tracking a local branch
|
// TODO: test branch status when tracking a local branch
|
||||||
|
// TODO: newRepoWithGlobalGitignore
|
||||||
|
// TODO: newRepoWithGlobalGitignoreSymlink
|
||||||
|
|||||||
Reference in New Issue
Block a user