Example usage for org.eclipse.jgit.api Git Git

List of usage examples for org.eclipse.jgit.api Git Git

Introduction

In this page you can find the example usage for org.eclipse.jgit.api Git Git.

Prototype

public Git(Repository repo) 

Source Link

Document

Construct a new org.eclipse.jgit.api.Git object which can interact with the specified git repository.

Usage

From source file:info.plichta.maven.plugins.changelog.CommitFilterTest.java

License:Apache License

@Before
public void setUp() throws Exception {
    super.setUp();
    try (Git git = new Git(db)) {
        commit = git.commit().setMessage("Commit").call();
        commit2 = git.commit().setMessage("Test").call();
    }//from w w w .j  ava2 s  .c  o m
}

From source file:info.plichta.maven.plugins.changelog.handlers.JiraHandlerTest.java

License:Apache License

@Test
public void test() throws GitAPIException {
    try (Git git = new Git(db)) {
        final RevCommit commit = git.commit().setMessage("This is commit with JIRA-1234 issue").call();
        final CommitWrapper wrapper = new CommitWrapper(commit, SERVER);
        handler.handle(wrapper);/*w  w  w . ja  v a2  s .  c  om*/
        final JiraIssue issue = new JiraIssue();
        issue.getTitle().add(new TitleToken("This is commit with ", null));
        issue.getTitle()
                .add(new TitleToken("JIRA-1234", new JiraLink("JIRA-1234", SERVER + "/browse/JIRA-1234")));
        issue.getTitle().add(new TitleToken(" issue", null));

        assertThat(wrapper.getTitle(), is("This is commit with JIRA-1234 issue"));
        assertThat(wrapper.getExtensions(), hasKey("jira"));
        assertThat(wrapper.getExtensions(), hasValue(sameBeanAs(issue)));
    }
}

From source file:info.plichta.maven.plugins.changelog.handlers.JiraHandlerTest.java

License:Apache License

@Test
public void testNoJira() throws GitAPIException {
    try (Git git = new Git(db)) {
        final RevCommit commit = git.commit().setMessage("Ordinary commit").call();
        final CommitWrapper wrapper = new CommitWrapper(commit, SERVER);
        handler.handle(wrapper);// ww  w.  j a  v  a  2  s.com
        assertThat(wrapper.getTitle(), is("Ordinary commit"));
        assertThat(wrapper.getExtensions(), not(hasKey("jira")));
    }
}

From source file:info.plichta.maven.plugins.changelog.handlers.PullRequestHandlerTest.java

License:Apache License

@Test
public void test() throws GitAPIException {
    try (Git git = new Git(db)) {
        final RevCommit commit = git.commit().setMessage("Merge pull request #1\n\nMy First PR").call();
        final CommitWrapper wrapper = new CommitWrapper(commit, SERVER);
        handler.handle(wrapper);//  ww w  . j a va 2  s  .c  o m
        assertThat(wrapper.getTitle(), is("My First PR"));
        assertThat(wrapper.getExtensions(), hasKey("pullRequest"));
        assertThat(wrapper.getExtensions(),
                hasValue(samePropertyValuesAs(new PullRequest("1", "My First PR", SERVER + "/pull/1"))));
    }
}

From source file:info.plichta.maven.plugins.changelog.handlers.PullRequestHandlerTest.java

License:Apache License

@Test
public void testNoPR() throws GitAPIException {
    try (Git git = new Git(db)) {
        final RevCommit commit = git.commit().setMessage("Ordinary commit").call();
        final CommitWrapper wrapper = new CommitWrapper(commit, SERVER);
        handler.handle(wrapper);/*from   w w w . j  av  a2 s.  c o  m*/
        assertThat(wrapper.getTitle(), is("Ordinary commit"));
        assertThat(wrapper.getExtensions(), not(hasKey("pullRequest")));
    }
}

From source file:info.plichta.maven.plugins.changelog.RepositoryProcessorTest.java

License:Apache License

@Test
public void processSimpleMainline() throws Exception {
    try (Git git = new Git(db)) {
        commitWithFile(git, "first");
        git.tag().setName(TAG_PREFIX + "-" + V_1).call();
        git.branchCreate().setName("branch").setStartPoint("HEAD").call();
        git.checkout().setName("branch").call();
        commitWithFile(git, "branch_1");
        final RevCommit branch = commitWithFile(git, "branch_2");
        git.checkout().setName(MASTER).call();
        git.merge().include(branch).setFastForward(FastForwardMode.NO_FF).setMessage("merge1").call();
        git.tag().setName(TAG_PREFIX + "-" + V_2).call();
    }//w  w w. ja va  2s  .c om

    final List<TagWrapper> tags = processor.process(db);
    assertThat(tags, hasSize(3));
    assertTag(tags.get(0), NEXT_VERSION, emptyMap());
    assertTag(tags.get(1), V_2, of("merge1", asList("branch_2", "branch_1")));
    assertTag(tags.get(2), V_1, of("first", emptyList()));
}

