1
1
package git_commands
2
2
3
3
import (
4
+ "fmt"
5
+ "os"
4
6
"testing"
5
7
6
8
"github.com/go-errors/errors"
@@ -10,6 +12,8 @@ import (
10
12
"github.com/stretchr/testify/assert"
11
13
)
12
14
15
+ var disableHooksFlag = fmt .Sprintf ("core.hooksPath=%s" , os .DevNull )
16
+
13
17
func TestWorkingTreeStageFile (t * testing.T ) {
14
18
runner := oscommands .NewFakeRunner (t ).
15
19
ExpectGitArgs ([]string {"add" , "--" , "test.txt" }, "" , nil )
@@ -113,7 +117,7 @@ func TestWorkingTreeDiscardAllFileChanges(t *testing.T) {
113
117
},
114
118
removeFile : func (string ) error { return nil },
115
119
runner : oscommands .NewFakeRunner (t ).
116
- ExpectGitArgs ([]string {"checkout" , "--" , "test" }, "" , errors .New ("error" )),
120
+ ExpectGitArgs ([]string {"-c" , disableHooksFlag , " checkout" , "--" , "test" }, "" , errors .New ("error" )),
117
121
expectedError : "error" ,
118
122
},
119
123
{
@@ -125,7 +129,7 @@ func TestWorkingTreeDiscardAllFileChanges(t *testing.T) {
125
129
},
126
130
removeFile : func (string ) error { return nil },
127
131
runner : oscommands .NewFakeRunner (t ).
128
- ExpectGitArgs ([]string {"checkout" , "--" , "test" }, "" , nil ),
132
+ ExpectGitArgs ([]string {"-c" , disableHooksFlag , " checkout" , "--" , "test" }, "" , nil ),
129
133
expectedError : "" ,
130
134
},
131
135
{
@@ -138,7 +142,7 @@ func TestWorkingTreeDiscardAllFileChanges(t *testing.T) {
138
142
removeFile : func (string ) error { return nil },
139
143
runner : oscommands .NewFakeRunner (t ).
140
144
ExpectGitArgs ([]string {"reset" , "--" , "test" }, "" , nil ).
141
- ExpectGitArgs ([]string {"checkout" , "--" , "test" }, "" , nil ),
145
+ ExpectGitArgs ([]string {"-c" , disableHooksFlag , " checkout" , "--" , "test" }, "" , nil ),
142
146
expectedError : "" ,
143
147
},
144
148
{
@@ -151,7 +155,7 @@ func TestWorkingTreeDiscardAllFileChanges(t *testing.T) {
151
155
removeFile : func (string ) error { return nil },
152
156
runner : oscommands .NewFakeRunner (t ).
153
157
ExpectGitArgs ([]string {"reset" , "--" , "test" }, "" , nil ).
154
- ExpectGitArgs ([]string {"checkout" , "--" , "test" }, "" , nil ),
158
+ ExpectGitArgs ([]string {"-c" , disableHooksFlag , " checkout" , "--" , "test" }, "" , nil ),
155
159
expectedError : "" ,
156
160
},
157
161
{
@@ -428,7 +432,7 @@ func TestWorkingTreeCheckoutFile(t *testing.T) {
428
432
commitHash : "11af912" ,
429
433
fileName : "test999.txt" ,
430
434
runner : oscommands .NewFakeRunner (t ).
431
- ExpectGitArgs ([]string {"checkout" , "11af912" , "--" , "test999.txt" }, "" , nil ),
435
+ ExpectGitArgs ([]string {"-c" , disableHooksFlag , " checkout" , "11af912" , "--" , "test999.txt" }, "" , nil ),
432
436
test : func (err error ) {
433
437
assert .NoError (t , err )
434
438
},
@@ -438,7 +442,7 @@ func TestWorkingTreeCheckoutFile(t *testing.T) {
438
442
commitHash : "11af912" ,
439
443
fileName : "test999.txt" ,
440
444
runner : oscommands .NewFakeRunner (t ).
441
- ExpectGitArgs ([]string {"checkout" , "11af912" , "--" , "test999.txt" }, "" , errors .New ("error" )),
445
+ ExpectGitArgs ([]string {"-c" , disableHooksFlag , " checkout" , "11af912" , "--" , "test999.txt" }, "" , errors .New ("error" )),
442
446
test : func (err error ) {
443
447
assert .Error (t , err )
444
448
},
@@ -468,7 +472,7 @@ func TestWorkingTreeDiscardUnstagedFileChanges(t *testing.T) {
468
472
testName : "valid case" ,
469
473
file : & models.File {Name : "test.txt" },
470
474
runner : oscommands .NewFakeRunner (t ).
471
- ExpectGitArgs ([]string {"checkout" , "--" , "test.txt" }, "" , nil ),
475
+ ExpectGitArgs ([]string {"-c" , disableHooksFlag , " checkout" , "--" , "test.txt" }, "" , nil ),
472
476
test : func (err error ) {
473
477
assert .NoError (t , err )
474
478
},
@@ -495,7 +499,7 @@ func TestWorkingTreeDiscardAnyUnstagedFileChanges(t *testing.T) {
495
499
{
496
500
testName : "valid case" ,
497
501
runner : oscommands .NewFakeRunner (t ).
498
- ExpectGitArgs ([]string {"checkout" , "--" , "." }, "" , nil ),
502
+ ExpectGitArgs ([]string {"-c" , disableHooksFlag , " checkout" , "--" , "." }, "" , nil ),
499
503
test : func (err error ) {
500
504
assert .NoError (t , err )
501
505
},
0 commit comments