Skip to content

Commit

Permalink
Add git command
Browse files Browse the repository at this point in the history
  • Loading branch information
anothertobi committed Oct 20, 2019
1 parent 66418e1 commit 25c325a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
36 changes: 36 additions & 0 deletions commands/git.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package commands

import (
"fmt"

"github.com/spf13/cobra"
"gopkg.in/src-d/go-billy.v4/osfs"
"gopkg.in/src-d/go-git.v4"
"gopkg.in/src-d/go-git.v4/storage/filesystem"
)

func init() {
rootCmd.AddCommand(gitCmd)
}

var gitCmd = &cobra.Command{
Use: "git",
Short: "Print the git HEAD",
Long: `tbd`,
Args: cobra.ExactValidArgs(1),
Run: func(cmd *cobra.Command, args []string) {
worktree := osfs.New(args[0])
gitdir, err := worktree.Chroot(".git")
if err != nil {
panic(err)
}

storer := filesystem.NewStorage(gitdir, nil)
repository, err := git.Open(storer, worktree)
if err != nil {
panic(err)
}

fmt.Println(repository.Head())
},
}
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ require (
golang.org/x/time v0.0.0-20190921001708-c4c64cad1fd0 // indirect
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/src-d/go-git.v4 v4.13.1 // indirect
gopkg.in/src-d/go-billy.v4 v4.3.2
gopkg.in/src-d/go-git.v4 v4.13.1
k8s.io/api v0.0.0-20190503184017-f1b257a4ce96 // indirect
k8s.io/apimachinery v0.0.0-20190223001710-c182ff3b9841
k8s.io/client-go v8.0.0+incompatible
Expand Down

0 comments on commit 25c325a

Please sign in to comment.