Overhaul the way the hgkeeper repo is created
--- a/hg/hg.go Thu Apr 18 23:15:44 2019 +0000
+++ b/hg/hg.go Sat Apr 27 02:03:00 2019 -0500
@@ -35,6 +35,12 @@
+func (r *Repository) run(args ...string) ([]byte, error) { + cmd := exec.Command("hg", args...) + cmd.Env = append(os.Environ(), "HGRCPATH=/dev/null") + return cmd.CombinedOutput() func (r *Repository) Init(mode os.FileMode) error {
return fmt.Errorf("repo %s already exists", r.path)
@@ -45,9 +51,9 @@
- cmd := exec.Command("hg", "init", r.path)
- cmd.Env = append(os.Environ(), "HGRCPATH=/dev/null")
+ _, err = r.run("init", r.path) func (r *Repository) Serve() error {
@@ -55,7 +61,20 @@
return fmt.Errorf("repo %s does not exist", r.path)
- cmd := exec.Command("hg", "-R", r.path, "serve", "--stdio")
- cmd.Env = append(os.Environ(), "HGRCPATH=/dev/null")
+ _, err := r.run("-R", r.path, "serve", "--stdio") +func (r *Repository) Add(files ...string) error { + args := append([]string{"add", "--cwd", r.path}, files...) + _, err := r.run(args...) +func (r *Repository) Commit(username, message string) error { + _, err := r.run("commit", "--cwd", r.path, "--config", "ui.username="+username, "-m", message) --- a/setup/command.go Thu Apr 18 23:15:44 2019 +0000
+++ b/setup/command.go Sat Apr 27 02:03:00 2019 -0500
@@ -1,11 +1,10 @@
- "bitbucket.org/rw_grim/hgkeeper/hg"
+ "bitbucket.org/rw_grim/hgkeeper/setup/repo" @@ -15,18 +14,6 @@
type setupFunc func(string) error
- hgrc = `# this file was created by hgkeeper, do not modify
-changegroup.aaab = hg update -C default > /dev/null
-changegroup.aaac = hg purge --all > /dev/null
-changegroup.aaad = hgkeeper refresh-auth
func (c *Command) Run(reposPath string) error {
c.adminRepoPath = filepath.Join(reposPath, c.AdminRepo)
@@ -57,17 +44,5 @@
func (c *Command) createAdminRepo(reposPath string) error {
- repo, err := hg.NewRepository(c.adminRepoPath)
- hgrcPath := filepath.Join(c.adminRepoPath, ".hg", "hgrc")
- return ioutil.WriteFile(hgrcPath, []byte(hgrc), 0644)
+ return repo.Create(c.adminRepoPath) --- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/setup/repo/access.go Sat Apr 27 02:03:00 2019 -0500
@@ -0,0 +1,37 @@
+ "bitbucket.org/rw_grim/hgkeeper/hg" +func addAccessYaml(r *hg.Repository) error { + filename := "access.yaml" + accessYamlPath := filepath.Join(r.Path(), filename) + err := ioutil.WriteFile(accessYamlPath, []byte(accessYaml), 0644) --- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/setup/repo/commit.go Sat Apr 27 02:03:00 2019 -0500
@@ -0,0 +1,13 @@
+ "bitbucket.org/rw_grim/hgkeeper/hg" + hgUsername = "hgkeeper" +func commit(r *hg.Repository) error { + return r.Commit(hgUsername, "Inital revision") --- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/setup/repo/hgrc.go Sat Apr 27 02:03:00 2019 -0500
@@ -0,0 +1,26 @@
+ "bitbucket.org/rw_grim/hgkeeper/hg" + hgrc = `# this file was created by hgkeeper, do not modify +changegroup.aaba = hg update -C default > /dev/null +changegroup.aaca = hg purge --all > /dev/null +changegroup.aada = hgkeeper refresh-auth +func addHGRC(r *hg.Repository) error { + hgrcPath := filepath.Join(r.Path(), ".hg", "hgrc") + return ioutil.WriteFile(hgrcPath, []byte(hgrc), 0644) --- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/setup/repo/readme.go Sat Apr 27 02:03:00 2019 -0500
@@ -0,0 +1,33 @@
+ "bitbucket.org/rw_grim/hgkeeper/hg" +This repository is used to manage keys for hgkeeper. This is done by +organizing ssh public keys in the keys directory. +Files in the keys directory should be named after the user the belong to and +contain the ssh public keys for that user. The name of the file is used in +access.yaml as the users/group name. +func addReadmeMd(r *hg.Repository) error { + filename := "README.md" + readmePath := filepath.Join(r.Path(), filename) + err := ioutil.WriteFile(readmePath, []byte(readmeMd), 0644) --- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/setup/repo/repo.go Sat Apr 27 02:03:00 2019 -0500
@@ -0,0 +1,35 @@
+ "bitbucket.org/rw_grim/hgkeeper/hg" +type setupFunc func(*hg.Repository) error +func Create(path string) error { + repo, err := hg.NewRepository(path) + setupFuncs := []setupFunc{ + for _, f := range setupFuncs { --- a/ssh/server.go Thu Apr 18 23:15:44 2019 +0000
+++ b/ssh/server.go Sat Apr 27 02:03:00 2019 -0500
@@ -54,6 +54,7 @@
func (s *Server) publicKeyCallback(meta ssh.ConnMetadata, key ssh.PublicKey) (*ssh.Permissions, error) {
+ log.Debugf("key: %s\n", key.Marshal())