helpers/archives/path_check_helper.go (30 lines of code) (raw):

package archives import ( "errors" "fmt" "os" "path/filepath" "strings" "github.com/sirupsen/logrus" ) func isPathAGitDirectory(path string) bool { parts := strings.Split(filepath.Clean(path), string(filepath.Separator)) if len(parts) > 0 && parts[0] == ".git" { return true } return false } func errorIfGitDirectory(path string) *os.PathError { if !isPathAGitDirectory(path) { return nil } return &os.PathError{ Op: ".git inside of archive", Path: path, Err: errors.New("trying to archive or extract .git path"), } } func printGitArchiveWarning(operation string) { logrus.Warn(fmt.Sprintf("Part of .git directory is on the list of files to %s", operation)) logrus.Warn("This may introduce unexpected problems") }