diff options
author | Stefan Lay <stefan.lay@sap.com> | 2011-07-04 13:20:51 +0200 |
---|---|---|
committer | Stefan Lay <stefan.lay@sap.com> | 2011-07-04 13:20:51 +0200 |
commit | e2815f0121332a9df3fa35ca6e4c8d28239ea8c4 (patch) | |
tree | 2c4a7cec3a24b4bd2c16251c7a71a1778672c4ab /org.eclipse.jgit.test | |
parent | eb46d7ffdc6dee1f8570d4be3b6c33cee8fa91c7 (diff) | |
download | jgit-e2815f0121332a9df3fa35ca6e4c8d28239ea8c4.tar.gz jgit-e2815f0121332a9df3fa35ca6e4c8d28239ea8c4.zip |
Add lookup to remote config if the refSpec is not explicitly set
If no refSpec is explicitly set, the PushCommand should first check the
remote config and then as a fallback use the current behavior.
Change-Id: I2bc648abc517b1d01b2de15d383423ace2081e72
Signed-off-by: Stefan Lay <stefan.lay@sap.com>
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PushCommandTest.java | 72 |
1 files changed, 72 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")); + + } } |