diff --git a/internal/bundles/gitignore/gitignore.go b/internal/bundles/gitignore/gitignore.go index d04d27b8f..f853e8f6e 100644 --- a/internal/bundles/gitignore/gitignore.go +++ b/internal/bundles/gitignore/gitignore.go @@ -44,6 +44,7 @@ type ignoreFile struct { type GitIgnoreList struct { files []ignoreFile + base util.Path cwd []string fs afero.Fs } @@ -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(), } } @@ -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) diff --git a/internal/bundles/gitignore/gitignore_test.go b/internal/bundles/gitignore/gitignore_test.go index ae011a89b..0666bbd63 100644 --- a/internal/bundles/gitignore/gitignore_test.go +++ b/internal/bundles/gitignore/gitignore_test.go @@ -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