forked from coop-cloud/abra
fix: maybe more robust gitignore checks
This commit is contained in:
parent
665396b679
commit
85a543afac
|
@ -51,7 +51,10 @@ func IsClean(recipeName string) (bool, error) {
|
|||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
worktree.Excludes = append(patterns, worktree.Excludes...)
|
||||
|
||||
if len(patterns) > 0 {
|
||||
worktree.Excludes = append(patterns, worktree.Excludes...)
|
||||
}
|
||||
|
||||
status, err := worktree.Status()
|
||||
if err != nil {
|
||||
|
@ -95,9 +98,12 @@ func parseGitConfig() (*gitConfigPkg.Config, error) {
|
|||
}
|
||||
|
||||
globalGitConfig := filepath.Join(usr.HomeDir, ".gitconfig")
|
||||
if _, err := os.Stat(globalGitConfig); os.IsNotExist(err) {
|
||||
logrus.Debugf("no %s exists, not reading any global git ignore config", globalGitConfig)
|
||||
return cfg, nil
|
||||
if _, err := os.Stat(globalGitConfig); err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
logrus.Debugf("no %s exists, not reading any global git ignore config", globalGitConfig)
|
||||
return cfg, nil
|
||||
}
|
||||
return cfg, err
|
||||
}
|
||||
|
||||
b, err := ioutil.ReadFile(globalGitConfig)
|
||||
|
@ -126,17 +132,26 @@ func getExcludesFile(cfg *gitConfigPkg.Config) string {
|
|||
}
|
||||
|
||||
func parseExcludesFile(excludesfile string) ([]gitignore.Pattern, error) {
|
||||
var ps []gitignore.Pattern
|
||||
|
||||
excludesfile, err := expandTilde(excludesfile)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if _, err := os.Stat(excludesfile); err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
logrus.Debugf("no %s exists, skipping reading ignore paths", excludesfile)
|
||||
return ps, nil
|
||||
}
|
||||
return ps, err
|
||||
}
|
||||
|
||||
data, err := ioutil.ReadFile(excludesfile)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var ps []gitignore.Pattern
|
||||
for _, s := range strings.Split(string(data), "\n") {
|
||||
if !strings.HasPrefix(s, "#") && len(strings.TrimSpace(s)) > 0 {
|
||||
ps = append(ps, gitignore.ParsePattern(s, nil))
|
||||
|
@ -150,11 +165,13 @@ func expandTilde(path string) (string, error) {
|
|||
if !strings.HasPrefix(path, "~") {
|
||||
return path, nil
|
||||
}
|
||||
|
||||
var paths []string
|
||||
u, err := user.Current()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
for _, p := range strings.Split(path, string(filepath.Separator)) {
|
||||
if p == "~" {
|
||||
paths = append(paths, u.HomeDir)
|
||||
|
@ -162,5 +179,6 @@ func expandTilde(path string) (string, error) {
|
|||
paths = append(paths, p)
|
||||
}
|
||||
}
|
||||
|
||||
return "/" + filepath.Join(paths...), nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue