Skip to content

Commit

Permalink
fix: add git untracked files to the list of files to scan (#1425)
Browse files Browse the repository at this point in the history
* fix: add git untracked files to the list of files to scan

* chore: disable BEARER_IGNORE_GIT
  • Loading branch information
cfabianski committed Dec 7, 2023
1 parent 63a708f commit d99d4ca
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .envrc.example
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 0 additions & 1 deletion internal/commands/process/gitrepository/gitrepository.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
29 changes: 29 additions & 0 deletions internal/git/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
}

0 comments on commit d99d4ca

Please sign in to comment.