@ -90,7 +90,7 @@ public class PushCommandTest extends RepositoryTestCase {
remoteConfig . update ( config ) ;
remoteConfig . update ( config ) ;
config . save ( ) ;
config . save ( ) ;
Git git1 = new Git ( db ) ;
try ( Git git1 = new Git ( db ) ) {
// create some refs via commits and tag
// create some refs via commits and tag
RevCommit commit = git1 . commit ( ) . setMessage ( "initial commit" ) . call ( ) ;
RevCommit commit = git1 . commit ( ) . setMessage ( "initial commit" ) . call ( ) ;
Ref tagRef = git1 . tag ( ) . setName ( "tag" ) . call ( ) ;
Ref tagRef = git1 . tag ( ) . setName ( "tag" ) . call ( ) ;
@ -111,6 +111,7 @@ public class PushCommandTest extends RepositoryTestCase {
assertEquals ( tagRef . getObjectId ( ) ,
assertEquals ( tagRef . getObjectId ( ) ,
db2 . resolve ( tagRef . getObjectId ( ) . getName ( ) ) ) ;
db2 . resolve ( tagRef . getObjectId ( ) . getName ( ) ) ) ;
}
}
}
@Test
@Test
public void testPrePushHook ( ) throws JGitInternalException , IOException ,
public void testPrePushHook ( ) throws JGitInternalException , IOException ,
@ -132,7 +133,7 @@ public class PushCommandTest extends RepositoryTestCase {
+ hookOutput . toPath ( ) + "\"\ncat - >>\"" + hookOutput . toPath ( )
+ hookOutput . toPath ( ) + "\"\ncat - >>\"" + hookOutput . toPath ( )
+ "\"\nexit 0" ) ;
+ "\"\nexit 0" ) ;
Git git1 = new Git ( db ) ;
try ( Git git1 = new Git ( db ) ) {
// create some refs via commits and tag
// create some refs via commits and tag
RevCommit commit = git1 . commit ( ) . setMessage ( "initial commit" ) . call ( ) ;
RevCommit commit = git1 . commit ( ) . setMessage ( "initial commit" ) . call ( ) ;
@ -142,6 +143,7 @@ public class PushCommandTest extends RepositoryTestCase {
+ commit . getName ( ) + " refs/heads/x "
+ commit . getName ( ) + " refs/heads/x "
+ ObjectId . zeroId ( ) . name ( ) , read ( hookOutput ) ) ;
+ ObjectId . zeroId ( ) . name ( ) , read ( hookOutput ) ) ;
}
}
}
private File writeHookFile ( final String name , final String data )
private File writeHookFile ( final String name , final String data )
throws IOException {
throws IOException {
@ -160,8 +162,7 @@ public class PushCommandTest extends RepositoryTestCase {
String branch = "refs/heads/master" ;
String branch = "refs/heads/master" ;
String trackingBranch = "refs/remotes/" + remote + "/master" ;
String trackingBranch = "refs/remotes/" + remote + "/master" ;
Git git = new Git ( db ) ;
try ( Git git = new Git ( db ) ) {
RevCommit commit1 = git . commit ( ) . setMessage ( "Initial commit" )
RevCommit commit1 = git . commit ( ) . setMessage ( "Initial commit" )
. call ( ) ;
. call ( ) ;
@ -200,6 +201,7 @@ public class PushCommandTest extends RepositoryTestCase {
assertEquals ( commit2 . getId ( ) , db . resolve ( trackingBranch ) ) ;
assertEquals ( commit2 . getId ( ) , db . resolve ( trackingBranch ) ) ;
assertEquals ( commit2 . getId ( ) , db2 . resolve ( branch ) ) ;
assertEquals ( commit2 . getId ( ) , db2 . resolve ( branch ) ) ;
}
}
}
/ * *
/ * *
* Check that pushes over file protocol lead to appropriate ref - updates .
* Check that pushes over file protocol lead to appropriate ref - updates .
@ -208,9 +210,8 @@ public class PushCommandTest extends RepositoryTestCase {
* /
* /
@Test
@Test
public void testPushRefUpdate ( ) throws Exception {
public void testPushRefUpdate ( ) throws Exception {
Git git = new Git ( db ) ;
try ( Git git = new Git ( db ) ;
Git git2 = new Git ( createBareRepository ( ) ) ;
Git git2 = new Git ( createBareRepository ( ) ) ) {
final StoredConfig config = git . getRepository ( ) . getConfig ( ) ;
final StoredConfig config = git . getRepository ( ) . getConfig ( ) ;
RemoteConfig remoteConfig = new RemoteConfig ( config , "test" ) ;
RemoteConfig remoteConfig = new RemoteConfig ( config , "test" ) ;
URIish uri = new URIish ( git2 . getRepository ( ) . getDirectory ( ) . toURI ( )
URIish uri = new URIish ( git2 . getRepository ( ) . getDirectory ( ) . toURI ( )
@ -232,7 +233,6 @@ public class PushCommandTest extends RepositoryTestCase {
git . branchCreate ( ) . setName ( "refs/heads/test" ) . call ( ) ;
git . branchCreate ( ) . setName ( "refs/heads/test" ) . call ( ) ;
git . checkout ( ) . setName ( "refs/heads/test" ) . call ( ) ;
git . checkout ( ) . setName ( "refs/heads/test" ) . call ( ) ;
for ( int i = 0 ; i < 6 ; i + + ) {
for ( int i = 0 ; i < 6 ; i + + ) {
writeTrashFile ( "f" + i , "content of f" + i ) ;
writeTrashFile ( "f" + i , "content of f" + i ) ;
git . add ( ) . addFilepattern ( "f" + i ) . call ( ) ;
git . add ( ) . addFilepattern ( "f" + i ) . call ( ) ;
@ -241,7 +241,7 @@ public class PushCommandTest extends RepositoryTestCase {
git2 . getRepository ( ) . getAllRefs ( ) ;
git2 . getRepository ( ) . getAllRefs ( ) ;
assertEquals ( "failed to update on attempt " + i , commit . getId ( ) ,
assertEquals ( "failed to update on attempt " + i , commit . getId ( ) ,
git2 . getRepository ( ) . resolve ( "refs/heads/test" ) ) ;
git2 . getRepository ( ) . resolve ( "refs/heads/test" ) ) ;
}
}
}
}
}
@ -252,9 +252,8 @@ public class PushCommandTest extends RepositoryTestCase {
* /
* /
@Test
@Test
public void testPushWithRefSpecFromConfig ( ) throws Exception {
public void testPushWithRefSpecFromConfig ( ) throws Exception {
Git git = new Git ( db ) ;
try ( Git git = new Git ( db ) ;
Git git2 = new Git ( createBareRepository ( ) ) ;
Git git2 = new Git ( createBareRepository ( ) ) ) {
final StoredConfig config = git . getRepository ( ) . getConfig ( ) ;
final StoredConfig config = git . getRepository ( ) . getConfig ( ) ;
RemoteConfig remoteConfig = new RemoteConfig ( config , "test" ) ;
RemoteConfig remoteConfig = new RemoteConfig ( config , "test" ) ;
URIish uri = new URIish ( git2 . getRepository ( ) . getDirectory ( ) . toURI ( )
URIish uri = new URIish ( git2 . getRepository ( ) . getDirectory ( ) . toURI ( )
@ -272,8 +271,7 @@ public class PushCommandTest extends RepositoryTestCase {
git . push ( ) . setRemote ( "test" ) . call ( ) ;
git . push ( ) . setRemote ( "test" ) . call ( ) ;
assertEquals ( commit . getId ( ) ,
assertEquals ( commit . getId ( ) ,
git2 . getRepository ( ) . resolve ( "refs/heads/newbranch" ) ) ;
git2 . getRepository ( ) . resolve ( "refs/heads/newbranch" ) ) ;
}
}
}
/ * *
/ * *
@ -283,9 +281,8 @@ public class PushCommandTest extends RepositoryTestCase {
* /
* /
@Test
@Test
public void testPushWithoutPushRefSpec ( ) throws Exception {
public void testPushWithoutPushRefSpec ( ) throws Exception {
Git git = new Git ( db ) ;
try ( Git git = new Git ( db ) ;
Git git2 = new Git ( createBareRepository ( ) ) ;
Git git2 = new Git ( createBareRepository ( ) ) ) {
final StoredConfig config = git . getRepository ( ) . getConfig ( ) ;
final StoredConfig config = git . getRepository ( ) . getConfig ( ) ;
RemoteConfig remoteConfig = new RemoteConfig ( config , "test" ) ;
RemoteConfig remoteConfig = new RemoteConfig ( config , "test" ) ;
URIish uri = new URIish ( git2 . getRepository ( ) . getDirectory ( ) . toURI ( )
URIish uri = new URIish ( git2 . getRepository ( ) . getDirectory ( ) . toURI ( )
@ -314,7 +311,7 @@ public class PushCommandTest extends RepositoryTestCase {
assertEquals ( null , git2 . getRepository ( )
assertEquals ( null , git2 . getRepository ( )
. resolve ( "refs/heads/not-pushed" ) ) ;
. resolve ( "refs/heads/not-pushed" ) ) ;
assertEquals ( null , git2 . getRepository ( ) . resolve ( "refs/heads/master" ) ) ;
assertEquals ( null , git2 . getRepository ( ) . resolve ( "refs/heads/master" ) ) ;
}
}
}
/ * *
/ * *
@ -335,9 +332,8 @@ public class PushCommandTest extends RepositoryTestCase {
remoteConfig . update ( config ) ;
remoteConfig . update ( config ) ;
config . save ( ) ;
config . save ( ) ;
Git git1 = new Git ( db ) ;
try ( Git git1 = new Git ( db ) ;
Git git2 = new Git ( db2 ) ;
Git git2 = new Git ( db2 ) ) {
// push master (with a new commit) to the remote
// push master (with a new commit) to the remote
git1 . commit ( ) . setMessage ( "initial commit" ) . call ( ) ;
git1 . commit ( ) . setMessage ( "initial commit" ) . call ( ) ;
@ -382,4 +378,5 @@ public class PushCommandTest extends RepositoryTestCase {
assertEquals ( commit3 . getId ( ) ,
assertEquals ( commit3 . getId ( ) ,
db2 . resolve ( commit3 . getId ( ) . getName ( ) + "^{commit}" ) ) ;
db2 . resolve ( commit3 . getId ( ) . getName ( ) + "^{commit}" ) ) ;
}
}
}
}
}