aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobin Stocker2011-02-28 13:12:37 (EST)
committerRobin Stocker2011-03-04 09:45:18 (EST)
commit4fb185ab67bcea83c16855fc7e777faeb25ffd60 (patch)
tree91379c4f318804c837334715e49f59e7c574f706
parent18833252c6c0fdad26d9bf140c5be937943eaf34 (diff)
downloadjgit-4fb185ab67bcea83c16855fc7e777faeb25ffd60.zip
jgit-4fb185ab67bcea83c16855fc7e777faeb25ffd60.tar.gz
jgit-4fb185ab67bcea83c16855fc7e777faeb25ffd60.tar.bz2
PushCommand: Test for update of tracking branchrefs/changes/39/2639/2
Bug 317411 (Push does not update remote tracking branch) is assigned to JGit. This test verifies that JGit does the right thing. Bug: 317411 Change-Id: I8f632e3e6c8a4f16a1170b1dba92e8fd3d6267d0
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PushCommandTest.java53
1 files changed, 53 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PushCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PushCommandTest.java
index a324926..6a28605 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PushCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PushCommandTest.java
@@ -43,6 +43,7 @@
package org.eclipse.jgit.api;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
import java.io.IOException;
@@ -51,13 +52,16 @@ import java.net.URISyntaxException;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.JGitInternalException;
import org.eclipse.jgit.errors.MissingObjectException;
+import org.eclipse.jgit.lib.RefUpdate;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.RepositoryTestCase;
import org.eclipse.jgit.lib.StoredConfig;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevTag;
+import org.eclipse.jgit.transport.PushResult;
import org.eclipse.jgit.transport.RefSpec;
import org.eclipse.jgit.transport.RemoteConfig;
+import org.eclipse.jgit.transport.TrackingRefUpdate;
import org.eclipse.jgit.transport.URIish;
import org.junit.Test;
@@ -99,4 +103,53 @@ public class PushCommandTest extends RepositoryTestCase {
assertEquals(tag.getId(), db2.resolve(tag.getId().getName()));
}
+ @Test
+ public void testTrackingUpdate() throws Exception {
+ Repository db2 = createBareRepository();
+
+ String remote = "origin";
+ String branch = "refs/heads/master";
+ String trackingBranch = "refs/remotes/" + remote + "/master";
+
+ Git git = new Git(db);
+
+ RevCommit commit1 = git.commit().setMessage("Initial commit")
+ .call();
+
+ RefUpdate branchRefUpdate = db.updateRef(branch);
+ branchRefUpdate.setNewObjectId(commit1.getId());
+ branchRefUpdate.update();
+
+ RefUpdate trackingBranchRefUpdate = db.updateRef(trackingBranch);
+ trackingBranchRefUpdate.setNewObjectId(commit1.getId());
+ trackingBranchRefUpdate.update();
+
+ final StoredConfig config = db.getConfig();
+ RemoteConfig remoteConfig = new RemoteConfig(config, remote);
+ URIish uri = new URIish(db2.getDirectory().toURI().toURL());
+ remoteConfig.addURI(uri);
+ remoteConfig.addFetchRefSpec(new RefSpec("+refs/heads/*:refs/remotes/"
+ + remote + "/*"));
+ remoteConfig.update(config);
+ config.save();
+
+
+ RevCommit commit2 = git.commit().setMessage("Commit to push").call();
+
+ RefSpec spec = new RefSpec(branch + ":" + branch);
+ Iterable<PushResult> resultIterable = git.push().setRemote(remote)
+ .setRefSpecs(spec).call();
+
+ PushResult result = resultIterable.iterator().next();
+ TrackingRefUpdate trackingRefUpdate = result
+ .getTrackingRefUpdate(trackingBranch);
+
+ assertNotNull(trackingRefUpdate);
+ assertEquals(trackingBranch, trackingRefUpdate.getLocalName());
+ assertEquals(branch, trackingRefUpdate.getRemoteName());
+ assertEquals(commit2.getId(), trackingRefUpdate.getNewObjectId());
+ assertEquals(commit2.getId(), db.resolve(trackingBranch));
+ assertEquals(commit2.getId(), db2.resolve(branch));
+ }
+
}