44 "bytes"
55 "fmt"
66 "io/ioutil"
7- "os"
87 "os/exec"
98 "path/filepath"
109 "strings"
@@ -31,16 +30,6 @@ func Dir() (string, error) {
3130 return gitDir , nil
3231}
3332
34- func WorkdirName () (string , error ) {
35- toplevelCmd := exec .Command ("git" , "rev-parse" , "--show-toplevel" )
36- output , err := utils .PrepareCmd (toplevelCmd ).Output ()
37- dir := firstLine (output )
38- if dir == "" {
39- return "" , fmt .Errorf ("unable to determine git working directory" )
40- }
41- return dir , err
42- }
43-
4433func VerifyRef (ref string ) bool {
4534 showRef := exec .Command ("git" , "show-ref" , "--verify" , "--quiet" , ref )
4635 err := utils .PrepareCmd (showRef ).Run ()
@@ -73,72 +62,10 @@ func BranchAtRef(paths ...string) (name string, err error) {
7362 return
7463}
7564
76- func Editor () (string , error ) {
77- varCmd := exec .Command ("git" , "var" , "GIT_EDITOR" )
78- output , err := utils .PrepareCmd (varCmd ).Output ()
79- if err != nil {
80- return "" , fmt .Errorf ("Can't load git var: GIT_EDITOR" )
81- }
82-
83- return os .ExpandEnv (firstLine (output )), nil
84- }
85-
8665func Head () (string , error ) {
8766 return BranchAtRef ("HEAD" )
8867}
8968
90- func SymbolicFullName (name string ) (string , error ) {
91- parseCmd := exec .Command ("git" , "rev-parse" , "--symbolic-full-name" , name )
92- output , err := utils .PrepareCmd (parseCmd ).Output ()
93- if err != nil {
94- return "" , fmt .Errorf ("Unknown revision or path not in the working tree: %s" , name )
95- }
96-
97- return firstLine (output ), nil
98- }
99-
100- func CommentChar (text string ) (string , error ) {
101- char , err := Config ("core.commentchar" )
102- if err != nil {
103- return "#" , nil
104- } else if char == "auto" {
105- lines := strings .Split (text , "\n " )
106- commentCharCandidates := strings .Split ("#;@!$%^&|:" , "" )
107- candidateLoop:
108- for _ , candidate := range commentCharCandidates {
109- for _ , line := range lines {
110- if strings .HasPrefix (line , candidate ) {
111- continue candidateLoop
112- }
113- }
114- return candidate , nil
115- }
116- return "" , fmt .Errorf ("unable to select a comment character that is not used in the current message" )
117- } else {
118- return char , nil
119- }
120- }
121-
122- func Show (sha string ) (string , error ) {
123- cmd := exec .Command ("git" , "-c" , "log.showSignature=false" , "show" , "-s" , "--format=%s%n%+b" , sha )
124- output , err := utils .PrepareCmd (cmd ).Output ()
125- return strings .TrimSpace (string (output )), err
126- }
127-
128- func Log (sha1 , sha2 string ) (string , error ) {
129- shaRange := fmt .Sprintf ("%s...%s" , sha1 , sha2 )
130- cmd := exec .Command (
131- "-c" , "log.showSignature=false" , "log" , "--no-color" ,
132- "--format=%h (%aN, %ar)%n%w(78,3,3)%s%n%+b" ,
133- "--cherry" , shaRange )
134- outputs , err := utils .PrepareCmd (cmd ).Output ()
135- if err != nil {
136- return "" , fmt .Errorf ("Can't load git log %s..%s" , sha1 , sha2 )
137- }
138-
139- return string (outputs ), nil
140- }
141-
14269func listRemotes () ([]string , error ) {
14370 remoteCmd := exec .Command ("git" , "remote" , "-v" )
14471 output , err := utils .PrepareCmd (remoteCmd ).Output ()
@@ -156,34 +83,6 @@ func Config(name string) (string, error) {
15683
15784}
15885
159- func ConfigAll (name string ) ([]string , error ) {
160- mode := "--get-all"
161- if strings .Contains (name , "*" ) {
162- mode = "--get-regexp"
163- }
164-
165- configCmd := exec .Command ("git" , "config" , mode , name )
166- output , err := utils .PrepareCmd (configCmd ).Output ()
167- if err != nil {
168- return nil , fmt .Errorf ("Unknown config %s" , name )
169- }
170- return outputLines (output ), nil
171- }
172-
173- func LocalBranches () ([]string , error ) {
174- branchesCmd := exec .Command ("git" , "branch" , "--list" )
175- output , err := utils .PrepareCmd (branchesCmd ).Output ()
176- if err != nil {
177- return nil , err
178- }
179-
180- branches := []string {}
181- for _ , branch := range outputLines (output ) {
182- branches = append (branches , branch [2 :])
183- }
184- return branches , nil
185- }
186-
18786var GitCommand = func (args ... string ) * exec.Cmd {
18887 return exec .Command ("git" , args ... )
18988}
0 commit comments