@ -48,11 +48,13 @@ import java.io.File;
import java.io.IOException ;
import java.nio.file.Path ;
import java.util.ArrayList ;
import java.util.Arrays ;
import java.util.List ;
import org.eclipse.jgit.junit.JGitTestUtil ;
import org.eclipse.jgit.junit.LocalDiskRepositoryTestCase ;
import org.eclipse.jgit.pgm.CLIGitCommand ;
import org.eclipse.jgit.pgm.Die ;
import org.junit.Before ;
public class CLIRepositoryTestCase extends LocalDiskRepositoryTestCase {
@ -79,7 +81,7 @@ public class CLIRepositoryTestCase extends LocalDiskRepositoryTestCase {
* @return command output
* @throws Exception
* /
protected String [ ] execute ( String . . . cmds ) throws Exception {
protected String [ ] executeUnchecked ( String . . . cmds ) throws Exception {
List < String > result = new ArrayList < String > ( cmds . length ) ;
for ( String cmd : cmds ) {
result . addAll ( CLIGitCommand . execute ( cmd , db ) ) ;
@ -87,6 +89,28 @@ public class CLIRepositoryTestCase extends LocalDiskRepositoryTestCase {
return result . toArray ( new String [ 0 ] ) ;
}
/ * *
* Executes specified git commands ( with arguments ) , throws exception and
* stops execution on first command which output contains a ' fatal : ' error
*
* @param cmds
* each string argument must be a valid git command line , e . g .
* "git branch -h"
* @return command output
* @throws Exception
* /
protected String [ ] execute ( String . . . cmds ) throws Exception {
List < String > result = new ArrayList < String > ( cmds . length ) ;
for ( String cmd : cmds ) {
List < String > out = CLIGitCommand . execute ( cmd , db ) ;
if ( contains ( out , "fatal: " ) ) {
throw new Die ( toString ( out ) ) ;
}
result . addAll ( out ) ;
}
return result . toArray ( new String [ 0 ] ) ;
}
/ * *
* @param link
* the path of the symbolic link to create
@ -196,15 +220,32 @@ public class CLIRepositoryTestCase extends LocalDiskRepositoryTestCase {
}
protected void assertArrayOfLinesEquals ( String [ ] expected , String [ ] actual ) {
assertEquals ( toText ( expected ) , toText ( actual ) ) ;
assertEquals ( toString ( expected ) , toString ( actual ) ) ;
}
private static String toText ( String [ ] lines ) {
public static String toString ( String [ ] lines ) {
return toString ( Arrays . asList ( lines ) ) ;
}
public static String toString ( List < String > lines ) {
StringBuilder b = new StringBuilder ( ) ;
for ( String s : lines ) {
if ( s ! = null & & ! s . isEmpty ( ) ) {
b . append ( s ) ;
if ( ! s . endsWith ( "\n" ) ) {
b . append ( '\n' ) ;
}
}
}
return b . toString ( ) ;
}
public static boolean contains ( List < String > lines , String str ) {
for ( String s : lines ) {
if ( s . contains ( str ) ) {
return true ;
}
}
return false ;
}
}