-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
49 lines (41 loc) · 903 Bytes
/
main.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
package main
import (
"fmt"
"log"
tea "github.com/charmbracelet/bubbletea"
"github.com/go-git/go-git/v5"
)
func main() {
slc := GetBranches()
branchItems := BuildItems(slc)
l := ListBuilder(branchItems)
repo, err := git.PlainOpen(".")
if err != nil {
log.Fatal(err)
}
w, err := repo.Worktree()
if err != nil {
log.Print(err)
}
status, err := w.Status()
if err != nil {
log.Print(err)
}
if !status.IsClean() {
raiseError(status)
} else {
if _, err := tea.NewProgram(Model{list: l, repo: repo}).Run(); err != nil {
log.Fatal(err)
}
}
}
func raiseError(status git.Status) {
fmt.Println(
"error: Your local changes to the following files would be overwritten by checkout:",
)
for k := range status {
fmt.Println(ModifiedFiles.Render(k))
}
fmt.Println("Please commit your changes or stash them before you switch branches.")
fmt.Println("Aborting")
}