@@ -2,7 +2,9 @@ package gitignore
2
2
3
3
import (
4
4
"os"
5
+ "os/user"
5
6
"strconv"
7
+ "strings"
6
8
7
9
"github.com/go-git/go-billy/v5"
8
10
"github.com/go-git/go-billy/v5/memfs"
@@ -12,7 +14,8 @@ import (
12
14
type MatcherSuite struct {
13
15
GFS billy.Filesystem // git repository root
14
16
RFS billy.Filesystem // root that contains user home
15
- RFSR billy.Filesystem // root that contains user home, but with with relative ~/.gitignore_global
17
+ RFSR billy.Filesystem // root that contains user home, but with relative ~/.gitignore_global
18
+ RFSU billy.Filesystem // root that contains user home, but with relative ~user/.gitignore_global
16
19
MCFS billy.Filesystem // root that contains user home, but missing ~/.gitconfig
17
20
MEFS billy.Filesystem // root that contains user home, but missing excludesfile entry
18
21
MIFS billy.Filesystem // root that contains user home, but missing .gitignore
@@ -144,6 +147,37 @@ func (s *MatcherSuite) SetUpTest(c *C) {
144
147
145
148
s .RFSR = fs
146
149
150
+ // root that contains user home, but with relative ~user/.gitignore_global
151
+ fs = memfs .New ()
152
+ err = fs .MkdirAll (home , os .ModePerm )
153
+ c .Assert (err , IsNil )
154
+
155
+ f , err = fs .Create (fs .Join (home , gitconfigFile ))
156
+ c .Assert (err , IsNil )
157
+ _ , err = f .Write ([]byte ("[core]\n " ))
158
+ c .Assert (err , IsNil )
159
+ currentUser , err := user .Current ()
160
+ c .Assert (err , IsNil )
161
+ // remove domain for windows
162
+ username := currentUser .Username [strings .Index (currentUser .Username , "\\ " )+ 1 :]
163
+ _ , err = f .Write ([]byte (" excludesfile = ~" + username + "/.gitignore_global" + "\n " ))
164
+ c .Assert (err , IsNil )
165
+ err = f .Close ()
166
+ c .Assert (err , IsNil )
167
+
168
+ f , err = fs .Create (fs .Join (home , ".gitignore_global" ))
169
+ c .Assert (err , IsNil )
170
+ _ , err = f .Write ([]byte ("# IntelliJ\n " ))
171
+ c .Assert (err , IsNil )
172
+ _ , err = f .Write ([]byte (".idea/\n " ))
173
+ c .Assert (err , IsNil )
174
+ _ , err = f .Write ([]byte ("*.iml\n " ))
175
+ c .Assert (err , IsNil )
176
+ err = f .Close ()
177
+ c .Assert (err , IsNil )
178
+
179
+ s .RFSU = fs
180
+
147
181
// root that contains user home, but missing ~/.gitconfig
148
182
fs = memfs .New ()
149
183
err = fs .MkdirAll (home , os .ModePerm )
@@ -255,14 +289,16 @@ func (s *MatcherSuite) TestDir_ReadPatterns(c *C) {
255
289
}
256
290
257
291
func (s * MatcherSuite ) TestDir_ReadRelativeGlobalGitIgnore (c * C ) {
258
- ps , err := LoadGlobalPatterns (s .RFSR )
259
- c .Assert (err , IsNil )
260
- c .Assert (ps , HasLen , 2 )
292
+ for _ , fs := range []billy.Filesystem {s .RFSR , s .RFSU } {
293
+ ps , err := LoadGlobalPatterns (fs )
294
+ c .Assert (err , IsNil )
295
+ c .Assert (ps , HasLen , 2 )
261
296
262
- m := NewMatcher (ps )
263
- c .Assert (m .Match ([]string {".idea/" }, true ), Equals , false )
264
- c .Assert (m .Match ([]string {"*.iml" }, true ), Equals , true )
265
- c .Assert (m .Match ([]string {"IntelliJ" }, true ), Equals , false )
297
+ m := NewMatcher (ps )
298
+ c .Assert (m .Match ([]string {".idea/" }, true ), Equals , false )
299
+ c .Assert (m .Match ([]string {"*.iml" }, true ), Equals , true )
300
+ c .Assert (m .Match ([]string {"IntelliJ" }, true ), Equals , false )
301
+ }
266
302
}
267
303
268
304
func (s * MatcherSuite ) TestDir_LoadGlobalPatterns (c * C ) {
0 commit comments