diff --git a/pkg/tdglib/todogenerator.go b/pkg/tdglib/todogenerator.go index 79b0bf4d132ebae5867d7f8b291184d1535cf9b8..97cc91bc3f34886e245101a8ed08d85b258456ad 100644 --- a/pkg/tdglib/todogenerator.go +++ b/pkg/tdglib/todogenerator.go @@ -73,9 +73,35 @@ type ToDoGenerator struct { semaphore chan bool } +// Marks root directory as safe so that Git commands can run +func markRootAsSafeForGit(root string) { + for strings.HasSuffix(root, "/.") || strings.HasSuffix(root, "/") { + root = strings.TrimSuffix(root, "/.") + root = strings.TrimSuffix(root, "/") + } + + log.Printf("Marking '%v' as safe", root) + command := "git" + args := []string{"config", "--global", "--add", "safe.directory", root} + + cmd := exec.Command(command, args...) + out, err := cmd.Output() + if out != nil { + log.Println(out) + } + if err != nil { + log.Printf("Error running git command: %v\n", err) + } +} + // NewToDoGenerator creates new generator for a source root func NewToDoGenerator(root string, include []string, exclude []string, blameFlag bool, minWords, minChars, concurrency int) *ToDoGenerator { log.Printf("Using source code root %v", root) + + if blameFlag { + markRootAsSafeForGit(root) + } + log.Printf("Using %v include filters", include) ifilters := make([]*regexp.Regexp, 0, len(include)) for _, f := range include {