@@ -51,6 +51,8 @@ type Repository interface {
5151 pushRefSpec (refSpec string ) error
5252}
5353
54+ const RootPath = "."
55+
5456// LocalRepository represents a git repository.
5557type LocalRepository struct {
5658 Dir string
@@ -335,18 +337,13 @@ func (r *LocalRepository) GetCommitsForPathsSinceCommit(paths []string, sinceCom
335337 // In theory, we should be able to remember our "current" commit for each
336338 // path, but that's likely to be significantly more complex.
337339 for _ , candidatePath := range paths {
338- currentPathHash , err := getHashForPathOrEmpty (commit , candidatePath )
339- if err != nil {
340- return err
341- }
342- parentPathHash , err := getHashForPathOrEmpty (parentCommit , candidatePath )
340+ matching , err := commitMatchesPath (candidatePath , commit , parentCommit )
343341 if err != nil {
344342 return err
345343 }
346344 // If we've found a change (including a path being added or removed),
347345 // add it to our list of commits and proceed to the next commit.
348- if currentPathHash != parentPathHash {
349-
346+ if matching {
350347 commits = append (commits , & Commit {
351348 Hash : commit .Hash ,
352349 Message : commit .Message ,
@@ -367,6 +364,21 @@ func (r *LocalRepository) GetCommitsForPathsSinceCommit(paths []string, sinceCom
367364 return commits , nil
368365}
369366
367+ func commitMatchesPath (path string , commit * object.Commit , parentCommit * object.Commit ) (bool , error ) {
368+ if path == RootPath {
369+ return true , nil
370+ }
371+ currentPathHash , err := getHashForPathOrEmpty (commit , path )
372+ if err != nil {
373+ return false , err
374+ }
375+ parentPathHash , err := getHashForPathOrEmpty (parentCommit , path )
376+ if err != nil {
377+ return false , err
378+ }
379+ return currentPathHash != parentPathHash , nil
380+ }
381+
370382// getHashForPathOrEmpty returns the hash for a path at a given commit, or an
371383// empty string if the path (file or directory) did not exist.
372384func getHashForPathOrEmpty (commit * object.Commit , path string ) (string , error ) {
0 commit comments