@@ -15,14 +15,38 @@ var empty = &ignore{}
15
15
// methods for testing files for matching the .gitignore file, and then
16
16
// determining whether a file should be ignored or included.
17
17
type GitIgnore interface {
18
+ // Base returns the directory containing the .gitignore file.
18
19
Base () string
19
20
20
- Match (string ) Match
21
+ // Match attempts to match the path against this GitIgnore, and will
22
+ // return its Match if successful. Match will invoke the GitIgnore error
23
+ // handler (if defined) if it is not possible to determine the absolute
24
+ // path of the given path, or if its not possible to determine if the
25
+ // path represents a file or a directory. If an error occurs, Match
26
+ // returns nil and the error handler (if defined via New, NewWithErrors
27
+ // or NewWithCache) will be invoked.
28
+ Match (path string ) Match
29
+
30
+ // Absolute attempts to match an absolute path against this GitIgnore. If
31
+ // the path is not located under the base directory of this GitIgnore, or
32
+ // is not matched by this GitIgnore, nil is returned.
21
33
Absolute (string , bool ) Match
22
- Relative (string , bool ) Match
23
34
24
- Ignore (string ) bool
25
- Include (string ) bool
35
+ // Relative attempts to match a path relative to the GitIgnore base
36
+ // directory. isdir is used to indicate whether the path represents a file
37
+ // or a directory. If the path is not matched by the GitIgnore, nil is
38
+ // returned.
39
+ Relative (path string , isdir bool ) Match
40
+
41
+ // Ignore returns true if the path is ignored by this GitIgnore. Paths
42
+ // that are not matched by this GitIgnore are not ignored. Internally,
43
+ // Ignore uses Match, and will return false if Match() returns nil for path.
44
+ Ignore (path string ) bool
45
+
46
+ // Include returns true if the path is included by this GitIgnore. Paths
47
+ // that are not matched by this GitIgnore are always included. Internally,
48
+ // Include uses Match, and will return true if Match() returns nil for path.
49
+ Include (path string ) bool
26
50
}
27
51
28
52
// ignore is the implementation of a .gitignore file.
@@ -187,13 +211,13 @@ func (i *ignore) Base() string {
187
211
return i ._base
188
212
} // Base()
189
213
190
- // Match attempts to match the path against this GitIgnore. If the path is
191
- // matched by a GitIgnore pattern, its Match will be returned. Match will
192
- // invoke the error handler (if defined) if its not possible to determine the
193
- // absolute path of the given path, or if its not possible to determine if the
194
- // path represents a file or a directory. If an error occurs, Match returns nil
195
- // and the error handler (if defined via New, NewWithErrors or NewWithCache)
196
- // will be invoked.
214
+ // Match attempts to match the path against this GitIgnore, and will
215
+ // return its Match if successful. Match will invoke the GitIgnore error
216
+ // handler (if defined) if it is not possible to determine the absolute
217
+ // path of the given path, or if its not possible to determine if the
218
+ // path represents a file or a directory. If an error occurs, Match
219
+ // returns nil and the error handler (if defined via New, NewWithErrors
220
+ // or NewWithCache) will be invoked.
197
221
func (i * ignore ) Match (path string ) Match {
198
222
// ensure we have the absolute path for the given file
199
223
_path , _err := filepath .Abs (path )
@@ -214,9 +238,9 @@ func (i *ignore) Match(path string) Match {
214
238
return i .Absolute (_path , _isdir )
215
239
} // Match()
216
240
217
- // Absolute attempts to match an absolute path against this GitIgnore. If the
218
- // path is not located under the base directory of this GitIgnore, or is not
219
- // matched by this GitIgnore, nil is returned.
241
+ // Absolute attempts to match an absolute path against this GitIgnore. If
242
+ // the path is not located under the base directory of this GitIgnore, or
243
+ // is not matched by this GitIgnore, nil is returned.
220
244
func (i * ignore ) Absolute (path string , isdir bool ) Match {
221
245
// does the file share the same directory as this ignore file?
222
246
if ! strings .HasPrefix (path , i ._base ) {
@@ -229,8 +253,10 @@ func (i *ignore) Absolute(path string, isdir bool) Match {
229
253
return i .Relative (_rel , isdir )
230
254
} // Absolute()
231
255
232
- // Relative attempts to match a path relative to the GitIgnore base directory.
233
- // If the path is not matched by the GitIgnore, nil is returned.
256
+ // Relative attempts to match a path relative to the GitIgnore base
257
+ // directory. isdir is used to indicate whether the path represents a file
258
+ // or a directory. If the path is not matched by the GitIgnore, nil is
259
+ // returned.
234
260
func (i * ignore ) Relative (path string , isdir bool ) Match {
235
261
// if we are on Windows, then translate the path to Unix form
236
262
_rel := path
@@ -251,9 +277,9 @@ func (i *ignore) Relative(path string, isdir bool) Match {
251
277
return nil
252
278
} // Relative()
253
279
254
- // Ignore returns true if the path is ignored by this GitIgnore. Paths that are
255
- // not matched by this GitIgnore are not ignored. Internally, Ignore uses
256
- // Match, and will return false if Match() returns nil for path.
280
+ // Ignore returns true if the path is ignored by this GitIgnore. Paths
281
+ // that are not matched by this GitIgnore are not ignored. Internally,
282
+ // Ignore uses Match, and will return false if Match() returns nil for path.
257
283
func (i * ignore ) Ignore (path string ) bool {
258
284
_match := i .Match (path )
259
285
if _match != nil {
@@ -264,9 +290,9 @@ func (i *ignore) Ignore(path string) bool {
264
290
return false
265
291
} // Ignore()
266
292
267
- // Include returns true if the path is included by this GitIgnore. Paths that
268
- // are not matched by this GitIgnore are always included. Internally, Include
269
- // uses Match, and will return true if Match() returns nil for path.
293
+ // Include returns true if the path is included by this GitIgnore. Paths
294
+ // that are not matched by this GitIgnore are always included. Internally,
295
+ // Include uses Match, and will return true if Match() returns nil for path.
270
296
func (i * ignore ) Include (path string ) bool {
271
297
_match := i .Match (path )
272
298
if _match != nil {
0 commit comments