File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -10,9 +10,25 @@ func AllReferencesFilter(_ Reference) bool {
1010 return true
1111}
1212
13+ // PrefixFilter returns a `ReferenceFilter` that matches references
14+ // whose names start with the specified `prefix`, which must match at
15+ // a component boundary. For example,
16+ //
17+ // * Prefix "refs/foo" matches "refs/foo" and "refs/foo/bar" but not
18+ // "refs/foobar".
19+ //
20+ // * Prefix "refs/foo/" matches "refs/foo/bar" but not "refs/foo" or
21+ // "refs/foobar".
1322func PrefixFilter (prefix string ) ReferenceFilter {
23+ if strings .HasSuffix (prefix , "/" ) {
24+ return func (r Reference ) bool {
25+ return strings .HasPrefix (r .Refname , prefix )
26+ }
27+ }
28+
1429 return func (r Reference ) bool {
15- return strings .HasPrefix (r .Refname , prefix )
30+ return strings .HasPrefix (r .Refname , prefix ) &&
31+ (len (r .Refname ) == len (prefix ) || r .Refname [len (prefix )] == '/' )
1632 }
1733}
1834
You can’t perform that action at this time.
0 commit comments