11package git
22
33import (
4+ "fmt"
45 "path"
56 "regexp"
67
@@ -53,15 +54,17 @@ func SplitPathspecs(pathspecs []string) (includes []string, excludes []string) {
5354 return includes , excludes
5455}
5556
57+ // Function might panic if passed an invalid pathspec. We validate these
58+ // elsewhere.
5659func PathspecMatch (pathspec string , p string ) bool {
5760 if len (pathspec ) == 0 {
5861 panic ("empty string is not valid pathspec" )
5962 }
6063
6164 // Note: Git uses fnmatch(). This match may differ. Hopefully only rarely.
62- didMatch , err := doublestar .PathMatch (pathspec , p )
65+ didMatch , err := doublestar .Match (pathspec , p )
6366 if err != nil {
64- panic ("bad pattern passed to doublestar.Match()" )
67+ panic (fmt . Sprintf ( "error calling doublestar.Match(): %v" , err ) )
6568 }
6669
6770 if didMatch {
@@ -71,9 +74,9 @@ func PathspecMatch(pathspec string, p string) bool {
7174 // Ensure we mimic Git behavior with trailing slash. See "pathspec" in
7275 // gitglossary(3).
7376 subdirPathspec := path .Join (pathspec , "**" )
74- didMatch , err = doublestar .PathMatch (subdirPathspec , p )
77+ didMatch , err = doublestar .Match (subdirPathspec , p )
7578 if err != nil {
76- panic ("bad pattern passed to doublestar.Match()" )
79+ panic (fmt . Sprintf ( "error calling doublestar.Match(): %v" , err ) )
7780 }
7881
7982 if didMatch {
@@ -82,9 +85,9 @@ func PathspecMatch(pathspec string, p string) bool {
8285
8386 if pathspec [0 ] == '*' {
8487 toplevelPathspec := path .Join ("**/" , pathspec )
85- didMatch , err = doublestar .PathMatch (toplevelPathspec , p )
88+ didMatch , err = doublestar .Match (toplevelPathspec , p )
8689 if err != nil {
87- panic ("bad pattern passed to doublestar.Match()" )
90+ panic (fmt . Sprintf ( "error calling doublestar.Match(): %v" , err ) )
8891 }
8992
9093 if didMatch {
0 commit comments