forked from prydonius/karn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
karn.go
60 lines (48 loc) · 1.05 KB
/
karn.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
58
59
60
package karn
import (
"fmt"
"log"
"os"
"github.com/prydonius/karn/config"
"github.com/prydonius/karn/repo"
)
func Update() {
if !repo.IsInsideWorkTree() {
log.Fatal("Not inside Git work tree")
}
dirs, err := config.GetConfig()
if err != nil {
log.Fatal(err)
}
cwd, err := os.Getwd()
if err != nil {
log.Fatal("Could not get current working directory")
}
id, err := config.GetIdentity(cwd, dirs)
if err != nil {
log.Fatal(err)
}
// Don't bother updating if we don't have an identity for the current working dir
if id == nil {
return
}
updated, err := repo.UpdateIdentity(id)
if err != nil {
log.Fatal(err)
}
if updated {
fmt.Println("### Updated Git Identity, you are now commiting as:")
fmt.Println(id)
}
}
func Init() {
fmt.Printf(`git() {
karn update
command git "$@"
}`)
}
func Install() {
fmt.Printf("To setup karn to check identity updates automatically before running any Git commands," +
" add the following line to your shell startup file:\n" +
"\tif which karn > /dev/null; then eval \"$(karn init)\"; fi")
}