summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.pgm
diff options
context:
space:
mode:
authorMatthias Sohn <matthias.sohn@sap.com>2014-11-23 23:57:51 +0100
committerMatthias Sohn <matthias.sohn@sap.com>2014-12-15 15:59:38 +0100
commit816de9e9fae04260edd8e288c150e6f148fd04ce (patch)
tree6f51e0e74c2e7ce8cd875e8bb25ef2b72194bae0 /org.eclipse.jgit.pgm
parent53ff0529988ae8ec6f75a1f3d1b7b75de7dc304f (diff)
downloadjgit-816de9e9fae04260edd8e288c150e6f148fd04ce.tar.gz
jgit-816de9e9fae04260edd8e288c150e6f148fd04ce.zip
[pgm] Use LsRemoteCommand to implement ls-remote and add a test
Change-Id: Ic266f844c23e2519df5770ca56284b26e4cfe1f4 Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.jgit.pgm')
-rw-r--r--org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/LsRemote.java34
1 files changed, 18 insertions, 16 deletions
diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/LsRemote.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/LsRemote.java
index 93fcd66c55..0200d8cfde 100644
--- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/LsRemote.java
+++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/LsRemote.java
@@ -46,13 +46,15 @@
package org.eclipse.jgit.pgm;
import java.io.IOException;
+import java.util.Comparator;
+import java.util.TreeSet;
-import org.kohsuke.args4j.Argument;
-import org.kohsuke.args4j.Option;
+import org.eclipse.jgit.api.Git;
+import org.eclipse.jgit.api.LsRemoteCommand;
import org.eclipse.jgit.lib.AnyObjectId;
import org.eclipse.jgit.lib.Ref;
-import org.eclipse.jgit.transport.FetchConnection;
-import org.eclipse.jgit.transport.Transport;
+import org.kohsuke.args4j.Argument;
+import org.kohsuke.args4j.Option;
@Command(common = true, usage = "usage_LsRemote")
class LsRemote extends TextBuiltin {
@@ -64,19 +66,19 @@ class LsRemote extends TextBuiltin {
@Override
protected void run() throws Exception {
- final Transport tn = Transport.open(db, remote);
- if (0 <= timeout)
- tn.setTimeout(timeout);
- final FetchConnection c = tn.openFetch();
- try {
- for (final Ref r : c.getRefs()) {
- show(r.getObjectId(), r.getName());
- if (r.getPeeledObjectId() != null)
- show(r.getPeeledObjectId(), r.getName() + "^{}"); //$NON-NLS-1$
+ LsRemoteCommand command = Git.lsRemoteRepository().setRemote(remote)
+ .setTimeout(timeout);
+ TreeSet<Ref> refs = new TreeSet<Ref>(new Comparator<Ref>() {
+
+ public int compare(Ref r1, Ref r2) {
+ return r1.getName().compareTo(r2.getName());
}
- } finally {
- c.close();
- tn.close();
+ });
+ refs.addAll(command.call());
+ for (final Ref r : refs) {
+ show(r.getObjectId(), r.getName());
+ if (r.getPeeledObjectId() != null)
+ show(r.getPeeledObjectId(), r.getName() + "^{}"); //$NON-NLS-1$
}
}