Skip to content

Commit 6cea7a7

Browse files
darkowlzzlhchavez
andauthored
Make ssh commands used in the git smart transport compatible with libgit2 (#852)
* Fix ssh commands used in go SmartSubtransport Before the fix, the commands sent were of the form: ``` git-upload-pack "/bar/test-reponame" ``` This resulted in the git server returning error: `error parsing command: invalid git command` This change replaces the double quotes with single quotes: ``` git-upload-pack '/bar/test-reponame' ``` * Update ssh.go Co-authored-by: lhchavez <[email protected]>
1 parent 0e8009f commit 6cea7a7

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

ssh.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"net"
1818
"net/url"
1919
"runtime"
20+
"strings"
2021
"unsafe"
2122

2223
"golang.org/x/crypto/ssh"
@@ -74,6 +75,13 @@ func (t *sshSmartSubtransport) Action(urlString string, action SmartServiceActio
7475
return nil, err
7576
}
7677

78+
// Escape \ and '.
79+
uPath := strings.Replace(u.Path, `\`, `\\`, -1)
80+
uPath = strings.Replace(uPath, `'`, `\'`, -1)
81+
82+
// TODO: Add percentage decode similar to libgit2.
83+
// Refer: https://github.com/libgit2/libgit2/blob/358a60e1b46000ea99ef10b4dd709e92f75ff74b/src/str.c#L455-L481
84+
7785
var cmd string
7886
switch action {
7987
case SmartServiceActionUploadpackLs, SmartServiceActionUploadpack:
@@ -83,7 +91,7 @@ func (t *sshSmartSubtransport) Action(urlString string, action SmartServiceActio
8391
}
8492
t.Close()
8593
}
86-
cmd = fmt.Sprintf("git-upload-pack %q", u.Path)
94+
cmd = fmt.Sprintf("git-upload-pack '%s'", uPath)
8795

8896
case SmartServiceActionReceivepackLs, SmartServiceActionReceivepack:
8997
if t.currentStream != nil {
@@ -92,7 +100,7 @@ func (t *sshSmartSubtransport) Action(urlString string, action SmartServiceActio
92100
}
93101
t.Close()
94102
}
95-
cmd = fmt.Sprintf("git-receive-pack %q", u.Path)
103+
cmd = fmt.Sprintf("git-receive-pack '%s'", uPath)
96104

97105
default:
98106
return nil, fmt.Errorf("unexpected action: %v", action)

0 commit comments

Comments
 (0)