@@ -9,12 +9,14 @@ describe("Tag", function() {
99 var Obj = NodeGit . Object ;
1010 var Oid = NodeGit . Oid ;
1111 var Reference = NodeGit . Reference ;
12+ var Signature = NodeGit . Signature ;
1213
1314 var reposPath = local ( "../repos/workdir" ) ;
1415 var tagName = "annotated-tag" ;
1516 var tagFullName = "refs/tags/" + tagName ;
1617 var tagOid = "dc800017566123ff3c746b37284a24a66546667e" ;
1718 var commitPointedTo = "32789a79e71fbc9e04d3eff7425e1771eb595150" ;
19+ var commitPointedTo2 = "c82fb078a192ea221c9f1093c64321c60d64aa0d" ;
1820 var tagMessage = "This is an annotated tag\n" ;
1921
2022 function testTag ( tag , name ) {
@@ -144,4 +146,78 @@ describe("Tag", function() {
144146 return Promise . resolve ( ) ;
145147 } ) ;
146148 } ) ;
149+
150+ it ( "can create a new signed tag with Tag.create and delete it" , function ( ) {
151+ var name = "created-signed-tag-create" ;
152+ var repository = this . repository ;
153+ var signature = Signature . default ( repository ) ;
154+ var commit = null ;
155+ var commit2 = null ;
156+
157+ return repository . getCommit ( commitPointedTo )
158+ . then ( function ( theCommit ) {
159+ commit = theCommit ;
160+ return repository . getCommit ( commitPointedTo2 ) ;
161+ } )
162+ . then ( function ( theCommit2 ) {
163+ commit2 = theCommit2 ;
164+ return Tag . create ( repository , name , commit , signature , tagMessage , 1 ) ;
165+ } )
166+ . then ( function ( oid ) {
167+ return repository . getTag ( oid ) ;
168+ } )
169+ . then ( function ( tag ) {
170+ testTag ( tag , name ) ;
171+ assert ( tag . tagger ( ) , signature ) ;
172+ } )
173+ . then ( function ( ) {
174+ // overwriting is okay
175+ return Tag . create ( repository , name , commit2 , signature , tagMessage , 1 ) ;
176+ } )
177+ . then ( function ( ) {
178+ // overwriting is not okay
179+ return Tag . create ( repository , name , commit , signature , tagMessage , 0 ) ;
180+ } )
181+ . then ( function ( ) {
182+ return Promise . reject ( new Error ( "should not be able to create the '" +
183+ name + "' tag twice" ) ) ;
184+ } , function ( ) {
185+ return Promise . resolve ( )
186+ . then ( function ( ) {
187+ return repository . deleteTagByName ( name ) ;
188+ } )
189+ . then ( function ( ) {
190+ return Reference . lookup ( repository , "refs/tags/" + name ) ;
191+ } )
192+ . then ( function ( ) {
193+ return Promise . reject ( new Error ( "the tag '" + name +
194+ "' should not exist" ) ) ;
195+ } , function ( ) {
196+ return Promise . resolve ( ) ;
197+ } ) ;
198+ } ) ;
199+ } ) ;
200+
201+ it ( "can create a new signed tag with Tag.annotationCreate" , function ( ) {
202+ var oid = Oid . fromString ( commitPointedTo ) ;
203+ var name = "created-signed-tag-annotationCreate" ;
204+ var repository = this . repository ;
205+ var signature = Signature . default ( repository ) ;
206+ var odb = null ;
207+
208+ return repository . odb ( )
209+ . then ( function ( theOdb ) {
210+ odb = theOdb ;
211+ } )
212+ . then ( function ( ) {
213+ return Tag . annotationCreate (
214+ repository , name , oid , signature , tagMessage ) ;
215+ } )
216+ . then ( function ( oid ) {
217+ return odb . read ( oid ) ;
218+ } )
219+ . then ( function ( object ) {
220+ assert ( object . type ( ) , Obj . TYPE . TAG ) ;
221+ } ) ;
222+ } ) ;
147223} ) ;
0 commit comments