Skip to content

Commit

Permalink
make match file path relative to base directory (#579)
Browse files Browse the repository at this point in the history
  • Loading branch information
mmarchetti authored Dec 14, 2023
1 parent 7c9cfea commit 057a9bc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
14 changes: 10 additions & 4 deletions internal/bundles/gitignore/gitignore.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type ignoreFile struct {

type GitIgnoreList struct {
files []ignoreFile
base util.Path
cwd []string
fs afero.Fs
}
Expand All @@ -66,9 +67,10 @@ func New(cwd util.Path) GitIgnoreList {
files[0].abspath = toSplit(absPath.Path())

return GitIgnoreList{
files,
toSplit(absPath.Path()),
absPath.Fs(),
files: files,
base: cwd,
cwd: toSplit(absPath.Path()),
fs: absPath.Fs(),
}
}

Expand Down Expand Up @@ -194,11 +196,15 @@ func (ign *GitIgnoreList) append(path util.Path, dir []string) error {
if err != nil {
return err
}
relPath, err := path.Rel(ign.base)
if err != nil {
return err
}
match := &Match{
Source: MatchSourceFile,
Pattern: s,
glob: g,
FilePath: path.Path(),
FilePath: relPath.Path(),
Line: line,
}
ignf.matches = append(ignf.matches, match)
Expand Down
2 changes: 1 addition & 1 deletion internal/bundles/gitignore/gitignore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (s *GitIgnoreSuite) TestMatch() {
s.NotNil(m)
s.Equal(MatchSourceFile, m.Source)
s.Equal(".Rhistory", m.Pattern)
s.Equal(ignoreFilePath.Path(), m.FilePath)
s.Equal(".positignore", m.FilePath)
s.Equal(1, m.Line)

// Non-file matches don't include file info
Expand Down

0 comments on commit 057a9bc

Please sign in to comment.