List of usage examples for org.eclipse.jgit.api ListTagCommand call
@Override public List<Ref> call() throws GitAPIException
From source file:fr.treeptik.cloudunit.utils.GitUtils.java
License:Open Source License
/** * this method is associate with listGitTagsOfApplication() method * which list all tags with index, this is this index which must pass as parammeter of this method * * @param application//w w w . j av a 2 s. com * @param indexChosen * @param dockerManagerAddress * @param containerGitAddress * @return * @throws InvalidRemoteException * @throws TransportException * @throws GitAPIException * @throws IOException */ public static List<String> resetOnChosenGitTag(Application application, int indexChosen, String dockerManagerAddress, String containerGitAddress) throws InvalidRemoteException, TransportException, GitAPIException, IOException { 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; File gitworkDir = Files.createTempDirectory("clone").toFile(); CloneCommand clone = Git.cloneRepository(); clone.setDirectory(gitworkDir); CredentialsProvider credentialsProvider = configCredentialsForGit(userNameGit, password); clone.setCredentialsProvider(credentialsProvider); clone.setURI(remoteRepository); Git git = clone.call(); ListTagCommand listTagCommand = git.tagList(); List<Ref> listRefs = listTagCommand.call(); Ref ref = listRefs.get(indexChosen); ResetCommand resetCommand = git.reset(); resetCommand.setMode(ResetType.HARD); resetCommand.setRef(ref.getName()); resetCommand.call(); PushCommand pushCommand = git.push(); pushCommand.setCredentialsProvider(credentialsProvider); pushCommand.setForce(true); List<PushResult> listPushResults = (List<PushResult>) pushCommand.call(); List<String> listPushResultsMessages = new ArrayList<>(); for (PushResult pushResult : listPushResults) { listPushResultsMessages.add(pushResult.getMessages()); } FilesUtils.deleteDirectory(gitworkDir); return listPushResultsMessages; }
From source file:org.modeshape.connector.git.GitFunction.java
License:Apache License
/** * Add the names of the tags as children of the current node. * //from www .j av a 2s . c om * @param git the Git object; may not be null * @param spec the call specification; may not be null * @param writer the document writer for the current node; may not be null * @throws GitAPIException if there is a problem accessing the Git repository */ protected void addTagsAsChildren(Git git, CallSpecification spec, DocumentWriter writer) throws GitAPIException { // Generate the child references to the branches, which will be sorted by name (by the command). ListTagCommand command = git.tagList(); List<Ref> tags = command.call(); // Reverse the sort of the branch names, since they might be version numbers ... Collections.sort(tags, REVERSE_REF_COMPARATOR); for (Ref ref : tags) { String fullName = ref.getName(); String name = fullName.replaceFirst(TAG_PREFIX, ""); writer.addChild(spec.childId(name), name); } }
From source file:org.modeshape.connector.git.GitFunctionalTest.java
License:Apache License
@Test public void shouldGetTags() throws Exception { // print = true; ListTagCommand command = git.tagList(); for (Ref ref : command.call()) { String fullName = ref.getName(); String name = fullName.replaceFirst("refs/tags/", ""); print(fullName + " \t--> " + name); }/*from w w w . j av a 2 s. c om*/ }