Repository: camel Updated Branches: refs/heads/master d8a377579 -> 23b13a1e1
CAMEL-10145: Camel-Git: Pull and Push operations require the remote Name and not the remote Path to git repository Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/23b13a1e Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/23b13a1e Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/23b13a1e Branch: refs/heads/master Commit: 23b13a1e14ca7e7d65f4a6d5f68f7d33deeec83a Parents: d8a3775 Author: Andrea Cosentino <anco...@gmail.com> Authored: Thu Jul 14 10:46:43 2016 +0200 Committer: Andrea Cosentino <anco...@gmail.com> Committed: Thu Jul 14 10:46:43 2016 +0200 ---------------------------------------------------------------------- components/camel-git/src/main/docs/git.adoc | 5 ++++- .../org/apache/camel/component/git/GitEndpoint.java | 14 ++++++++++++++ .../camel/component/git/producer/GitProducer.java | 16 ++++++++-------- .../component/git/producer/GitProducerTest.java | 12 ++++++++++++ 4 files changed, 38 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/23b13a1e/components/camel-git/src/main/docs/git.adoc ---------------------------------------------------------------------- diff --git a/components/camel-git/src/main/docs/git.adoc b/components/camel-git/src/main/docs/git.adoc index 5e802de..e2e68b4 100644 --- a/components/camel-git/src/main/docs/git.adoc +++ b/components/camel-git/src/main/docs/git.adoc @@ -38,8 +38,9 @@ The Git component has no options. + // endpoint options: START -The Git component supports 12 endpoint options which are listed below: +The Git component supports 13 endpoint options which are listed below: {% raw %} [width="100%",cols="2s,1,1m,1m,5",options="header"] @@ -48,6 +49,7 @@ The Git component supports 12 endpoint options which are listed below: | localPath | common | | String | *Required* Local repository path | branchName | common | | String | The branch name to work on | password | common | | String | Remote repository password +| remoteName | common | | String | The remote repository name to use in particular operation like pull | remotePath | common | | String | The remote repository path | tagName | common | | String | The tag name to work on | username | common | | String | Remote repository username @@ -63,6 +65,7 @@ The Git component supports 12 endpoint options which are listed below: + [[Git-MessageHeaders]] Message Headers ^^^^^^^^^^^^^^^ http://git-wip-us.apache.org/repos/asf/camel/blob/23b13a1e/components/camel-git/src/main/java/org/apache/camel/component/git/GitEndpoint.java ---------------------------------------------------------------------- diff --git a/components/camel-git/src/main/java/org/apache/camel/component/git/GitEndpoint.java b/components/camel-git/src/main/java/org/apache/camel/component/git/GitEndpoint.java index 71f2ab0..d25dbb2 100644 --- a/components/camel-git/src/main/java/org/apache/camel/component/git/GitEndpoint.java +++ b/components/camel-git/src/main/java/org/apache/camel/component/git/GitEndpoint.java @@ -57,6 +57,9 @@ public class GitEndpoint extends DefaultEndpoint { @UriParam private String remotePath; + + @UriParam + private String remoteName; @UriParam(enums = "clone,init,add,remove,commit,commitAll,createBranch,deleteBranch,createTag,deleteTag,status,log,push,pull,showBranches,cherryPick", label = "producer") private String operation; @@ -175,5 +178,16 @@ public class GitEndpoint extends DefaultEndpoint { public void setTagName(String tagName) { this.tagName = tagName; } + + /** + * The remote repository name to use in particular operation like pull + */ + public String getRemoteName() { + return remoteName; + } + + public void setRemoteName(String remoteName) { + this.remoteName = remoteName; + } } http://git-wip-us.apache.org/repos/asf/camel/blob/23b13a1e/components/camel-git/src/main/java/org/apache/camel/component/git/producer/GitProducer.java ---------------------------------------------------------------------- diff --git a/components/camel-git/src/main/java/org/apache/camel/component/git/producer/GitProducer.java b/components/camel-git/src/main/java/org/apache/camel/component/git/producer/GitProducer.java index 5c16ef3..be7ef1d 100644 --- a/components/camel-git/src/main/java/org/apache/camel/component/git/producer/GitProducer.java +++ b/components/camel-git/src/main/java/org/apache/camel/component/git/producer/GitProducer.java @@ -346,17 +346,17 @@ public class GitProducer extends DefaultProducer { protected void doPush(Exchange exchange, String operation) throws Exception { Iterable<PushResult> result = null; try { - if (ObjectHelper.isEmpty(endpoint.getRemotePath())) { - throw new IllegalArgumentException("Remote path must be specified to execute " + operation); + if (ObjectHelper.isEmpty(endpoint.getRemoteName())) { + throw new IllegalArgumentException("Remote name must be specified to execute " + operation); } if (ObjectHelper.isNotEmpty(endpoint.getBranchName())) { git.checkout().setCreateBranch(false).setName(endpoint.getBranchName()).call(); } if (ObjectHelper.isNotEmpty(endpoint.getUsername()) && ObjectHelper.isNotEmpty(endpoint.getPassword())) { UsernamePasswordCredentialsProvider credentials = new UsernamePasswordCredentialsProvider(endpoint.getUsername(), endpoint.getPassword()); - result = git.push().setCredentialsProvider(credentials).setRemote(endpoint.getRemotePath()).call(); + result = git.push().setCredentialsProvider(credentials).setRemote(endpoint.getRemoteName()).call(); } else { - result = git.push().setRemote(endpoint.getRemotePath()).call(); + result = git.push().setRemote(endpoint.getRemoteName()).call(); } } catch (Exception e) { LOG.error("There was an error in Git " + operation + " operation"); @@ -368,17 +368,17 @@ public class GitProducer extends DefaultProducer { protected void doPull(Exchange exchange, String operation) throws Exception { PullResult result = null; try { - if (ObjectHelper.isEmpty(endpoint.getRemotePath())) { - throw new IllegalArgumentException("Remote path must be specified to execute " + operation); + if (ObjectHelper.isEmpty(endpoint.getRemoteName())) { + throw new IllegalArgumentException("Remote name must be specified to execute " + operation); } if (ObjectHelper.isNotEmpty(endpoint.getBranchName())) { git.checkout().setCreateBranch(false).setName(endpoint.getBranchName()).call(); } if (ObjectHelper.isNotEmpty(endpoint.getUsername()) && ObjectHelper.isNotEmpty(endpoint.getPassword())) { UsernamePasswordCredentialsProvider credentials = new UsernamePasswordCredentialsProvider(endpoint.getUsername(), endpoint.getPassword()); - result = git.pull().setCredentialsProvider(credentials).setRemote(endpoint.getRemotePath()).call(); + result = git.pull().setCredentialsProvider(credentials).setRemote(endpoint.getRemoteName()).call(); } else { - result = git.pull().setRemote(endpoint.getRemotePath()).call(); + result = git.pull().setRemote(endpoint.getRemoteName()).call(); } } catch (Exception e) { LOG.error("There was an error in Git " + operation + " operation"); http://git-wip-us.apache.org/repos/asf/camel/blob/23b13a1e/components/camel-git/src/test/java/org/apache/camel/component/git/producer/GitProducerTest.java ---------------------------------------------------------------------- diff --git a/components/camel-git/src/test/java/org/apache/camel/component/git/producer/GitProducerTest.java b/components/camel-git/src/test/java/org/apache/camel/component/git/producer/GitProducerTest.java index a9000df..6dc66ed 100755 --- a/components/camel-git/src/test/java/org/apache/camel/component/git/producer/GitProducerTest.java +++ b/components/camel-git/src/test/java/org/apache/camel/component/git/producer/GitProducerTest.java @@ -27,6 +27,7 @@ import org.apache.camel.component.git.GitConstants; import org.apache.camel.component.git.GitTestSupport; import org.eclipse.jgit.api.CreateBranchCommand.SetupUpstreamMode; import org.eclipse.jgit.api.Git; +import org.eclipse.jgit.api.PullResult; import org.eclipse.jgit.api.Status; import org.eclipse.jgit.lib.Ref; import org.eclipse.jgit.lib.Repository; @@ -58,6 +59,15 @@ public class GitProducerTest extends GitTestSupport { } @Test + public void pullTest() throws Exception { + template.sendBody("direct:clone", ""); + File gitDir = new File(gitLocalRepo, ".git"); + assertEquals(gitDir.exists(), true); + PullResult pr = template.requestBody("direct:pull", "", PullResult.class); + assertTrue(pr.isSuccessful()); + } + + @Test public void addTest() throws Exception { Repository repository = getTestRepository(); @@ -1096,6 +1106,8 @@ public class GitProducerTest extends GitTestSupport { .to("git://" + gitLocalRepo + "?operation=cherryPick&branchName=" + branchTest); from("direct:cherrypick-master") .to("git://" + gitLocalRepo + "?operation=cherryPick&branchName=refs/heads/master"); + from("direct:pull") + .to("git://" + gitLocalRepo + "?remoteName=origin&operation=pull"); } }; }