--- a/hg/hg.go Mon Sep 09 23:11:01 2019 -0500
+++ b/hg/hg.go Tue Sep 10 01:37:08 2019 -0500
@@ -5,34 +5,46 @@
-func common(cmd *exec.Cmd) *exec.Cmd {
- cmd.Env = append(cmd.Env, os.Environ()...)
- cmd.Env = append(cmd.Env, "HGRCPATH=/dev/null")
-func Init(path string) *exec.Cmd {
- return common(exec.Command("hg", "init", path))
+func (c *Command) Setup() { + c.cmd.Env = append(os.Environ(), "HGRCPATH=/dev/null") +func (c *Command) Teardown() { +func (c *Command) Cmd() *exec.Cmd { -func Serve(path string, writeable bool) *exec.Cmd {
+func Init(path string) *Command { + cmd: exec.Command("hg", "init", path),
- return common(exec.Command("hg", args...))
-func Add(path string, files ...string) *exec.Cmd {
+func Serve(path string, writeable bool) *Command { + cmd: exec.Command("hg", "-R", path, "serve", "--stdio"), +func Add(path string, files ...string) *Command { args := append([]string{"add", "--cwd", path}, files...)
- return common(exec.Command("hg", args...))
+ cmd: exec.Command("hg", args...), -func Commit(path, username, message string) *exec.Cmd {
+func Commit(path, username, message string) *Command { @@ -40,5 +52,7 @@
- return common(exec.Command("hg", args...))
+ cmd: exec.Command("hg", args...), --- a/setup/command.go Mon Sep 09 23:11:01 2019 -0500
+++ b/setup/command.go Tue Sep 10 01:37:08 2019 -0500
@@ -5,7 +5,6 @@
@@ -21,8 +20,8 @@
commitMessage = "initial revision"
-func runCmd(cmd *exec.Cmd) error {
- output, err := cmd.CombinedOutput()
+func runCmd(cmd *hg.Command) error { + output, err := cmd.Cmd().CombinedOutput() fmt.Printf("%s\n", output)
--- a/ssh/commands/run.go Mon Sep 09 23:11:01 2019 -0500
+++ b/ssh/commands/run.go Tue Sep 10 01:37:08 2019 -0500
@@ -2,18 +2,23 @@
log "github.com/sirupsen/logrus"
"golang.org/x/crypto/ssh"
+ "bitbucket.org/rw_grim/hgkeeper/hg" -func run(cmd *exec.Cmd, conn ssh.Channel, serverConn *ssh.ServerConn, req *ssh.Request) error {
+func run(hgCmd *hg.Command, conn ssh.Channel, serverConn *ssh.ServerConn, req *ssh.Request) error { if err := cmd.Wait(); err != nil {
"%s command %q failed: %v",
@@ -68,6 +73,8 @@
if err := cmd.Start(); err != nil {