summaryrefslogtreecommitdiff
path: root/ssh.go
diff options
context:
space:
mode:
authorSunny <[email protected]>2021-11-08 01:50:56 +0530
committerGitHub <[email protected]>2021-11-07 12:20:56 -0800
commit6cea7a7a59f44e0e72ca577fbea65a042b3fb26b (patch)
tree4675859441f4e04fd7576e8a7b26ca74921586d2 /ssh.go
parent0e8009f00a65034d196c67b1cdd82af6f12c34d3 (diff)
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]>
Diffstat (limited to 'ssh.go')
-rw-r--r--ssh.go12
1 files changed, 10 insertions, 2 deletions
diff --git a/ssh.go b/ssh.go
index dd2725e..0581ca0 100644
--- a/ssh.go
+++ b/ssh.go
@@ -17,6 +17,7 @@ import (
"net"
"net/url"
"runtime"
+ "strings"
"unsafe"
"golang.org/x/crypto/ssh"
@@ -74,6 +75,13 @@ func (t *sshSmartSubtransport) Action(urlString string, action SmartServiceActio
return nil, err
}
+ // Escape \ and '.
+ uPath := strings.Replace(u.Path, `\`, `\\`, -1)
+ uPath = strings.Replace(uPath, `'`, `\'`, -1)
+
+ // TODO: Add percentage decode similar to libgit2.
+ // Refer: https://github.com/libgit2/libgit2/blob/358a60e1b46000ea99ef10b4dd709e92f75ff74b/src/str.c#L455-L481
+
var cmd string
switch action {
case SmartServiceActionUploadpackLs, SmartServiceActionUploadpack:
@@ -83,7 +91,7 @@ func (t *sshSmartSubtransport) Action(urlString string, action SmartServiceActio
}
t.Close()
}
- cmd = fmt.Sprintf("git-upload-pack %q", u.Path)
+ cmd = fmt.Sprintf("git-upload-pack '%s'", uPath)
case SmartServiceActionReceivepackLs, SmartServiceActionReceivepack:
if t.currentStream != nil {
@@ -92,7 +100,7 @@ func (t *sshSmartSubtransport) Action(urlString string, action SmartServiceActio
}
t.Close()
}
- cmd = fmt.Sprintf("git-receive-pack %q", u.Path)
+ cmd = fmt.Sprintf("git-receive-pack '%s'", uPath)
default:
return nil, fmt.Errorf("unexpected action: %v", action)