@ -45,6 +45,7 @@ package org.eclipse.jgit.api;
import static org.junit.Assert.assertEquals ;
import static org.junit.Assert.fail ;
import java.io.IOException ;
import java.util.List ;
import org.eclipse.jgit.api.errors.ConcurrentRefUpdateException ;
@ -53,25 +54,29 @@ import org.eclipse.jgit.api.errors.JGitInternalException;
import org.eclipse.jgit.api.errors.NoHeadException ;
import org.eclipse.jgit.api.errors.NoMessageException ;
import org.eclipse.jgit.api.errors.WrongRepositoryStateException ;
import org.eclipse.jgit.errors.IncorrectObjectTypeException ;
import org.eclipse.jgit.errors.MissingObjectException ;
import org.eclipse.jgit.errors.UnmergedPathException ;
import org.eclipse.jgit.lib.Constants ;
import org.eclipse.jgit.lib.Ref ;
import org.eclipse.jgit.lib.Repository ;
import org.eclipse.jgit.lib.RepositoryTestCase ;
import org.eclipse.jgit.revwalk.RevCommit ;
import org.eclipse.jgit.revwalk.RevTag ;
import org.eclipse.jgit.revwalk.RevWalk ;
import org.junit.Test ;
public class TagCommandTest extends RepositoryTestCase {
@Test
public void testTaggingOnHead ( ) throws NoHeadException , NoMessageException ,
UnmergedPathException , ConcurrentRefUpdate Exception,
JGitInternalException , WrongRepositoryStat eException,
InvalidTagName Exception {
ConcurrentRefUpdateException , JGitInternal Exception,
WrongRepositoryStateException , InvalidTagNam eException,
MissingObjectException , IncorrectObjectTypeException , IO Exception {
Git git = new Git ( db ) ;
RevCommit commit = git . commit ( ) . setMessage ( "initial commit" ) . call ( ) ;
RevTag tag = git . tag ( ) . setName ( "tag" ) . call ( ) ;
assertEquals ( commit . getId ( ) , tag . getObject ( ) . getId ( ) ) ;
Ref tagRef = git . tag ( ) . setName ( "tag" ) . call ( ) ;
assertEquals ( commit . getId ( ) , db . peel ( tagRef ) . getPeeledObjectId ( ) ) ;
RevWalk walk = new RevWalk ( db ) ;
assertEquals ( "tag" , walk . parseTag ( tagRef . getObjectId ( ) ) . getTagName ( ) ) ;
}
@Test
@ -83,8 +88,8 @@ public class TagCommandTest extends RepositoryTestCase {
git . commit ( ) . setMessage ( "initial commit" ) . call ( ) ;
RevCommit commit = git . commit ( ) . setMessage ( "second commit" ) . call ( ) ;
git . commit ( ) . setMessage ( "third commit" ) . call ( ) ;
RevTag tag = git . tag ( ) . setObjectId ( commit ) . setName ( "tag" ) . call ( ) ;
assertEquals ( commit . getId ( ) , tag . getObject ( ) . getId ( ) ) ;
Ref tagRef = git . tag ( ) . setObjectId ( commit ) . setName ( "tag" ) . call ( ) ;
assertEquals ( commit . getId ( ) , db . peel ( tagRef ) . getPeeledObjec tId ( ) ) ;
}
@Test
@ -136,21 +141,20 @@ public class TagCommandTest extends RepositoryTestCase {
public void testDelete ( ) throws Exception {
Git git = new Git ( db ) ;
git . commit ( ) . setMessage ( "initial commit" ) . call ( ) ;
RevTag tag = git . tag ( ) . setName ( "tag" ) . call ( ) ;
Ref tagRef = git . tag ( ) . setName ( "tag" ) . call ( ) ;
assertEquals ( 1 , db . getTags ( ) . size ( ) ) ;
List < String > deleted = git . tagDelete ( ) . setTags ( tag . getTag Name ( ) )
List < String > deleted = git . tagDelete ( ) . setTags ( tagRef . getName ( ) )
. call ( ) ;
assertEquals ( 1 , deleted . size ( ) ) ;
assertEquals ( tag . getTagName ( ) ,
Repository . shortenRefName ( deleted . get ( 0 ) ) ) ;
assertEquals ( tagRef . getName ( ) , deleted . get ( 0 ) ) ;
assertEquals ( 0 , db . getTags ( ) . size ( ) ) ;
RevTag tag 1 = git . tag ( ) . setName ( "tag1" ) . call ( ) ;
RevTag tag 2 = git . tag ( ) . setName ( "tag2" ) . call ( ) ;
Ref tagRef 1 = git . tag ( ) . setName ( "tag1" ) . call ( ) ;
Ref tagRef 2 = git . tag ( ) . setName ( "tag2" ) . call ( ) ;
assertEquals ( 2 , db . getTags ( ) . size ( ) ) ;
deleted = git . tagDelete ( )
. setTags ( tag1 . getTagName ( ) , tag2 . getTagName ( ) ) . call ( ) ;
deleted = git . tagDelete ( ) . setTags ( tagRef1 . getName ( ) , tagRef2 . getName ( ) )
. call ( ) ;
assertEquals ( 2 , deleted . size ( ) ) ;
assertEquals ( 0 , db . getTags ( ) . size ( ) ) ;
}
@ -159,13 +163,13 @@ public class TagCommandTest extends RepositoryTestCase {
public void testDeleteFullName ( ) throws Exception {
Git git = new Git ( db ) ;
git . commit ( ) . setMessage ( "initial commit" ) . call ( ) ;
RevTag tag = git . tag ( ) . setName ( "tag" ) . call ( ) ;
Ref tagRef = git . tag ( ) . setName ( "tag" ) . call ( ) ;
assertEquals ( 1 , db . getTags ( ) . size ( ) ) ;
List < String > deleted = git . tagDelete ( )
. setTags ( Constants . R_TAGS + tag . getTag Name ( ) ) . call ( ) ;
. setTags ( Repository . shortenRefName ( tagRef . getName ( ) ) ) . call ( ) ;
assertEquals ( 1 , deleted . size ( ) ) ;
assertEquals ( Constants . R_TAGS + tag . getTag Name ( ) , deleted . get ( 0 ) ) ;
assertEquals ( tagRef . getName ( ) , deleted . get ( 0 ) ) ;
assertEquals ( 0 , db . getTags ( ) . size ( ) ) ;
}
@ -203,7 +207,7 @@ public class TagCommandTest extends RepositoryTestCase {
Git git = new Git ( db ) ;
git . add ( ) . addFilepattern ( "*" ) . call ( ) ;
git . commit ( ) . setMessage ( "initial commit" ) . call ( ) ;
List < RevTag > list = git . tagList ( ) . call ( ) ;
List < Ref > list = git . tagList ( ) . call ( ) ;
assertEquals ( 0 , list . size ( ) ) ;
}
@ -211,7 +215,7 @@ public class TagCommandTest extends RepositoryTestCase {
public void testShouldNotBlowUpIfThereAreNoCommitsInRepository ( )
throws Exception {
Git git = new Git ( db ) ;
List < RevTag > list = git . tagList ( ) . call ( ) ;
List < Ref > list = git . tagList ( ) . call ( ) ;
assertEquals ( 0 , list . size ( ) ) ;
}
@ -225,12 +229,12 @@ public class TagCommandTest extends RepositoryTestCase {
git . tag ( ) . setName ( "v2" ) . call ( ) ;
git . tag ( ) . setName ( "v10" ) . call ( ) ;
List < RevTag > list = git . tagList ( ) . call ( ) ;
List < Ref > list = git . tagList ( ) . call ( ) ;
assertEquals ( 3 , list . size ( ) ) ;
assertEquals ( "v10" , list . get ( 0 ) . getTag Name ( ) ) ;
assertEquals ( "v2" , list . get ( 1 ) . getTag Name ( ) ) ;
assertEquals ( "v3" , list . get ( 2 ) . getTag Name ( ) ) ;
assertEquals ( "refs/tags/ v10" , list . get ( 0 ) . getName ( ) ) ;
assertEquals ( "refs/tags/ v2" , list . get ( 1 ) . getName ( ) ) ;
assertEquals ( "refs/tags/ v3" , list . get ( 2 ) . getName ( ) ) ;
}
}