Skip to content

Commit c1abc99

Browse files
authored
Merge pull request #27 from gitopia/escape-path
Escape double quotes in all path names
2 parents 5c7d5d1 + 6882614 commit c1abc99

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

utils/git.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ 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+" -- \""+path+"\"")
25+
cmd := exec.Command("bash", "-c", "git log --pretty=%H --max-count=1 "+revision+" -- \""+strings.ReplaceAll(path, "\"", "\\\"")+"\"")
2626
cmd.Dir = repoPath
2727
out, err := cmd.Output()
2828
if err != nil {
@@ -34,7 +34,7 @@ func LastCommitForPath(repoPath, revision string, path string) (string, error) {
3434

3535
// CommitHistory returns the commit history for given revision or path.
3636
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+" -- "+path)
37+
cmd := exec.Command("bash", "-c", "git log --pretty=%H --max-count="+strconv.Itoa(limit)+" --skip="+strconv.Itoa(offset)+" "+revision+" -- \""+strings.ReplaceAll(path, "\"", "\\\"")+"\"")
3838
cmd.Dir = repoPath
3939
out, err := cmd.Output()
4040
if err != nil {
@@ -50,7 +50,7 @@ func CommitHistory(repoPath, revision string, path string, offset int, limit int
5050

5151
// CountCommits returns total count of commits.
5252
func CountCommits(repoPath, revision string, path string) (string, error) {
53-
cmd := exec.Command("bash", "-c", "git rev-list --count "+revision+" -- "+path)
53+
cmd := exec.Command("bash", "-c", "git rev-list --count "+revision+" -- \""+strings.ReplaceAll(path, "\"", "\\\"")+"\"")
5454
cmd.Dir = repoPath
5555
out, err := cmd.Output()
5656
if err != nil {

0 commit comments

Comments
 (0)