Browse Source

Enable LsRemoteCommand to work without local repository

It's supported by C Git and can be useful.

Bug: 413388
Change-Id: I12c6c10e791cc09ee271d89eb8b8d32f53e385db
Signed-off-by: Robin Stocker <robin@nibor.org>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
tags/v3.1.0.201309270735-rc1
Robin Stocker 10 years ago
parent
commit
9b26e4bffb

+ 9
- 1
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/LsRemoteCommandTest.java View File

/* /*
* Copyright (C) 2011, Chris Aniszczyk <caniszczyk@gmail.com>
* Copyright (C) 2011, 2013 Chris Aniszczyk <caniszczyk@gmail.com> and others.
* and other copyright owners as documented in the project's IP log. * and other copyright owners as documented in the project's IP log.
* *
* This program and the accompanying materials are made available * This program and the accompanying materials are made available
assertEquals(2, refs.size()); assertEquals(2, refs.size());
} }


@Test
public void testLsRemoteWithoutLocalRepository() throws Exception {
String uri = "file://" + git.getRepository().getWorkTree().getPath();
Collection<Ref> refs = Git.lsRemoteRepository().setRemote(uri).setHeads(true).call();
assertNotNull(refs);
assertEquals(2, refs.size());
}

} }

+ 11
- 0
org.eclipse.jgit/src/org/eclipse/jgit/api/Git.java View File

return new CloneCommand(); 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 * Returns a command object to execute a {@code init} command
* *

+ 7
- 1
org.eclipse.jgit/src/org/eclipse/jgit/api/LsRemoteCommand.java View File

import org.eclipse.jgit.transport.FetchConnection; import org.eclipse.jgit.transport.FetchConnection;
import org.eclipse.jgit.transport.RefSpec; import org.eclipse.jgit.transport.RefSpec;
import org.eclipse.jgit.transport.Transport; import org.eclipse.jgit.transport.Transport;
import org.eclipse.jgit.transport.URIish;


/** /**
* The ls-remote command * The ls-remote command


/** /**
* @param repo * @param repo
* local repository or null for operation without local
* repository
*/ */
public LsRemoteCommand(Repository repo) { public LsRemoteCommand(Repository repo) {
super(repo); super(repo);
Transport transport = null; Transport transport = null;
FetchConnection fc = null; FetchConnection fc = null;
try { try {
transport = Transport.open(repo, remote);
if (repo != null)
transport = Transport.open(repo, remote);
else
transport = Transport.open(new URIish(remote));
transport.setOptionUploadPack(uploadPack); transport.setOptionUploadPack(uploadPack);
configure(transport); configure(transport);
Collection<RefSpec> refSpecs = new ArrayList<RefSpec>(1); Collection<RefSpec> refSpecs = new ArrayList<RefSpec>(1);

Loading…
Cancel
Save