@@ -13,9 +13,9 @@ afterEach(() => {
13
13
14
14
const mockGitFs = ( ) => {
15
15
mock ( {
16
- 'root /.git' : { } ,
17
- 'root /foo.js' : 'foo()' ,
18
- 'root /bar.md' : '# foo' ,
16
+ '/.git' : { } ,
17
+ '/foo.js' : 'foo()' ,
18
+ '/bar.md' : '# foo' ,
19
19
} ) ;
20
20
execa . sync . mockImplementation ( ( command , args ) => {
21
21
if ( command !== 'git' ) {
@@ -37,21 +37,36 @@ const mockGitFs = () => {
37
37
describe ( 'with git' , ( ) => {
38
38
test ( 'calls `git merge-base`' , ( ) => {
39
39
mock ( {
40
- 'root /.git' : { } ,
40
+ '/.git' : { } ,
41
41
} ) ;
42
42
43
43
prettyQuick ( 'root' ) ;
44
44
45
45
expect ( execa . sync ) . toHaveBeenCalledWith (
46
46
'git' ,
47
47
[ 'merge-base' , 'HEAD' , 'master' ] ,
48
- { cwd : 'root' }
48
+ { cwd : '/' }
49
+ ) ;
50
+ } ) ;
51
+
52
+ test ( 'calls `git merge-base` with root git directory' , ( ) => {
53
+ mock ( {
54
+ '/.git' : { } ,
55
+ '/other-dir' : { } ,
56
+ } ) ;
57
+
58
+ prettyQuick ( '/other-dir' ) ;
59
+
60
+ expect ( execa . sync ) . toHaveBeenCalledWith (
61
+ 'git' ,
62
+ [ 'merge-base' , 'HEAD' , 'master' ] ,
63
+ { cwd : '/' }
49
64
) ;
50
65
} ) ;
51
66
52
67
test ( 'with --staged does NOT call `git merge-base`' , ( ) => {
53
68
mock ( {
54
- 'root /.git' : { } ,
69
+ '/.git' : { } ,
55
70
} ) ;
56
71
57
72
prettyQuick ( 'root' ) ;
@@ -65,37 +80,37 @@ describe('with git', () => {
65
80
66
81
test ( 'calls `git diff --name-only` with revision' , ( ) => {
67
82
mock ( {
68
- 'root /.git' : { } ,
83
+ '/.git' : { } ,
69
84
} ) ;
70
85
71
86
prettyQuick ( 'root' , { since : 'banana' } ) ;
72
87
73
88
expect ( execa . sync ) . toHaveBeenCalledWith (
74
89
'git' ,
75
90
[ 'diff' , '--name-only' , '--diff-filter=ACMRTUB' , 'banana' ] ,
76
- { cwd : 'root ' }
91
+ { cwd : '/ ' }
77
92
) ;
78
93
} ) ;
79
94
80
95
test ( 'calls `git ls-files`' , ( ) => {
81
96
mock ( {
82
- 'root /.git' : { } ,
97
+ '/.git' : { } ,
83
98
} ) ;
84
99
85
100
prettyQuick ( 'root' , { since : 'banana' } ) ;
86
101
87
102
expect ( execa . sync ) . toHaveBeenCalledWith (
88
103
'git' ,
89
104
[ 'ls-files' , '--others' , '--exclude-standard' ] ,
90
- { cwd : 'root ' }
105
+ { cwd : '/ ' }
91
106
) ;
92
107
} ) ;
93
108
94
109
test ( 'calls onFoundSinceRevision with return value from `git merge-base`' , ( ) => {
95
110
const onFoundSinceRevision = jest . fn ( ) ;
96
111
97
112
mock ( {
98
- 'root /.git' : { } ,
113
+ '/.git' : { } ,
99
114
} ) ;
100
115
execa . sync . mockReturnValue ( { stdout : 'banana' } ) ;
101
116
@@ -130,8 +145,8 @@ describe('with git', () => {
130
145
131
146
prettyQuick ( 'root' , { since : 'banana' , onWriteFile } ) ;
132
147
133
- expect ( fs . readFileSync ( 'root /foo.js' , 'utf8' ) ) . toEqual ( 'formatted:foo()' ) ;
134
- expect ( fs . readFileSync ( 'root /bar.md' , 'utf8' ) ) . toEqual ( 'formatted:# foo' ) ;
148
+ expect ( fs . readFileSync ( '/foo.js' , 'utf8' ) ) . toEqual ( 'formatted:foo()' ) ;
149
+ expect ( fs . readFileSync ( '/bar.md' , 'utf8' ) ) . toEqual ( 'formatted:# foo' ) ;
135
150
} ) ;
136
151
137
152
test ( 'with --staged stages changed files' , ( ) => {
@@ -140,10 +155,10 @@ describe('with git', () => {
140
155
prettyQuick ( 'root' , { since : 'banana' , staged : true } ) ;
141
156
142
157
expect ( execa . sync ) . toHaveBeenCalledWith ( 'git' , [ 'add' , './foo.js' ] , {
143
- cwd : 'root ' ,
158
+ cwd : '/ ' ,
144
159
} ) ;
145
160
expect ( execa . sync ) . toHaveBeenCalledWith ( 'git' , [ 'add' , './bar.md' ] , {
146
- cwd : 'root ' ,
161
+ cwd : '/ ' ,
147
162
} ) ;
148
163
} ) ;
149
164
@@ -153,10 +168,10 @@ describe('with git', () => {
153
168
prettyQuick ( 'root' , { since : 'banana' } ) ;
154
169
155
170
expect ( execa . sync ) . not . toHaveBeenCalledWith ( 'git' , [ 'add' , './foo.js' ] , {
156
- cwd : 'root ' ,
171
+ cwd : '/ ' ,
157
172
} ) ;
158
173
expect ( execa . sync ) . not . toHaveBeenCalledWith ( 'git' , [ 'add' , './bar.md' ] , {
159
- cwd : 'root ' ,
174
+ cwd : '/ ' ,
160
175
} ) ;
161
176
} ) ;
162
177
} ) ;
0 commit comments