Make ssh commands used in the git smart transport compatible with libgit2 (#852) #855

Merged
github-actions[bot] merged 2 commits from cherry-pick-1432268967-release-1.0 into release-1.0 2021-11-09 08:27:06 -06:00
1 changed files with 10 additions and 2 deletions

12
ssh.go
View File

@ -17,6 +17,7 @@ import (
"net" "net"
"net/url" "net/url"
"runtime" "runtime"
"strings"
"unsafe" "unsafe"
"golang.org/x/crypto/ssh" "golang.org/x/crypto/ssh"
@ -74,6 +75,13 @@ func (t *sshSmartSubtransport) Action(urlString string, action SmartServiceActio
return nil, err 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 var cmd string
switch action { switch action {
case SmartServiceActionUploadpackLs, SmartServiceActionUploadpack: case SmartServiceActionUploadpackLs, SmartServiceActionUploadpack:
@ -83,7 +91,7 @@ func (t *sshSmartSubtransport) Action(urlString string, action SmartServiceActio
} }
t.Close() t.Close()
} }
cmd = fmt.Sprintf("git-upload-pack %q", u.Path) cmd = fmt.Sprintf("git-upload-pack '%s'", uPath)
case SmartServiceActionReceivepackLs, SmartServiceActionReceivepack: case SmartServiceActionReceivepackLs, SmartServiceActionReceivepack:
if t.currentStream != nil { if t.currentStream != nil {
@ -92,7 +100,7 @@ func (t *sshSmartSubtransport) Action(urlString string, action SmartServiceActio
} }
t.Close() t.Close()
} }
cmd = fmt.Sprintf("git-receive-pack %q", u.Path) cmd = fmt.Sprintf("git-receive-pack '%s'", uPath)
default: default:
return nil, fmt.Errorf("unexpected action: %v", action) return nil, fmt.Errorf("unexpected action: %v", action)