@ -48,6 +48,7 @@ import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.lib.CLIRepositoryTestCase ;
import org.eclipse.jgit.lib.CLIRepositoryTestCase ;
import org.eclipse.jgit.revwalk.RevCommit ;
import org.eclipse.jgit.revwalk.RevCommit ;
import org.junit.Before ;
import org.junit.Before ;
import org.junit.Ignore ;
import org.junit.Test ;
import org.junit.Test ;
public class ResetTest extends CLIRepositoryTestCase {
public class ResetTest extends CLIRepositoryTestCase {
@ -61,6 +62,13 @@ public class ResetTest extends CLIRepositoryTestCase {
git = new Git ( db ) ;
git = new Git ( db ) ;
}
}
@Test
public void testZombieArgument_Bug484951 ( ) throws Exception {
String [ ] result = execute ( "git reset -h" ) ;
assertFalse ( "Unexpected argument: " + result [ 0 ] ,
result [ 0 ] . contains ( "[VAL ...]" ) ) ;
}
@Test
@Test
public void testResetSelf ( ) throws Exception {
public void testResetSelf ( ) throws Exception {
RevCommit commit = git . commit ( ) . setMessage ( "initial commit" ) . call ( ) ;
RevCommit commit = git . commit ( ) . setMessage ( "initial commit" ) . call ( ) ;
@ -91,15 +99,28 @@ public class ResetTest extends CLIRepositoryTestCase {
@Test
@Test
public void testResetPathDoubleDash ( ) throws Exception {
public void testResetPathDoubleDash ( ) throws Exception {
resetPath ( true ) ;
resetPath ( true , true ) ;
}
}
@Test
@Test
public void testResetPathNoDoubleDash ( ) throws Exception {
public void testResetPathNoDoubleDash ( ) throws Exception {
resetPath ( false ) ;
resetPath ( false , true ) ;
}
@Test
public void testResetPathDoubleDashNoRef ( ) throws Exception {
resetPath ( true , false ) ;
}
@Ignore ( "Currently we cannote recognize if a name is a commit-ish or a path, "
+ "so 'git reset a' will not work if 'a' is not a branch name but a file path" )
@Test
public void testResetPathNoDoubleDashNoRef ( ) throws Exception {
resetPath ( false , false ) ;
}
}
private void resetPath ( boolean useDoubleDash ) throws Exception {
private void resetPath ( boolean useDoubleDash , boolean supplyCommit )
throws Exception {
// create files a and b
// create files a and b
writeTrashFile ( "a" , "Hello world a" ) ;
writeTrashFile ( "a" , "Hello world a" ) ;
writeTrashFile ( "b" , "Hello world b" ) ;
writeTrashFile ( "b" , "Hello world b" ) ;
@ -115,8 +136,9 @@ public class ResetTest extends CLIRepositoryTestCase {
git . add ( ) . addFilepattern ( "." ) . call ( ) ;
git . add ( ) . addFilepattern ( "." ) . call ( ) ;
// reset only file a
// reset only file a
String cmd = String . format ( "git reset %s%s a" , commit . getId ( ) . name ( ) ,
String cmd = String . format ( "git reset %s%s a" ,
( useDoubleDash ) ? " --" : "" ) ;
supplyCommit ? commit . getId ( ) . name ( ) : "" ,
useDoubleDash ? " --" : "" ) ;
assertStringArrayEquals ( "" , execute ( cmd ) ) ;
assertStringArrayEquals ( "" , execute ( cmd ) ) ;
assertEquals ( commit . getId ( ) ,
assertEquals ( commit . getId ( ) ,
git . getRepository ( ) . exactRef ( "HEAD" ) . getObjectId ( ) ) ;
git . getRepository ( ) . exactRef ( "HEAD" ) . getObjectId ( ) ) ;