fork of go-git with some jj specific features
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at v5.13.2 61 lines 1.2 kB view raw
1package main 2 3import ( 4 "fmt" 5 "os" 6 "strings" 7 8 "github.com/go-git/go-git/v5/plumbing/object" 9) 10 11func checkIfError(err error, code exitCode, mainReason string, v ...interface{}) { 12 if err == nil { 13 return 14 } 15 16 printErr(wrapErr(err, mainReason, v...)) 17 os.Exit(int(code)) 18} 19 20func helpAndExit(s string, helpMsg string, code exitCode) { 21 if code == exitCodeSuccess { 22 printMsg("%s", s) 23 } else { 24 printErr(fmt.Errorf(s)) 25 } 26 27 fmt.Println(strings.Replace(helpMsg, "%_COMMAND_NAME_%", os.Args[0], -1)) 28 29 os.Exit(int(code)) 30} 31 32func printErr(err error) { 33 fmt.Printf("\x1b[31;1m%s\x1b[0m\n", fmt.Sprintf("error: %s", err)) 34} 35 36func printMsg(format string, args ...interface{}) { 37 fmt.Printf("%s\n", fmt.Sprintf(format, args...)) 38} 39 40func printCommits(commits []*object.Commit) { 41 for _, commit := range commits { 42 if os.Getenv("LOG_LEVEL") == "verbose" { 43 fmt.Printf( 44 "\x1b[36;1m%s \x1b[90;21m%s\x1b[0m %s\n", 45 commit.Hash.String()[:7], 46 commit.Hash.String(), 47 strings.Split(commit.Message, "\n")[0], 48 ) 49 } else { 50 fmt.Println(commit.Hash.String()) 51 } 52 } 53} 54 55func wrapErr(err error, s string, v ...interface{}) error { 56 if err != nil { 57 return fmt.Errorf("%s\n %s", fmt.Sprintf(s, v...), err) 58 } 59 60 return nil 61}