grim/hgkeeper

8275959b76f0
Parents 2e68e9d4652d
Children ab97e6944829
Add support for specifying which mercurial executable to use
  • +3 -2
    globals/globals.go
  • +23 -5
    hg/hg.go
  • +5 -0
    main.go
  • --- a/globals/globals.go Wed Jan 04 07:29:10 2023 -0600
    +++ b/globals/globals.go Tue Mar 14 18:00:18 2023 -0500
    @@ -1,6 +1,7 @@
    package globals
    type Globals struct {
    - ReposPath string `kong:"flag,name='repos-path',env='HGK_REPOS_PATH',default='repos',help='the directory where the repositories are stored'"`
    - AdminRepo string `kong:"flag,name='admin-repo',env='HGK_ADMIN_REPO',default='hgkeeper',help='the name of the admin repo to create/use'"`
    + HgExecutable string `kong:"flag,name='hg-exe',env='HGK_HG_EXE',default='hg',help='The hg executable to use. This can be a relative or absolute path.'"`
    + ReposPath string `kong:"flag,name='repos-path',env='HGK_REPOS_PATH',default='repos',help='the directory where the repositories are stored'"`
    + AdminRepo string `kong:"flag,name='admin-repo',env='HGK_ADMIN_REPO',default='hgkeeper',help='the name of the admin repo to create/use'"`
    }
    --- a/hg/hg.go Wed Jan 04 07:29:10 2023 -0600
    +++ b/hg/hg.go Tue Mar 14 18:00:18 2023 -0500
    @@ -1,6 +1,7 @@
    package hg
    import (
    + "errors"
    "io"
    "os"
    "os/exec"
    @@ -13,12 +14,29 @@
    "keep.imfreedom.org/grim/hgkeeper/access"
    )
    +var (
    + hgExe string
    +)
    +
    type Command struct {
    cmd *exec.Cmd
    tmpHgrc string
    writeable bool
    }
    +func SetExe(path string) error {
    + path, err := exec.LookPath(path)
    + if err != nil {
    + if !errors.Is(err, exec.ErrDot) {
    + return err
    + }
    + }
    +
    + hgExe = path
    +
    + return nil
    +}
    +
    func (c *Command) Setup(repoName, username string) error {
    hgrc, err := createHgrc(c.writeable)
    if err != nil {
    @@ -127,13 +145,13 @@
    func Init(path string) *Command {
    return &Command{
    - cmd: exec.Command("hg", "init", path),
    + cmd: exec.Command(hgExe, "init", path),
    }
    }
    func Serve(path string, writeable bool) *Command {
    return &Command{
    - cmd: exec.Command("hg", "-R", path, "serve", "--stdio"),
    + cmd: exec.Command(hgExe, "-R", path, "serve", "--stdio"),
    writeable: writeable,
    }
    }
    @@ -142,7 +160,7 @@
    args := append([]string{"add", "--cwd", path}, files...)
    return &Command{
    - cmd: exec.Command("hg", args...),
    + cmd: exec.Command(hgExe, args...),
    }
    }
    @@ -155,7 +173,7 @@
    }
    return &Command{
    - cmd: exec.Command("hg", args...),
    + cmd: exec.Command(hgExe, args...),
    }
    }
    @@ -166,6 +184,6 @@
    }
    return &Command{
    - cmd: exec.Command("hg", args...),
    + cmd: exec.Command(hgExe, args...),
    }
    }
    --- a/main.go Wed Jan 04 07:29:10 2023 -0600
    +++ b/main.go Tue Mar 14 18:00:18 2023 -0500
    @@ -8,6 +8,7 @@
    "keep.imfreedom.org/grim/hgkeeper/authorized_keys"
    "keep.imfreedom.org/grim/hgkeeper/globals"
    + "keep.imfreedom.org/grim/hgkeeper/hg"
    "keep.imfreedom.org/grim/hgkeeper/once"
    "keep.imfreedom.org/grim/hgkeeper/serve"
    "keep.imfreedom.org/grim/hgkeeper/setup"
    @@ -43,6 +44,10 @@
    cmd := commands{}
    ctx := kong.Parse(&cmd)
    + if err := hg.SetExe(cmd.Globals.HgExecutable); err != nil {
    + ctx.FatalIfErrorf(err)
    + }
    +
    if err := ctx.Run(&cmd.Globals); err != nil {
    ctx.FatalIfErrorf(err)
    }