@@ -14,7 +14,11 @@ var excludeFromDiff = []string{
1414 "go.sum" ,
1515}
1616
17- func excludeFiles () []string {
17+ type Command struct {
18+ ignoreLists []string
19+ }
20+
21+ func (c * Command ) excludeFiles () []string {
1822 newFileLists := []string {}
1923 for _ , f := range excludeFromDiff {
2024 newFileLists = append (newFileLists , ":(exclude)" + f )
@@ -23,40 +27,39 @@ func excludeFiles() []string {
2327 return newFileLists
2428}
2529
26- func diffNames () * exec.Cmd {
30+ func ( c * Command ) diffNames () * exec.Cmd {
2731 args := []string {
2832 "diff" ,
2933 "--staged" ,
3034 "--name-only" ,
3135 }
3236
33- args = append (args , excludeFiles ()... )
37+ args = append (args , c . excludeFiles ()... )
3438
3539 return exec .Command (
3640 "git" ,
3741 args ... ,
3842 )
3943}
4044
41- func diffFiles () * exec.Cmd {
45+ func ( c * Command ) diffFiles () * exec.Cmd {
4246 args := []string {
4347 "diff" ,
4448 "--staged" ,
4549 "--ignore-all-space" ,
4650 "--diff-algorithm=minimal" ,
4751 "--function-context" ,
48- "--unified=1" ,
4952 }
5053
51- args = append (args , excludeFiles ()... )
54+ args = append (args , c . excludeFiles ()... )
5255
5356 return exec .Command (
5457 "git" ,
5558 args ... ,
5659 )
5760}
5861
59- func hookPath () * exec.Cmd {
62+ func ( c * Command ) hookPath () * exec.Cmd {
6063 args := []string {
6164 "rev-parse" ,
6265 "--git-path" ,
@@ -72,16 +75,16 @@ func hookPath() *exec.Cmd {
7275// Diff compares the differences between two sets of data.
7376// It returns a string representing the differences and an error.
7477// If there are no differences, it returns an empty string and an error.
75- func Diff () (string , error ) {
76- output , err := diffNames ().Output ()
78+ func ( c * Command ) DiffFiles () (string , error ) {
79+ output , err := c . diffNames ().Output ()
7780 if err != nil {
7881 log .Fatal (err )
7982 }
8083 if string (output ) == "" {
8184 return "" , errors .New ("please add your staged changes using git add <files...>" )
8285 }
8386
84- output , err = diffFiles ().Output ()
87+ output , err = c . diffFiles ().Output ()
8588 if err != nil {
8689 log .Fatal (err )
8790 }
@@ -90,7 +93,11 @@ func Diff() (string, error) {
9093}
9194
9295// Hook to show git hook path
93- func Hook () (string , error ) {
94- output , err := hookPath ().Output ()
96+ func ( c * Command ) HookPath () (string , error ) {
97+ output , err := c . hookPath ().Output ()
9598 return string (output ), err
9699}
100+
101+ func New () * Command {
102+ return & Command {}
103+ }
0 commit comments