List of usage examples for org.eclipse.jgit.api LsRemoteCommand setTags
public LsRemoteCommand setTags(boolean tags)
From source file:bluej.groupwork.git.GitProvider.java
License:Open Source License
@Override public TeamworkCommandResult checkConnection(TeamSettings settings) { try {/*from w w w . j a v a 2 s. c o m*/ String gitUrl = makeGitUrl(settings); //perform a lsRemote on the remote git repo. LsRemoteCommand lsRemoteCommand = Git.lsRemoteRepository(); UsernamePasswordCredentialsProvider cp = new UsernamePasswordCredentialsProvider(settings.getUserName(), settings.getPassword()); // set a configuration with username and password. lsRemoteCommand.setRemote(gitUrl); //configure remote repository address. lsRemoteCommand.setCredentialsProvider(cp); //associate the repository to the username and password. lsRemoteCommand.setTags(false); //disable refs/tags in reference results lsRemoteCommand.setHeads(false); //disable refs/heads in reference results //It seems that ssh host fingerprint check is not working properly. //Disable it in a ssh connection. if (gitUrl.startsWith("ssh")) { SshSessionFactory sshSessionFactory = new JschConfigSessionFactory() { @Override protected void configure(OpenSshConfig.Host host, Session sn) { java.util.Properties config = new java.util.Properties(); config.put("StrictHostKeyChecking", "no"); sn.setConfig(config); } @Override protected JSch createDefaultJSch(FS fs) throws JSchException { return super.createDefaultJSch(fs); } }; lsRemoteCommand.setTransportConfigCallback((Transport t) -> { SshTransport sshTransport = (SshTransport) t; sshTransport.setSshSessionFactory(sshSessionFactory); }); } lsRemoteCommand.call(); //executes the lsRemote commnand. } catch (GitAPIException ex) { return new TeamworkCommandError(ex.getMessage(), ex.getLocalizedMessage()); } catch (UnsupportedSettingException ex) { return new TeamworkCommandUnsupportedSetting(ex.getMessage()); } //if we got here, it means the command was successful. return new TeamworkCommandResult(); }
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); try {//from w w w . j a v a 2 s . c om 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); try {/*from ww w .jav a2 s.c om*/ 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/*w ww . j ava 2s . co 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; }