Skip to content

Commit fdbf85e

Browse files
author
nate smith
committed
sigh worthy mechanism for selecting arbitrary git outputs
1 parent f6afe1b commit fdbf85e

File tree

2 files changed

+27
-10
lines changed

2 files changed

+27
-10
lines changed

git/git.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,11 +222,7 @@ var GitCommand = func(args ...string) *exec.Cmd {
222222

223223
func UncommittedChangeCount() (int, error) {
224224
statusCmd := GitCommand("status", "--porcelain")
225-
fmt.Println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
226-
fmt.Printf("%+v", statusCmd)
227225
output, err := statusCmd.Output()
228-
fmt.Println(string(output))
229-
fmt.Println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
230226
if err != nil {
231227
return 0, fmt.Errorf("failed to run git status: %s", err)
232228
}

git/git_test.go

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@ import (
77
"testing"
88
)
99

10+
var _cases map[string]string
11+
12+
func init() {
13+
_cases = map[string]string{
14+
"foobar": `fart
15+
bar
16+
town`,
17+
}
18+
}
19+
1020
func StubbedGit(args ...string) *exec.Cmd {
1121
cs := []string{"-test.run=TestHelperProcess", "--", "git"}
1222
cs = append(cs, args...)
@@ -33,11 +43,22 @@ func TestHelperProcess(*testing.T) {
3343
}
3444
args = args[1:]
3545
}
36-
cmd, args := args[0], args[1:]
37-
switch cmd {
38-
case "git":
39-
fmt.Println("fart")
40-
fmt.Println("town")
46+
c, args := args[0], args[1:]
47+
fmt.Println(_cases[c])
48+
}
49+
50+
func StubGit(c string) func(...string) *exec.Cmd {
51+
return func(args ...string) *exec.Cmd {
52+
cs := []string{"-test.run=TestHelperProcess", "--", c}
53+
cs = append(cs, args...)
54+
env := []string{
55+
"GO_WANT_HELPER_PROCESS=1",
56+
}
57+
58+
cmd := exec.Command(os.Args[0], cs...)
59+
cmd.Env = append(env, os.Environ()...)
60+
fmt.Printf("%+v", cmd.Env)
61+
return cmd
4162
}
4263

4364
}
@@ -48,7 +69,7 @@ func Test_UncommittedChangeCount(t *testing.T) {
4869
GitCommand = origGitCommand
4970
}()
5071

51-
GitCommand = StubbedGit
72+
GitCommand = StubGit("foobar")
5273

5374
ucc, err := UncommittedChangeCount()
5475
if err != nil {

0 commit comments

Comments
 (0)