-
Notifications
You must be signed in to change notification settings - Fork 0
/
persistence.go
57 lines (42 loc) · 981 Bytes
/
persistence.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package main
import (
"bufio"
"log"
)
var gitDataFile = "/tmp/git-chain-data"
func createBranchChain(branches []string) {
file := createFile(gitDataFile)
defer file.Close()
for _, branch := range branches {
file.WriteString(branch + "\n")
}
file.Sync()
}
func addBranchToChain(branch string) {
file := openFile(gitDataFile)
if file == nil {
println("No git chain exists. Use the create command to get one started.")
return
}
defer file.Close()
println("Writing branch:", branch)
file.WriteString(branch + "\n")
file.Sync()
}
func getBranchChain() []string {
file := openFile(gitDataFile)
if file == nil {
println("No git chain exists. Use the create command to get one started.")
return []string{}
}
defer file.Close()
var branchChain []string
scanner := bufio.NewScanner(file)
for scanner.Scan() {
branchChain = append(branchChain, scanner.Text())
}
if err := scanner.Err(); err != nil {
log.Fatal(err)
}
return branchChain
}