summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/FetchCommandTest.java85
1 files changed, 85 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/FetchCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/FetchCommandTest.java
index 83a0564c77..4a89a84cac 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/FetchCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/FetchCommandTest.java
@@ -102,6 +102,91 @@ public class FetchCommandTest extends RepositoryTestCase {
}
@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();
Ref tagRef = remoteGit.tag().setName("foo").call();