forked from denormal/go-gitignore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample_test.go
55 lines (47 loc) · 1.22 KB
/
example_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package gitignore_test
import (
"fmt"
"github.com/joint-online-judge/go-gitignore"
)
func ExampleNewFromFile() {
ignore, err := gitignore.NewFromFile("/my/project/.gitignore")
if err != nil {
panic(err)
}
// attempt to match an absolute path
match := ignore.Match("/my/project/src/file.go")
if match != nil {
if match.Ignore() {
fmt.Println("ignore file.go")
}
}
// attempt to match a relative path
// - this is equivalent to the call above
match = ignore.Relative("src/file.go", false)
if match != nil {
if match.Include() {
fmt.Println("include file.go")
}
}
} // ExampleNewFromFile()
func ExampleNewRepository() {
ignore, err := gitignore.NewRepository("/my/project")
if err != nil {
panic(err)
}
// attempt to match a directory in the repository
match := ignore.Relative("src/examples", true)
if match != nil {
if match.Ignore() {
fmt.Printf(
"ignore src/examples because of pattern %q at %s",
match, match.Position(),
)
}
}
// if we have an absolute path, or a path relative to the current
// working directory we can use the short-hand methods
if ignore.Include("/my/project/etc/service.conf") {
fmt.Println("include the service configuration")
}
} // ExampleNewRepository()