@@ -22,7 +22,10 @@ func GetFullCommitSha(repoPath, shortID string) (string, error) {
2222
2323// LastCommitForPath returns the last commit which modified path for given revision.
2424func LastCommitForPath (repoPath , revision string , path string ) (string , error ) {
25- cmd := exec .Command ("bash" , "-c" , "git log --pretty=%H --max-count=1 " + revision + " -- \" " + strings .ReplaceAll (path , "\" " , "\\ \" " )+ "\" " )
25+ if path != "" {
26+ path = "\" " + strings .ReplaceAll (path , "\" " , "\\ \" " ) + "\" "
27+ }
28+ cmd := exec .Command ("bash" , "-c" , "git log --pretty=%H --max-count=1 " + revision + " -- " + path )
2629 cmd .Dir = repoPath
2730 out , err := cmd .Output ()
2831 if err != nil {
@@ -34,7 +37,10 @@ func LastCommitForPath(repoPath, revision string, path string) (string, error) {
3437
3538// CommitHistory returns the commit history for given revision or path.
3639func CommitHistory (repoPath , revision string , path string , offset int , limit int ) ([]string , error ) {
37- cmd := exec .Command ("bash" , "-c" , "git log --pretty=%H --max-count=" + strconv .Itoa (limit )+ " --skip=" + strconv .Itoa (offset )+ " " + revision + " -- \" " + strings .ReplaceAll (path , "\" " , "\\ \" " )+ "\" " )
40+ if path != "" {
41+ path = "\" " + strings .ReplaceAll (path , "\" " , "\\ \" " ) + "\" "
42+ }
43+ cmd := exec .Command ("bash" , "-c" , "git log --pretty=%H --max-count=" + strconv .Itoa (limit )+ " --skip=" + strconv .Itoa (offset )+ " " + revision + " -- " + path )
3844 cmd .Dir = repoPath
3945 out , err := cmd .Output ()
4046 if err != nil {
@@ -50,7 +56,10 @@ func CommitHistory(repoPath, revision string, path string, offset int, limit int
5056
5157// CountCommits returns total count of commits.
5258func CountCommits (repoPath , revision string , path string ) (string , error ) {
53- cmd := exec .Command ("bash" , "-c" , "git rev-list --count " + revision + " -- \" " + strings .ReplaceAll (path , "\" " , "\\ \" " )+ "\" " )
59+ if path != "" {
60+ path = "\" " + strings .ReplaceAll (path , "\" " , "\\ \" " ) + "\" "
61+ }
62+ cmd := exec .Command ("bash" , "-c" , "git rev-list --count " + revision + " -- " + path )
5463 cmd .Dir = repoPath
5564 out , err := cmd .Output ()
5665 if err != nil {
0 commit comments