Browse Source

FetchCommandTest: test add/update/delete fetch

Change-Id: I2442394fb7eae5b3715779555477dd27b274ee83
Signed-off-by: Marc Strapetz <marc.strapetz@syntevo.com>
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
stable-4.9
Marc Strapetz 7 years ago committed by Thomas Wolf
parent
commit
109c07ac8e
  1. 85
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/FetchCommandTest.java

85
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/FetchCommandTest.java

@ -101,6 +101,91 @@ public class FetchCommandTest extends RepositoryTestCase {
db.resolve(tagRef.getObjectId().getName()));
}
@Test
public void fetchAddsBranches() throws Exception {
final String branch1 = "b1";
final String branch2 = "b2";
final String remoteBranch1 = "test/" + branch1;
final String remoteBranch2 = "test/" + branch2;
remoteGit.commit().setMessage("commit").call();
Ref branchRef1 = remoteGit.branchCreate().setName(branch1).call();
remoteGit.commit().setMessage("commit").call();
Ref branchRef2 = remoteGit.branchCreate().setName(branch2).call();
String spec = "refs/heads/*:refs/remotes/test/*";
git.fetch().setRemote("test").setRefSpecs(spec).call();
assertEquals(branchRef1.getObjectId(), db.resolve(remoteBranch1));
assertEquals(branchRef2.getObjectId(), db.resolve(remoteBranch2));
}
@Test
public void fetchDoesntDeleteBranches() throws Exception {
final String branch1 = "b1";
final String branch2 = "b2";
final String remoteBranch1 = "test/" + branch1;
final String remoteBranch2 = "test/" + branch2;
remoteGit.commit().setMessage("commit").call();
Ref branchRef1 = remoteGit.branchCreate().setName(branch1).call();
remoteGit.commit().setMessage("commit").call();
Ref branchRef2 = remoteGit.branchCreate().setName(branch2).call();
String spec = "refs/heads/*:refs/remotes/test/*";
git.fetch().setRemote("test").setRefSpecs(spec).call();
assertEquals(branchRef1.getObjectId(), db.resolve(remoteBranch1));
assertEquals(branchRef2.getObjectId(), db.resolve(remoteBranch2));
remoteGit.branchDelete().setBranchNames(branch1).call();
git.fetch().setRemote("test").setRefSpecs(spec).call();
assertEquals(branchRef1.getObjectId(), db.resolve(remoteBranch1));
assertEquals(branchRef2.getObjectId(), db.resolve(remoteBranch2));
}
@Test
public void fetchUpdatesBranches() throws Exception {
final String branch1 = "b1";
final String branch2 = "b2";
final String remoteBranch1 = "test/" + branch1;
final String remoteBranch2 = "test/" + branch2;
remoteGit.commit().setMessage("commit").call();
Ref branchRef1 = remoteGit.branchCreate().setName(branch1).call();
remoteGit.commit().setMessage("commit").call();
Ref branchRef2 = remoteGit.branchCreate().setName(branch2).call();
String spec = "refs/heads/*:refs/remotes/test/*";
git.fetch().setRemote("test").setRefSpecs(spec).call();
assertEquals(branchRef1.getObjectId(), db.resolve(remoteBranch1));
assertEquals(branchRef2.getObjectId(), db.resolve(remoteBranch2));
remoteGit.commit().setMessage("commit").call();
branchRef2 = remoteGit.branchCreate().setName(branch2).setForce(true).call();
git.fetch().setRemote("test").setRefSpecs(spec).call();
assertEquals(branchRef1.getObjectId(), db.resolve(remoteBranch1));
assertEquals(branchRef2.getObjectId(), db.resolve(remoteBranch2));
}
@Test
public void fetchPrunesBranches() throws Exception {
final String branch1 = "b1";
final String branch2 = "b2";
final String remoteBranch1 = "test/" + branch1;
final String remoteBranch2 = "test/" + branch2;
remoteGit.commit().setMessage("commit").call();
Ref branchRef1 = remoteGit.branchCreate().setName(branch1).call();
remoteGit.commit().setMessage("commit").call();
Ref branchRef2 = remoteGit.branchCreate().setName(branch2).call();
String spec = "refs/heads/*:refs/remotes/test/*";
git.fetch().setRemote("test").setRefSpecs(spec).call();
assertEquals(branchRef1.getObjectId(), db.resolve(remoteBranch1));
assertEquals(branchRef2.getObjectId(), db.resolve(remoteBranch2));
remoteGit.branchDelete().setBranchNames(branch1).call();
git.fetch().setRemote("test").setRefSpecs(spec)
.setRemoveDeletedRefs(true).call();
assertNull(db.resolve(remoteBranch1));
assertEquals(branchRef2.getObjectId(), db.resolve(remoteBranch2));
}
@Test
public void fetchShouldAutoFollowTag() throws Exception {
remoteGit.commit().setMessage("commit").call();

Loading…
Cancel
Save