@ -46,6 +46,7 @@ import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals ;
import static org.junit.Assert.assertEquals ;
import static org.junit.Assert.assertFalse ;
import static org.junit.Assert.assertFalse ;
import static org.junit.Assert.assertTrue ;
import static org.junit.Assert.assertTrue ;
import static org.junit.Assert.fail ;
import java.util.Arrays ;
import java.util.Arrays ;
@ -71,6 +72,12 @@ public class DescribeTest extends CLIRepositoryTestCase {
git . tag ( ) . setName ( "v1.0" ) . call ( ) ;
git . tag ( ) . setName ( "v1.0" ) . call ( ) ;
}
}
private void secondCommit ( ) throws Exception {
writeTrashFile ( "greeting" , "Hello, world!" ) ;
git . add ( ) . addFilepattern ( "greeting" ) . call ( ) ;
git . commit ( ) . setMessage ( "2nd commit" ) . call ( ) ;
}
@Test
@Test
public void testNoHead ( ) throws Exception {
public void testNoHead ( ) throws Exception {
assertEquals ( CLIText . fatalError ( CLIText . get ( ) . noNamesFound ) ,
assertEquals ( CLIText . fatalError ( CLIText . get ( ) . noNamesFound ) ,
@ -94,9 +101,7 @@ public class DescribeTest extends CLIRepositoryTestCase {
@Test
@Test
public void testDescribeCommit ( ) throws Exception {
public void testDescribeCommit ( ) throws Exception {
initialCommitAndTag ( ) ;
initialCommitAndTag ( ) ;
writeTrashFile ( "greeting" , "Hello, world!" ) ;
secondCommit ( ) ;
git . add ( ) . addFilepattern ( "greeting" ) . call ( ) ;
git . commit ( ) . setMessage ( "2nd commit" ) . call ( ) ;
assertArrayEquals ( new String [ ] { "v1.0-1-g56f6ceb" , "" } ,
assertArrayEquals ( new String [ ] { "v1.0-1-g56f6ceb" , "" } ,
execute ( "git describe" ) ) ;
execute ( "git describe" ) ) ;
}
}
@ -108,6 +113,47 @@ public class DescribeTest extends CLIRepositoryTestCase {
execute ( "git describe --long HEAD" ) ) ;
execute ( "git describe --long HEAD" ) ) ;
}
}
@Test
public void testDescribeCommitMatch ( ) throws Exception {
initialCommitAndTag ( ) ;
secondCommit ( ) ;
assertArrayEquals ( new String [ ] { "v1.0-1-g56f6ceb" , "" } ,
execute ( "git describe --match v1.*" ) ) ;
}
@Test
public void testDescribeCommitMatch2 ( ) throws Exception {
initialCommitAndTag ( ) ;
secondCommit ( ) ;
git . tag ( ) . setName ( "v2.0" ) . call ( ) ;
assertArrayEquals ( new String [ ] { "v1.0-1-g56f6ceb" , "" } ,
execute ( "git describe --match v1.*" ) ) ;
}
@Test
public void testDescribeCommitMultiMatch ( ) throws Exception {
initialCommitAndTag ( ) ;
secondCommit ( ) ;
git . tag ( ) . setName ( "v2.0.0" ) . call ( ) ;
git . tag ( ) . setName ( "v2.1.1" ) . call ( ) ;
assertArrayEquals ( "git yields v2.0.0" , new String [ ] { "v2.0.0" , "" } ,
execute ( "git describe --match v2.0* --match v2.1.*" ) ) ;
}
@Test
public void testDescribeCommitNoMatch ( ) throws Exception {
initialCommitAndTag ( ) ;
writeTrashFile ( "greeting" , "Hello, world!" ) ;
secondCommit ( ) ;
try {
execute ( "git describe --match 1.*" ) ;
fail ( "git describe should not find any tag matching 1.*" ) ;
} catch ( Die e ) {
assertEquals ( "No names found, cannot describe anything." ,
e . getMessage ( ) ) ;
}
}
@Test
@Test
public void testHelpArgumentBeforeUnknown ( ) throws Exception {
public void testHelpArgumentBeforeUnknown ( ) throws Exception {
String [ ] output = execute ( "git describe -h -XYZ" ) ;
String [ ] output = execute ( "git describe -h -XYZ" ) ;