Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add git untracked files to the list of files to scan #1425

Merged
merged 2 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
Loading