mirror of https://git.jolheiser.com/ugit.git
Compare commits
No commits in common. "285640256ebdee3678bfb53a52afd9e57ba35b3d" and "ad26f8c949cb75532eff7462877785c7a7e78566" have entirely different histories.
285640256e
...
ad26f8c949
|
@ -1,60 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"flag"
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"net/http"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"github.com/go-git/go-git/v5"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
repoDir, ok := os.LookupEnv("UGIT_REPODIR")
|
|
||||||
if !ok {
|
|
||||||
panic("UGIT_REPODIR not set")
|
|
||||||
}
|
|
||||||
|
|
||||||
urlFlag := flag.String("url", "http://localhost:3448", "URL for UCI")
|
|
||||||
flag.StringVar(urlFlag, "u", *urlFlag, "--url")
|
|
||||||
repoDirFlag := flag.String("repo-dir", "", "Repo dir (including .git)")
|
|
||||||
flag.StringVar(repoDirFlag, "rd", *repoDirFlag, "--repo-dir")
|
|
||||||
manifestFlag := flag.String("manifest", ".uci.jsonnet", "Path to manifest in repo")
|
|
||||||
flag.StringVar(manifestFlag, "m", *manifestFlag, "--manifest")
|
|
||||||
flag.Parse()
|
|
||||||
|
|
||||||
if *repoDirFlag != "" {
|
|
||||||
repoDir = *repoDirFlag
|
|
||||||
}
|
|
||||||
|
|
||||||
repo, err := git.PlainOpen(repoDir)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
tree, err := repo.Worktree()
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
fi, err := tree.Filesystem.Open(*manifestFlag)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer fi.Close()
|
|
||||||
|
|
||||||
data, err := io.ReadAll(fi)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp, err := http.Post(*urlFlag, "applicaiton/jsonnet", bytes.NewReader(data))
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
if resp.StatusCode != http.StatusOK {
|
|
||||||
panic(fmt.Sprintf("non-ok response: %s", resp.Status))
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -149,19 +149,12 @@ func requiredFS(repoDir string) error {
|
||||||
}
|
}
|
||||||
fp = filepath.Join(fp, "pre-receive")
|
fp = filepath.Join(fp, "pre-receive")
|
||||||
|
|
||||||
if err := os.MkdirAll(fp+".d", os.ModePerm); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
fi, err := os.Create(fp)
|
fi, err := os.Create(fp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
fi.WriteString("#!/usr/bin/env bash\n")
|
fi.WriteString("#!/usr/bin/env bash\n")
|
||||||
fi.WriteString(fmt.Sprintf("%s pre-receive-hook\n", bin))
|
fi.WriteString(fmt.Sprintf("%s pre-receive-hook\n", bin))
|
||||||
fi.WriteString(fmt.Sprintf(`for hook in %s.d/*; do
|
|
||||||
"${hook}"
|
|
||||||
done`, fp))
|
|
||||||
fi.Close()
|
fi.Close()
|
||||||
|
|
||||||
return os.Chmod(fp, 0o755)
|
return os.Chmod(fp, 0o755)
|
||||||
|
|
|
@ -35,7 +35,7 @@
|
||||||
path = ./.;
|
path = ./.;
|
||||||
});
|
});
|
||||||
pwd = ./.;
|
pwd = ./.;
|
||||||
subPackages = ["cmd/ugitd" "cmd/ugit-uci"];
|
subPackages = ["cmd/ugitd"];
|
||||||
CGO_ENABLED = 0;
|
CGO_ENABLED = 0;
|
||||||
flags = [
|
flags = [
|
||||||
"-trimpath"
|
"-trimpath"
|
||||||
|
|
|
@ -58,6 +58,7 @@ func gitService(ctx ReadWriteContexter, command, repoDir string, args ...string)
|
||||||
cmd.Env = append(os.Environ(), fmt.Sprintf("UGIT_REPODIR=%s", repoDir), "GIT_PROTOCOL=version=2")
|
cmd.Env = append(os.Environ(), fmt.Sprintf("UGIT_REPODIR=%s", repoDir), "GIT_PROTOCOL=version=2")
|
||||||
cmd.Stdin = ctx
|
cmd.Stdin = ctx
|
||||||
cmd.Stdout = ctx
|
cmd.Stdout = ctx
|
||||||
|
fmt.Println(cmd.Env, cmd.String())
|
||||||
|
|
||||||
return cmd.Run()
|
return cmd.Run()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue