diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/LsRemoteCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/LsRemoteCommandTest.java index 991214d58..f31276dee 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/LsRemoteCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/LsRemoteCommandTest.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011, Chris Aniszczyk + * Copyright (C) 2011, 2013 Chris Aniszczyk and others. * and other copyright owners as documented in the project's IP log. * * This program and the accompanying materials are made available @@ -128,4 +128,12 @@ public class LsRemoteCommandTest extends RepositoryTestCase { assertEquals(2, refs.size()); } + @Test + public void testLsRemoteWithoutLocalRepository() throws Exception { + String uri = "file://" + git.getRepository().getWorkTree().getPath(); + Collection refs = Git.lsRemoteRepository().setRemote(uri).setHeads(true).call(); + assertNotNull(refs); + assertEquals(2, refs.size()); + } + } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/Git.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/Git.java index 7a521263d..b643cbe25 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/Git.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/Git.java @@ -137,6 +137,17 @@ public class Git { return new CloneCommand(); } + /** + * Returns a command to list remote branches/tags without a local + * repository. + * + * @return a {@link LsRemoteCommand} + * @since 3.1 + */ + public static LsRemoteCommand lsRemoteRepository() { + return new LsRemoteCommand(null); + } + /** * Returns a command object to execute a {@code init} command * diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/LsRemoteCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/LsRemoteCommand.java index 3843dc4a1..55ca58f9c 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/LsRemoteCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/LsRemoteCommand.java @@ -61,6 +61,7 @@ import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.transport.FetchConnection; import org.eclipse.jgit.transport.RefSpec; import org.eclipse.jgit.transport.Transport; +import org.eclipse.jgit.transport.URIish; /** * The ls-remote command @@ -82,6 +83,8 @@ public class LsRemoteCommand extends /** * @param repo + * local repository or null for operation without local + * repository */ public LsRemoteCommand(Repository repo) { super(repo); @@ -155,7 +158,10 @@ public class LsRemoteCommand extends Transport transport = null; FetchConnection fc = null; try { - transport = Transport.open(repo, remote); + if (repo != null) + transport = Transport.open(repo, remote); + else + transport = Transport.open(new URIish(remote)); transport.setOptionUploadPack(uploadPack); configure(transport); Collection refSpecs = new ArrayList(1);