aboutsummaryrefslogtreecommitdiffstats
path: root/cli
diff options
context:
space:
mode:
Diffstat (limited to 'cli')
-rw-r--r--cli/go-git/main.go41
-rw-r--r--cli/go-git/receive_pack.go36
-rw-r--r--cli/go-git/upload_pack.go37
-rw-r--r--cli/go-git/version.go14
4 files changed, 128 insertions, 0 deletions
diff --git a/cli/go-git/main.go b/cli/go-git/main.go
new file mode 100644
index 0000000..97b8c3e
--- /dev/null
+++ b/cli/go-git/main.go
@@ -0,0 +1,41 @@
+package main
+
+import (
+ "os"
+ "path/filepath"
+
+ "github.com/jessevdk/go-flags"
+)
+
+const (
+ bin = "go-git"
+ receivePackBin = "git-receive-pack"
+ uploadPackBin = "git-upload-pack"
+)
+
+func main() {
+ switch filepath.Base(os.Args[0]) {
+ case receivePackBin:
+ os.Args = append([]string{"git", "receive-pack"}, os.Args[1:]...)
+ case uploadPackBin:
+ os.Args = append([]string{"git", "upload-pack"}, os.Args[1:]...)
+ }
+
+ parser := flags.NewNamedParser(bin, flags.Default)
+ parser.AddCommand("receive-pack", "", "", &CmdReceivePack{})
+ parser.AddCommand("upload-pack", "", "", &CmdUploadPack{})
+ parser.AddCommand("version", "Show the version information.", "", &CmdVersion{})
+
+ _, err := parser.Parse()
+ if err != nil {
+ if e, ok := err.(*flags.Error); ok && e.Type == flags.ErrCommandRequired {
+ parser.WriteHelp(os.Stdout)
+ }
+
+ os.Exit(1)
+ }
+}
+
+type cmd struct {
+ Verbose bool `short:"v" description:"Activates the verbose mode"`
+}
diff --git a/cli/go-git/receive_pack.go b/cli/go-git/receive_pack.go
new file mode 100644
index 0000000..0f96a28
--- /dev/null
+++ b/cli/go-git/receive_pack.go
@@ -0,0 +1,36 @@
+package main
+
+import (
+ "fmt"
+ "os"
+ "path/filepath"
+
+ "gopkg.in/src-d/go-git.v4/plumbing/transport/file"
+)
+
+type CmdReceivePack struct {
+ cmd
+
+ Args struct {
+ GitDir string `positional-arg-name:"git-dir" required:"true"`
+ } `positional-args:"yes"`
+}
+
+func (CmdReceivePack) Usage() string {
+ //TODO: git-receive-pack returns error code 129 if arguments are invalid.
+ return fmt.Sprintf("usage: %s <git-dir>", os.Args[0])
+}
+
+func (c *CmdReceivePack) Execute(args []string) error {
+ gitDir, err := filepath.Abs(c.Args.GitDir)
+ if err != nil {
+ return err
+ }
+
+ if err := file.ServeReceivePack(gitDir); err != nil {
+ fmt.Fprintln(os.Stderr, "ERR:", err)
+ os.Exit(128)
+ }
+
+ return nil
+}
diff --git a/cli/go-git/upload_pack.go b/cli/go-git/upload_pack.go
new file mode 100644
index 0000000..c45fe48
--- /dev/null
+++ b/cli/go-git/upload_pack.go
@@ -0,0 +1,37 @@
+package main
+
+import (
+ "fmt"
+ "os"
+ "path/filepath"
+
+ "gopkg.in/src-d/go-git.v4/plumbing/transport/file"
+)
+
+//TODO: usage: git upload-pack [--strict] [--timeout=<n>] <dir>
+type CmdUploadPack struct {
+ cmd
+
+ Args struct {
+ GitDir string `positional-arg-name:"git-dir" required:"true"`
+ } `positional-args:"yes"`
+}
+
+func (CmdUploadPack) Usage() string {
+ //TODO: git-upload-pack returns error code 129 if arguments are invalid.
+ return fmt.Sprintf("usage: %s <git-dir>", os.Args[0])
+}
+
+func (c *CmdUploadPack) Execute(args []string) error {
+ gitDir, err := filepath.Abs(c.Args.GitDir)
+ if err != nil {
+ return err
+ }
+
+ if err := file.ServeUploadPack(gitDir); err != nil {
+ fmt.Fprintln(os.Stderr, "ERR:", err)
+ os.Exit(128)
+ }
+
+ return nil
+}
diff --git a/cli/go-git/version.go b/cli/go-git/version.go
new file mode 100644
index 0000000..b0e773d
--- /dev/null
+++ b/cli/go-git/version.go
@@ -0,0 +1,14 @@
+package main
+
+import "fmt"
+
+var version string
+var build string
+
+type CmdVersion struct{}
+
+func (c *CmdVersion) Execute(args []string) error {
+ fmt.Printf("%s (%s) - build %s\n", bin, version, build)
+
+ return nil
+}