From source file:info.plichta.maven.plugins.changelog.RepositoryProcessorTest.java

License:Apache License

@Test
public void processMainlineWithLongLivingBranches() throws Exception {
    try (Git git = new Git(db)) {
        commitWithFile(git, "first");
        git.tag().setName(TAG_PREFIX + "-" + V_1).call();
        git.branchCreate().setName("branch").setStartPoint("HEAD").call();
        git.checkout().setName("branch").call();
        commitWithFile(git, "branch_1");
        RevCommit branch = commitWithFile(git, "branch_2");
        git.checkout().setName(MASTER).call();
        git.merge().include(branch).setFastForward(FastForwardMode.NO_FF).setMessage("merge1").call();
        git.tag().setName(TAG_PREFIX + "-" + V_2).call();
        git.checkout().setName("branch").call();
        branch = commitWithFile(git, "branch_3");
        git.checkout().setName(MASTER).call();
        git.merge().include(branch).setFastForward(FastForwardMode.NO_FF).setMessage("merge2").call();
        git.tag().setName(TAG_PREFIX + "-" + V_3).call();
    }//from  w ww.  ja  va 2s .c  o m

    final List<TagWrapper> tags = processor.process(db);
    assertThat(tags, hasSize(4));
    assertTag(tags.get(0), NEXT_VERSION, emptyMap());
    assertTag(tags.get(1), V_3, of("merge2", singletonList("branch_3")));
    assertTag(tags.get(2), V_2, of("merge1", asList("branch_2", "branch_1")));
    assertTag(tags.get(3), V_1, of("first", emptyList()));
}

From source file:io.apigee.buildTools.enterprise4g.utils.GitUtil.java

License:Apache License

public GitUtil(File f) {
    try {//from   ww w  .  j ava  2  s . c o m
        File workspace = findWorkspaceRoot(f);
        if (workspace == null) {
            throw new IllegalStateException("Does not appear to be a Git workspace: " + f.getCanonicalPath());
        }
        Repository r = new RepositoryBuilder().setWorkTree(findWorkspaceRoot(f)).build();
        git = new Git(r);
    } catch (IOException e) {
        throw new AstException(e);
    }
}

From source file:io.fabric8.collector.git.GitBuildConfigProcessor.java

License:Apache License

protected void doPull(File gitFolder, CredentialsProvider cp, String branch, PersonIdent personIdent,
        UserDetails userDetails) {/*from  w w  w .  ja  va  2  s .c o  m*/
    try {
        FileRepositoryBuilder builder = new FileRepositoryBuilder();
        Repository repository = builder.setGitDir(gitFolder).readEnvironment() // scan environment GIT_* variables
                .findGitDir() // scan up the file system tree
                .build();

        Git git = new Git(repository);

        File projectFolder = repository.getDirectory();

        StoredConfig config = repository.getConfig();
        String url = config.getString("remote", userDetails.getRemote(), "url");
        if (Strings.isNullOrBlank(url)) {
            LOG.warn("No remote repository url for " + branch + " defined for the git repository at "
                    + projectFolder.getCanonicalPath() + " so cannot pull");
            //return;
        }
        String mergeUrl = config.getString("branch", branch, "merge");
        if (Strings.isNullOrBlank(mergeUrl)) {
            LOG.warn("No merge spec for branch." + branch + ".merge in the git repository at "
                    + projectFolder.getCanonicalPath() + " so not doing a pull");
            //return;
        }

        LOG.debug("Performing a pull in git repository " + projectFolder.getCanonicalPath() + " on remote URL: "
                + url);
        PullCommand pull = git.pull();
        GitHelpers.configureCommand(pull, userDetails);
        pull.setRebase(true).call();
    } catch (Throwable e) {
        LOG.error("Failed to pull from the remote git repo with credentials " + cp + " due: " + e.getMessage()
                + ". This exception is ignored.", e);
    }
}

From source file:io.fabric8.collector.git.GitHelpers.java

License:Apache License

public static Git gitFromGitFolder(File gitFolder) throws IOException {
    FileRepositoryBuilder builder = new FileRepositoryBuilder();
    Repository repository = builder.setGitDir(gitFolder).readEnvironment() // scan environment GIT_* variables
            .findGitDir() // scan up the file system tree
            .build();//from  ww w . j  a  v  a2 s.c  o m

    return new Git(repository);
}