List of usage examples for org.eclipse.jgit.api LsRemoteCommand LsRemoteCommand
public LsRemoteCommand(Repository repo)
From source file:de.egore911.versioning.util.vcs.GitProvider.java
License:Open Source License
@Override public boolean tagExistsImpl(String tagName) { InMemoryRepository repo = initRepository(); // Ask for the remote tags LsRemoteCommand command = new LsRemoteCommand(repo); command.setTags(true);// w w w. j a v a 2 s . c o m try { Collection<Ref> tags = command.call(); for (Ref tag : tags) { // Tag found, all is fine if (tag.getName().equals("refs/tags/" + tagName)) { return true; } } // Tag not found return false; } catch (GitAPIException e) { log.error(e.getMessage(), e); return false; } }
From source file:de.egore911.versioning.util.vcs.GitProvider.java
License:Open Source License
@Override protected List<Tag> getTagsImpl() { InMemoryRepository repo = initRepository(); List<Tag> result = new ArrayList<>(); // Ask for the remote tags LsRemoteCommand command = new LsRemoteCommand(repo); command.setTags(true);/*from w ww. j a v a2s.c o m*/ try { Collection<Ref> tags = command.call(); result.addAll(tags.stream().map(tag -> new Tag(null, tag.getName().replace("refs/tags/", ""))) .collect(Collectors.toList())); return result; } catch (GitAPIException e) { log.error(e.getMessage(), e); return Collections.emptyList(); } }
From source file:fr.treeptik.cloudunit.utils.GitUtils.java
License:Open Source License
/** * List all GIT Tags of an application with an index * After this index is use to choose on which tag user want to restre his application * with resetOnChosenGitTag() method/*from w ww . ja v a2 s.c o m*/ * * @param application * @param dockerManagerAddress * @param containerGitAddress * @return * @throws GitAPIException * @throws IOException */ public static List<String> listGitTagsOfApplication(Application application, String dockerManagerAddress, String containerGitAddress) throws GitAPIException, IOException { List<String> listTagsName = new ArrayList<>(); User user = application.getUser(); String sshPort = application.getServers().get(0).getSshPort(); String password = user.getPassword(); String userNameGit = user.getLogin(); String dockerManagerIP = dockerManagerAddress.substring(0, dockerManagerAddress.length() - 5); String remoteRepository = "ssh://" + userNameGit + "@" + dockerManagerIP + ":" + sshPort + containerGitAddress; Path myTempDirPath = Files.createTempDirectory(Paths.get("/tmp"), null); File gitworkDir = myTempDirPath.toFile(); InitCommand initCommand = Git.init(); initCommand.setDirectory(gitworkDir); initCommand.call(); FileRepository gitRepo = new FileRepository(gitworkDir); LsRemoteCommand lsRemoteCommand = new LsRemoteCommand(gitRepo); CredentialsProvider credentialsProvider = configCredentialsForGit(userNameGit, password); lsRemoteCommand.setCredentialsProvider(credentialsProvider); lsRemoteCommand.setRemote(remoteRepository); lsRemoteCommand.setTags(true); Collection<Ref> collectionRefs = lsRemoteCommand.call(); List<Ref> listRefs = new ArrayList<>(collectionRefs); for (Ref ref : listRefs) { listTagsName.add(ref.getName()); } Collections.sort(listTagsName); FilesUtils.deleteDirectory(gitworkDir); return listTagsName; }
From source file:org.gitective.core.RepositoryUtils.java
License:Open Source License
/** * List remote references and return all remote references that are missing * locally or have a different remote object id than the local reference. * * @param repository//from w w w .ja v a2 s . co m * @param remote * @return non-null but possibly collection of {@link RefDiff} */ public static Collection<RefDiff> diffRemoteRefs(final Repository repository, final String remote) { if (repository == null) throw new IllegalArgumentException(Assert.formatNotNull("Repository")); if (remote == null) throw new IllegalArgumentException(Assert.formatNotNull("Remote")); if (remote.length() == 0) throw new IllegalArgumentException(Assert.formatNotEmpty("Remote")); final LsRemoteCommand lsRemote = new LsRemoteCommand(repository); lsRemote.setRemote(remote); try { final Collection<Ref> remoteRefs = lsRemote.call(); final List<RefDiff> diffs = new ArrayList<RefDiff>(); if (hasRemote(repository, remote)) { final String refPrefix = R_REMOTES + remote + "/"; for (Ref remoteRef : remoteRefs) { String name = remoteRef.getName(); if (name.startsWith(R_HEADS)) name = refPrefix + name.substring(R_HEADS.length()); else if (!name.startsWith(R_TAGS)) name = refPrefix + name; final Ref localRef = repository.getRef(name); if (localRef == null || !remoteRef.getObjectId().equals(localRef.getObjectId())) diffs.add(new RefDiff(localRef, remoteRef)); } } else for (Ref remoteRef : remoteRefs) { final Ref localRef = repository.getRef(remoteRef.getName()); if (localRef == null || !remoteRef.getObjectId().equals(localRef.getObjectId())) diffs.add(new RefDiff(localRef, remoteRef)); } return diffs; } catch (Exception e) { throw new GitException(e, repository); } }
From source file:org.omegat.core.team.GITRemoteRepository.java
License:Open Source License
/** * Determines whether or not the supplied URL represents a valid Git repository. * // w ww . j a va 2 s . c om * <p>Does the equivalent of <code>git ls-remote <i>url</i></code>. * * @param url URL of supposed remote repository * @return true if repository appears to be valid, false otherwise */ public static boolean isGitRepository(String url, Credentials credentials) throws AuthenticationException { // Heuristics to save some waiting time if (url.startsWith("svn://") || url.startsWith("svn+")) { return false; } try { if (credentials != null) { MyCredentialsProvider provider = new MyCredentialsProvider(null); provider.setCredentials(credentials); CredentialsProvider.setDefault(provider); } Collection<Ref> result = new LsRemoteCommand(null).setRemote(url).call(); return !result.isEmpty(); } catch (TransportException ex) { String message = ex.getMessage(); if (message.endsWith("not authorized") || message.endsWith("Auth fail") || message.contains("Too many authentication failures") || message.contains("Authentication is required")) { throw new AuthenticationException(ex); } return false; } catch (GitAPIException ex) { throw new AuthenticationException(ex); } catch (JGitInternalException ex) { // Happens if the URL is a Subversion URL like svn://... return false; } }
From source file:org.omegat.core.team2.impl.GITRemoteRepository2.java
License:Open Source License
/** * Determines whether or not the supplied URL represents a valid Git repository. * // ww w.j a v a2 s .c o m * <p> * Does the equivalent of <code>git ls-remote <i>url</i></code>. * * @param url * URL of supposed remote repository * @return true if repository appears to be valid, false otherwise */ public static boolean isGitRepository(String url) { // Heuristics to save some waiting time try { Collection<Ref> result = new LsRemoteCommand(null).setRemote(url).call(); return !result.isEmpty(); } catch (TransportException ex) { String message = ex.getMessage(); if (message.endsWith("not authorized") || message.endsWith("Auth fail") || message.contains("Too many authentication failures") || message.contains("Authentication is required")) { return true; } return false; } catch (GitAPIException ex) { return false; } catch (JGitInternalException ex) { // Happens if the URL is a Subversion URL like svn://... return false; } }