Skip to content

Commit c58e7a2

Browse files
authored
Merge pull request #28 from gitopia/hariom/fix-content-api
don't escape double quotes if empty path
2 parents c1abc99 + 3198c9f commit c58e7a2

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

utils/git.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ func GetFullCommitSha(repoPath, shortID string) (string, error) {
2222

2323
// LastCommitForPath returns the last commit which modified path for given revision.
2424
func 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.
3639
func 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.
5258
func 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

Comments
 (0)