@@ -96,9 +96,38 @@ func (s *RefSpecSuite) TestRefSpecMatch(c *C) {
9696}
9797
9898func (s * RefSpecSuite ) TestRefSpecMatchGlob (c * C ) {
99- spec := RefSpec ("refs/heads/*:refs/remotes/origin/*" )
100- c .Assert (spec .Match (plumbing .ReferenceName ("refs/tag/foo" )), Equals , false )
101- c .Assert (spec .Match (plumbing .ReferenceName ("refs/heads/foo" )), Equals , true )
99+ tests := map [string ]map [string ]bool {
100+ "refs/heads/*:refs/remotes/origin/*" : {
101+ "refs/tag/foo" : false ,
102+ "refs/heads/foo" : true ,
103+ },
104+ "refs/heads/*bc:refs/remotes/origin/*bc" : {
105+ "refs/heads/abc" : true ,
106+ "refs/heads/bc" : true ,
107+ "refs/heads/abx" : false ,
108+ },
109+ "refs/heads/a*c:refs/remotes/origin/a*c" : {
110+ "refs/heads/abc" : true ,
111+ "refs/heads/ac" : true ,
112+ "refs/heads/abx" : false ,
113+ },
114+ "refs/heads/ab*:refs/remotes/origin/ab*" : {
115+ "refs/heads/abc" : true ,
116+ "refs/heads/ab" : true ,
117+ "refs/heads/xbc" : false ,
118+ },
119+ }
120+
121+ for specStr , data := range tests {
122+ spec := RefSpec (specStr )
123+ for ref , matches := range data {
124+ c .Assert (spec .Match (plumbing .ReferenceName (ref )),
125+ Equals ,
126+ matches ,
127+ Commentf ("while matching spec %q against ref %q" , specStr , ref ),
128+ )
129+ }
130+ }
102131}
103132
104133func (s * RefSpecSuite ) TestRefSpecDst (c * C ) {
@@ -110,11 +139,33 @@ func (s *RefSpecSuite) TestRefSpecDst(c *C) {
110139}
111140
112141func (s * RefSpecSuite ) TestRefSpecDstBlob (c * C ) {
113- spec := RefSpec ("refs/heads/*:refs/remotes/origin/*" )
114- c .Assert (
115- spec .Dst (plumbing .ReferenceName ("refs/heads/foo" )).String (), Equals ,
116- "refs/remotes/origin/foo" ,
117- )
142+ ref := "refs/heads/abc"
143+ tests := map [string ]string {
144+ "refs/heads/*:refs/remotes/origin/*" : "refs/remotes/origin/abc" ,
145+ "refs/heads/*bc:refs/remotes/origin/*" : "refs/remotes/origin/a" ,
146+ "refs/heads/*bc:refs/remotes/origin/*bc" : "refs/remotes/origin/abc" ,
147+ "refs/heads/a*c:refs/remotes/origin/*" : "refs/remotes/origin/b" ,
148+ "refs/heads/a*c:refs/remotes/origin/a*c" : "refs/remotes/origin/abc" ,
149+ "refs/heads/ab*:refs/remotes/origin/*" : "refs/remotes/origin/c" ,
150+ "refs/heads/ab*:refs/remotes/origin/ab*" : "refs/remotes/origin/abc" ,
151+ "refs/heads/*abc:refs/remotes/origin/*abc" : "refs/remotes/origin/abc" ,
152+ "refs/heads/abc*:refs/remotes/origin/abc*" : "refs/remotes/origin/abc" ,
153+ // for these two cases, git specifically logs:
154+ // error: * Ignoring funny ref 'refs/remotes/origin/' locally
155+ // and ignores the ref; go-git does not currently do this validation,
156+ // but probably should.
157+ // "refs/heads/*abc:refs/remotes/origin/*": "",
158+ // "refs/heads/abc*:refs/remotes/origin/*": "",
159+ }
160+
161+ for specStr , dst := range tests {
162+ spec := RefSpec (specStr )
163+ c .Assert (spec .Dst (plumbing .ReferenceName (ref )).String (),
164+ Equals ,
165+ dst ,
166+ Commentf ("while getting dst from spec %q with ref %q" , specStr , ref ),
167+ )
168+ }
118169}
119170func (s * RefSpecSuite ) TestMatchAny (c * C ) {
120171 specs := []RefSpec {
0 commit comments