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