org.eclipse.jgit.transport.TagOpt Java Examples

The following examples show how to use org.eclipse.jgit.transport.TagOpt. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JgitTests.java    From super-cloudops with Apache License 2.0 6 votes vote down vote up
@Test
public void tagListTest() throws IOException, GitAPIException {
    Git git = Git.open(new File(gitPath));
    /*ListTagCommand listTagCommand = git.tagList();
    List<Ref> call = listTagCommand.call();
    for(Ref ref : call){
        System.out.println(ref.getName());
    }*/

    //
    FetchCommand fetchCommand = git.fetch().setTagOpt(TagOpt.FETCH_TAGS);
    fetchCommand.setCredentialsProvider(usernamePasswordCredentialsProvider);
    fetchCommand.call();
    List<Ref> tags = git.tagList().call();
    if(tags != null && tags.size() > 0) {
        for(Ref tag : tags) {
            System.out.println(tag.getName());
        }
    }
}
 
Example #2
Source File: JgitTests.java    From super-cloudops with Apache License 2.0 5 votes vote down vote up
@Test
public void checkoutBranch() throws IOException, GitAPIException {
    String branchName = "branch1";

    Git git = Git.open(new File(gitPath));
    FetchCommand fetchCommand = git.fetch().setTagOpt(TagOpt.FETCH_TAGS);
    fetchCommand.setCredentialsProvider(usernamePasswordCredentialsProvider);
    fetchCommand.call();


    List<Ref> refs = git.branchList().call();
    boolean exist = false;// is branch exist
    for (Ref ref : refs) {
        String branchNameHad = getBranchName(ref);
        if (StringUtils.equals(branchName, branchNameHad)) {
            exist = true;
        }
    }
    if (exist) { // Exist to checkout
        git.checkout().setName(branchName).call();
    } else { // Not exist to checkout & create local branch
        git.checkout().setCreateBranch(true).setName(branchName).setStartPoint("origin/" + branchName)
                .setForceRefUpdate(true).setUpstreamMode(CreateBranchCommand.SetupUpstreamMode.SET_UPSTREAM).call();
    }

    PullCommand pullCommand2 = git.pull().setTagOpt(TagOpt.FETCH_TAGS);
    pullCommand2.setCredentialsProvider(usernamePasswordCredentialsProvider);
    pullCommand2.call();


    System.out.println("success");
}
 
Example #3
Source File: JgitTests.java    From super-cloudops with Apache License 2.0 5 votes vote down vote up
@Test
public void checkoutTag() throws IOException, GitAPIException {
    String branchName = "tag2";
    Git git = Git.open(new File(gitPath));
    FetchCommand fetchCommand = git.fetch().setTagOpt(TagOpt.FETCH_TAGS);
    fetchCommand.setCredentialsProvider(usernamePasswordCredentialsProvider);
    fetchCommand.call();

    /*FetchCommand fetch = git.fetch();
    fetch.setCredentialsProvider(usernamePasswordCredentialsProvider);
    fetch.call();*/
    git.checkout().setName(branchName).call();
    System.out.println("success");
}
 
Example #4
Source File: GitOperations.java    From spring-data-dev-tools with Apache License 2.0 3 votes vote down vote up
/**
 * Updates the given {@link Project}. Will either pull the latest changes or clone the project's repository if not
 * already available.
 *
 * @param project must not be {@literal null}.
 */
public void update(Project project) {

	Assert.notNull(project, "Project must not be null!");

	logger.log(project, "Updating project…");

	GitProject gitProject = new GitProject(project, server);
	String repositoryName = gitProject.getRepositoryName();

	doWithGit(project, git -> {

		if (workspace.hasProjectDirectory(project)) {

			logger.log(project, "Found existing repository %s. Obtaining latest changes…", repositoryName);

			checkout(project, Branch.MASTER);

			logger.log(project, "git fetch --tags");
			git.fetch().setTagOpt(TagOpt.FETCH_TAGS).call();

		} else {
			clone(project);
		}
	});

	logger.log(project, "Project update done!");
}