summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Halstrick <christian.halstrick@gmail.com>2011-07-06 04:14:49 -0400
committerCode Review <codereview-daemon@eclipse.org>2011-07-06 04:14:49 -0400
commit18e10b41c919220fa774ada0a9d9ca94f286a099 (patch)
tree68f39ae2314917dd2f5905541083b8b8d7d8a489
parentac56c024c119c9782beb83f022deb3b258b754dc (diff)
parente2815f0121332a9df3fa35ca6e4c8d28239ea8c4 (diff)
downloadjgit-18e10b41c919220fa774ada0a9d9ca94f286a099.tar.gz
jgit-18e10b41c919220fa774ada0a9d9ca94f286a099.zip
Merge "Add lookup to remote config if the refSpec is not explicitly set"
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PushCommandTest.java72
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/api/PushCommand.java5
2 files changed, 77 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 760d31a349..d5ae0c9930 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
@@ -195,4 +195,76 @@ public class PushCommandTest extends RepositoryTestCase {
}
}
+
+ /**
+ * Check that the push refspec is read from config.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testPushWithRefSpecFromConfig() throws Exception {
+ Git git = new Git(db);
+ Git git2 = new Git(createBareRepository());
+
+ final StoredConfig config = git.getRepository().getConfig();
+ RemoteConfig remoteConfig = new RemoteConfig(config, "test");
+ URIish uri = new URIish(git2.getRepository().getDirectory().toURI()
+ .toURL());
+ remoteConfig.addURI(uri);
+ remoteConfig.addPushRefSpec(new RefSpec("HEAD:refs/heads/newbranch"));
+ remoteConfig.update(config);
+ config.save();
+
+ writeTrashFile("f", "content of f");
+ git.add().addFilepattern("f").call();
+ RevCommit commit = git.commit().setMessage("adding f").call();
+
+ assertEquals(null, git2.getRepository().resolve("refs/heads/master"));
+ git.push().setRemote("test").call();
+ assertEquals(commit.getId(),
+ git2.getRepository().resolve("refs/heads/newbranch"));
+
+
+ }
+
+ /**
+ * Check that only HEAD is pushed if no refspec is given.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testPushWithoutPushRefSpec() throws Exception {
+ Git git = new Git(db);
+ Git git2 = new Git(createBareRepository());
+
+ final StoredConfig config = git.getRepository().getConfig();
+ RemoteConfig remoteConfig = new RemoteConfig(config, "test");
+ URIish uri = new URIish(git2.getRepository().getDirectory().toURI()
+ .toURL());
+ remoteConfig.addURI(uri);
+ remoteConfig.addFetchRefSpec(new RefSpec(
+ "+refs/heads/*:refs/remotes/origin/*"));
+ remoteConfig.update(config);
+ config.save();
+
+ writeTrashFile("f", "content of f");
+ git.add().addFilepattern("f").call();
+ RevCommit commit = git.commit().setMessage("adding f").call();
+
+ git.checkout().setName("not-pushed").setCreateBranch(true).call();
+ git.checkout().setName("branchtopush").setCreateBranch(true).call();
+
+ assertEquals(null,
+ git2.getRepository().resolve("refs/heads/branchtopush"));
+ assertEquals(null, git2.getRepository()
+ .resolve("refs/heads/not-pushed"));
+ assertEquals(null, git2.getRepository().resolve("refs/heads/master"));
+ git.push().setRemote("test").call();
+ assertEquals(commit.getId(),
+ git2.getRepository().resolve("refs/heads/branchtopush"));
+ assertEquals(null, git2.getRepository()
+ .resolve("refs/heads/not-pushed"));
+ assertEquals(null, git2.getRepository().resolve("refs/heads/master"));
+
+ }
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/PushCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/PushCommand.java
index 40bade8840..f843a02441 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/api/PushCommand.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/PushCommand.java
@@ -125,6 +125,11 @@ public class PushCommand extends GitCommand<Iterable<PushResult>> {
try {
if (refSpecs.isEmpty()) {
+ RemoteConfig config = new RemoteConfig(repo.getConfig(),
+ getRemote());
+ refSpecs.addAll(config.getPushRefSpecs());
+ }
+ if (refSpecs.isEmpty()) {
Ref head = repo.getRef(Constants.HEAD);
if (head != null && head.isSymbolic())
refSpecs.add(new RefSpec(head.getLeaf().getName()));