From d99d4cabfd7d3dfd09329bdab9d0be62db4c2f14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Fabianski?= Date: Thu, 7 Dec 2023 15:14:43 +0100 Subject: [PATCH] fix: add git untracked files to the list of files to scan (#1425) * fix: add git untracked files to the list of files to scan * chore: disable BEARER_IGNORE_GIT --- .envrc.example | 2 +- .../process/gitrepository/gitrepository.go | 1 - internal/git/tree.go | 29 +++++++++++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/.envrc.example b/.envrc.example index b2ec6d07e..4ea4849c4 100644 --- a/.envrc.example +++ b/.envrc.example @@ -11,4 +11,4 @@ export BEARER_DISABLE_VERSION_CHECK=true export BEARER_DISABLE_DEFAULT_RULES=true export BEARER_EXTERNAL_RULE_DIR=$PWD/../bearer-rules/rules export BEARER_FORCE=true -export BEARER_IGNORE_GIT=true +# export BEARER_IGNORE_GIT=true diff --git a/internal/commands/process/gitrepository/gitrepository.go b/internal/commands/process/gitrepository/gitrepository.go index d62a8dc2a..f99cf9686 100644 --- a/internal/commands/process/gitrepository/gitrepository.go +++ b/internal/commands/process/gitrepository/gitrepository.go @@ -226,7 +226,6 @@ func (repository *Repository) fileFor( } fullPath := filepath.Join(repository.targetPath, relativePath) - fileInfo, err := os.Stat(fullPath) if err != nil { log.Debug().Msgf("error getting file stat: %s, %s", fullPath, err) diff --git a/internal/git/tree.go b/internal/git/tree.go index 4badf91e6..198195709 100644 --- a/internal/git/tree.go +++ b/internal/git/tree.go @@ -10,6 +10,7 @@ import ( type TreeFile struct { Filename string `json:"filename" yaml:"filename"` SHA string `json:"sha" yaml:"sha"` + Other bool `json:"other" yaml:"other"` } func HasUncommittedChanges(rootDir string) (bool, error) { @@ -62,5 +63,33 @@ func ListTree(rootDir, commitSHA string) ([]TreeFile, error) { }, ) + if err != nil { + return result, nil + } + + err = captureCommand( + context.TODO(), + rootDir, + []string{"ls-files", "--others", "--exclude-standard", "-z"}, + func(stdout io.Reader) error { + stdoutBuf := bufio.NewReader(stdout) + for { + filename, err := stdoutBuf.ReadString(0) + if err == io.EOF { + break + } + if err != nil { + return err + } + + if len(filename) > 1 { + result = append(result, TreeFile{Filename: filename[:len(filename)-1], Other: true}) + } + } + + return nil + }, + ) + return result, err }