@ -53,6 +53,8 @@ import org.eclipse.jgit.api.errors.NoFilepatternException;
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.ObjectId ;
@ -105,6 +107,7 @@ public class CommitAndLogCommandTests extends RepositoryTestCase {
git . commit ( ) . setAuthor ( author ) . call ( ) ;
fail ( "Didn't get the expected exception" ) ;
} catch ( NoMessageException e ) {
// expected
}
}
@ -122,6 +125,7 @@ public class CommitAndLogCommandTests extends RepositoryTestCase {
commitCmd . setAuthor ( author ) ;
fail ( "didn't catch the expected exception" ) ;
} catch ( IllegalStateException e ) {
// expected
}
LogCommand logCmd = git . log ( ) ;
logCmd . call ( ) ;
@ -130,6 +134,7 @@ public class CommitAndLogCommandTests extends RepositoryTestCase {
logCmd . call ( ) ;
fail ( "didn't catch the expected exception" ) ;
} catch ( IllegalStateException e ) {
// expected
}
}
@ -191,4 +196,39 @@ public class CommitAndLogCommandTests extends RepositoryTestCase {
assertEquals ( "db00fd65b218578127ea51f3dffac701f12f486a" ,
tw . getObjectId ( 0 ) . getName ( ) ) ;
}
public void testCommitRange ( ) throws NoHeadException , NoMessageException ,
UnmergedPathException , ConcurrentRefUpdateException ,
JGitInternalException , WrongRepositoryStateException ,
IncorrectObjectTypeException , MissingObjectException {
// do 4 commits and set the range to the second and fourth one
Git git = new Git ( db ) ;
git . commit ( ) . setMessage ( "first commit" ) . call ( ) ;
RevCommit second = git . commit ( ) . setMessage ( "second commit" )
. setCommitter ( committer ) . call ( ) ;
git . commit ( ) . setMessage ( "third commit" ) . setAuthor ( author ) . call ( ) ;
RevCommit last = git . commit ( ) . setMessage ( "fourth commit" ) . setAuthor (
author )
. setCommitter ( committer ) . call ( ) ;
Iterable < RevCommit > commits = git . log ( ) . addRange ( second . getId ( ) ,
last . getId ( ) ) . call ( ) ;
// check that we have the third and fourth commit
PersonIdent defaultCommitter = new PersonIdent ( db ) ;
PersonIdent expectedAuthors [ ] = new PersonIdent [ ] { author , author } ;
PersonIdent expectedCommitters [ ] = new PersonIdent [ ] {
defaultCommitter , committer } ;
String expectedMessages [ ] = new String [ ] { "third commit" ,
"fourth commit" } ;
int l = expectedAuthors . length - 1 ;
for ( RevCommit c : commits ) {
assertEquals ( expectedAuthors [ l ] . getName ( ) , c . getAuthorIdent ( )
. getName ( ) ) ;
assertEquals ( expectedCommitters [ l ] . getName ( ) , c . getCommitterIdent ( )
. getName ( ) ) ;
assertEquals ( c . getFullMessage ( ) , expectedMessages [ l ] ) ;
l - - ;
}
assertEquals ( l , - 1 ) ;
}
}