aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2014-12-06 18:07:26 -0500
committerTeddy Wing2014-12-06 18:07:26 -0500
commit4751d4f5641137fba7c6848813a456640927ed85 (patch)
treee07f93443b3661dbdf418cc9e5089261f1bff894
parentf8066036afc09e07a17e77df430b0d5aac4e9240 (diff)
downloadgit-checkout-history-4751d4f5641137fba7c6848813a456640927ed85.tar.bz2
git-checkout-history: Output list of branches in history
On run, output the list of branches currently stored in git-checkout-history.
-rw-r--r--git-checkout-history/main.go43
1 files changed, 43 insertions, 0 deletions
diff --git a/git-checkout-history/main.go b/git-checkout-history/main.go
index e69de29..fa9747c 100644
--- a/git-checkout-history/main.go
+++ b/git-checkout-history/main.go
@@ -0,0 +1,43 @@
+package main
+
+import (
+ "fmt"
+ "io/ioutil"
+ "log"
+ "os/user"
+
+ "gopkg.in/yaml.v2"
+)
+
+// TODO: move to package
+type BranchList struct {
+ Branches []string
+}
+
+// TODO: move to package
+func getHomeDir() string {
+ usr, err := user.Current()
+ if err != nil {
+ log.Fatal(err)
+ }
+ return usr.HomeDir
+}
+
+func main() {
+ branchList := BranchList{}
+
+ file_path := getHomeDir() + "/.git-checkout-history"
+ data, err := ioutil.ReadFile(file_path)
+ if err != nil {
+ log.Fatal(err)
+ }
+
+ err = yaml.Unmarshal(data, &branchList)
+ if err != nil {
+ log.Fatal(err)
+ }
+
+ for i := 1; i < len(branchList.Branches); i++ {
+ fmt.Printf("[%d] %s\n", i, branchList.Branches[i])
+ }
+}