aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2015-01-11 18:15:31 -0500
committerTeddy Wing2015-01-11 18:15:31 -0500
commitb89de92a5bb69e40f80e51ab4d4847c78598e48e (patch)
tree59fc144940d0a089e7f2c6674be6fa347ddc814f
parentfaad1a93bf0cbadc06f245a46d1057ced4f3710c (diff)
downloadgit-checkout-history-b89de92a5bb69e40f80e51ab4d4847c78598e48e.tar.bz2
utils.go: Separate history by repository
Use a different history list for each repo. Now the YAML file is organised in this way: /path/to/repo: - branch name - branch name /path/to/another/repo: - branch name
-rw-r--r--utils/utils.go14
1 files changed, 6 insertions, 8 deletions
diff --git a/utils/utils.go b/utils/utils.go
index 0c7760e..82da017 100644
--- a/utils/utils.go
+++ b/utils/utils.go
@@ -15,10 +15,6 @@ import (
var history_file string = ".git-checkout-history"
-type BranchList struct {
- Branches []string
-}
-
func getHomeDir() string {
usr, err := user.Current()
if err != nil {
@@ -72,7 +68,6 @@ func OpenHistoryFile() (f *os.File, err error) {
}
func Store(branch string) {
- branchList := BranchList{}
rcfile, err := OpenHistoryFile()
if err != nil {
log.Fatal(err)
@@ -85,12 +80,15 @@ func Store(branch string) {
log.Fatal(err)
}
+ branchList := make(map[string][]string)
+
err = yaml.Unmarshal(data, &branchList)
if err != nil {
log.Fatal(err)
}
- branchList.Branches = append([]string{branch}, branchList.Branches...)
+ current_git_dir := currentGitDir()
+ branchList[current_git_dir] = append([]string{branch}, branchList[current_git_dir]...)
data, err = yaml.Marshal(&branchList)
if err != nil {
@@ -104,7 +102,7 @@ func Store(branch string) {
}
func Branches() []string {
- branchList := BranchList{}
+ branchList := make(map[string][]string)
file_path := getHomeDir() + "/" + history_file
data, err := ioutil.ReadFile(file_path)
@@ -117,5 +115,5 @@ func Branches() []string {
log.Fatal(err)
}
- return branchList.Branches
+ return branchList[currentGitDir()]
}