--- a/commands/commands.go Tue Jul 23 16:52:18 2019 -0500
+++ b/commands/commands.go Sun Sep 08 04:55:34 2019 -0500
@@ -23,7 +23,7 @@
- Run(conn ssh.Channel, serverConn *ssh.ServerConn, req *ssh.Request) error
+ Run(conn ssh.Channel, serverConn *ssh.ServerConn, username string, req *ssh.Request) error CheckAccess(access *access.Access, username string) bool
@@ -46,7 +46,7 @@
return values, ctx.Command(), nil
-func Find(cmd, reposPath string) (Command, error) {
+func Find(cmd, reposPath string, access *access.Access) (Command, error) { values, pcmd, err := parse(cmd)
@@ -54,9 +54,9 @@
- return NewServe(reposPath, values.Hg.Repo), nil
+ return NewServe(reposPath, values.Hg.Repo, access), nil - return NewInit(reposPath, values.Hg.Init.Repo), nil
+ return NewInit(reposPath, values.Hg.Init.Repo, access), nil return nil, fmt.Errorf("unknown command %s", cmd)
--- a/commands/init.go Tue Jul 23 16:52:18 2019 -0500
+++ b/commands/init.go Sun Sep 08 04:55:34 2019 -0500
@@ -11,16 +11,18 @@
-func NewInit(reposPath, repoName string) *Init {
+func NewInit(reposPath, repoName string, access *access.Access) *Init { repoPath: filepath.Join(reposPath, repoName),
-func (i *Init) Run(conn ssh.Channel, serverConn *ssh.ServerConn, req *ssh.Request) error {
+func (i *Init) Run(conn ssh.Channel, serverConn *ssh.ServerConn, username string, req *ssh.Request) error { return run(hg.Init(i.repoPath), conn, serverConn, req)
--- a/commands/serve.go Tue Jul 23 16:52:18 2019 -0500
+++ b/commands/serve.go Sun Sep 08 04:55:34 2019 -0500
@@ -12,17 +12,21 @@
-func NewServe(reposPath, repoName string) *Serve {
+func NewServe(reposPath, repoName string, access *access.Access) *Serve { repoPath: filepath.Join(reposPath, repoName),
-func (s *Serve) Run(conn ssh.Channel, serverConn *ssh.ServerConn, req *ssh.Request) error {
- return run(hg.Serve(s.repoPath), conn, serverConn, req)
+func (s *Serve) Run(conn ssh.Channel, serverConn *ssh.ServerConn, username string, req *ssh.Request) error { + writeable := s.access.Global.CanWrite(username) + return run(hg.Serve(s.repoPath, writeable), conn, serverConn, req) func (s *Serve) CheckAccess(access *access.Access, username string) bool {
--- a/hg/hg.go Tue Jul 23 16:52:18 2019 -0500
+++ b/hg/hg.go Sun Sep 08 04:55:34 2019 -0500
@@ -15,8 +15,18 @@
return common(exec.Command("hg", "init", path))
-func Serve(path string) *exec.Cmd {
- return common(exec.Command("hg", "-R", path, "serve", "--stdio"))
+func Serve(path string, writeable bool) *exec.Cmd { + args = append(args, "--config", "hooks.pretxnchangegroup=/bin/false") + return common(exec.Command("hg", args...)) func Add(path string, files ...string) *exec.Cmd {
--- a/ssh/server.go Tue Jul 23 16:52:18 2019 -0500
+++ b/ssh/server.go Sun Sep 08 04:55:34 2019 -0500
@@ -124,7 +124,7 @@
log.Infof("%s requested command %q", serverConn.RemoteAddr(), rawCmd)
- cmd, err := commands.Find(rawCmd, s.reposPath)
+ cmd, err := commands.Find(rawCmd, s.reposPath, s.a) log.Warnf("failed to find command for %q, %v", rawCmd, err)
@@ -142,7 +142,7 @@
- if err := cmd.Run(conn, serverConn, req); err != nil {
+ if err := cmd.Run(conn, serverConn, username, req); err != nil { log.Warnf("%s command %q failed: %v", serverConn.RemoteAddr(), rawCmd, err)