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:fr.brouillard.oss.jgitver.strategy.configurable.others.Scenario8WithoutGPrefixCommitTest.java

License:Apache License

/**
 * Prepare common variables to access the git repository.
 *
 * @throws IOException if a disk error occurred
 *///from ww  w . j  av a2  s.co  m
@Before
public void init() throws IOException {
    repository = new FileRepositoryBuilder().setGitDir(scenario.getRepositoryLocation()).build();
    git = new Git(repository);
    versionCalculator = GitVersionCalculator.location(scenario.getRepositoryLocation());
    versionCalculator.setMavenLike(false);
    versionCalculator.setAutoIncrementPatch(true);
    versionCalculator.setUseGitCommitId(true);
    versionCalculator.setUseLongFormat(false); // without using the new format
    versionCalculator.setGitCommitIdLength(8);
    versionCalculator.setUseDistance(false);

    // reset the head to master
    unchecked(() -> git.checkout().setName("master").call());
}

From source file:fr.brouillard.oss.jgitver.strategy.maven.defaults.Scenario10WithDefaultsTest.java

License:Apache License

/**
 * Prepare common variables to access the git repository.
 * //from   w w  w .ja v  a  2 s.c o m
 * @throws IOException if a disk error occurred
 */
@Before
public void init() throws IOException {
    repository = new FileRepositoryBuilder().setGitDir(scenario.getRepositoryLocation()).build();
    git = new Git(repository);
    versionCalculator = GitVersionCalculator.location(scenario.getRepositoryLocation()).setMavenLike(true);

    // reset the head to master
    unchecked(() -> git.checkout().setName("master").call());
}

From source file:fr.brouillard.oss.jgitver.strategy.maven.others.Scenario13GitflowWithNonQualifierAndPartialNameTest.java

License:Apache License

/**
 * Prepare common variables to access the git repository.
 * //from www .j a  v  a2  s .  c o  m
 * @throws IOException if a disk error occurred
 */
@Before
public void init() throws IOException {
    repository = new FileRepositoryBuilder().setGitDir(scenario.getRepositoryLocation()).build();
    git = new Git(repository);
    versionCalculator = GitVersionCalculator.location(scenario.getRepositoryLocation()).setMavenLike(true)
            .setQualifierBranchingPolicies(BranchingPolicy.ignoreBranchName("master"),
                    BranchingPolicy.fixedBranchName("develop"),
                    new BranchingPolicy("release/(.*)",
                            Collections.singletonList(BranchNameTransformations.IGNORE.name())),
                    new BranchingPolicy("feature/(.*)",
                            Arrays.asList(BranchNameTransformations.REMOVE_UNEXPECTED_CHARS.name(),
                                    BranchNameTransformations.LOWERCASE_EN.name())))
            .setUseDefaultBranchingPolicy(false);

    // reset the head to master
    unchecked(() -> git.checkout().setName("master").call());
}

From source file:fr.brouillard.oss.jgitver.strategy.maven.others.Scenario5WithMasterAndIntBranchesNonQualifiedTest.java

License:Apache License

/**
 * Prepare common variables to access the git repository.
 * /* w w w  .  ja v a 2 s .com*/
 * @throws IOException if a disk error occurred
 */
@Before
public void init() throws IOException {
    repository = new FileRepositoryBuilder().setGitDir(scenario.getRepositoryLocation()).build();
    git = new Git(repository);
    versionCalculator = GitVersionCalculator.location(scenario.getRepositoryLocation()).setMavenLike(true)
            .setNonQualifierBranches("master,int");

    // reset the head to master
    unchecked(() -> git.checkout().setName("master").call());
}

From source file:fr.brouillard.oss.jgitver.strategy.maven.others.Scenario5WithNoDefaultQualiferNoNonQualiferTest.java

License:Apache License

/**
 * Prepare common variables to access the git repository.
 * /*from  w  ww .j a  va  2 s . c om*/
 * @throws IOException if a disk error occurred
 */
@Before
public void init() throws IOException {
    repository = new FileRepositoryBuilder().setGitDir(scenario.getRepositoryLocation()).build();
    git = new Git(repository);
    versionCalculator = GitVersionCalculator.location(scenario.getRepositoryLocation()).setMavenLike(true)
            .setUseDefaultBranchingPolicy(false).setNonQualifierBranches("");

    // reset the head to master
    unchecked(() -> git.checkout().setName("master").call());
}

From source file:fr.brouillard.oss.jgitver.strategy.maven.others.Scenario5WithNoDefaultQualiferTest.java

License:Apache License

/**
 * Prepare common variables to access the git repository.
 * /*  w ww.j a  va 2s. c o  m*/
 * @throws IOException if a disk error occurred
 */
@Before
public void init() throws IOException {
    repository = new FileRepositoryBuilder().setGitDir(scenario.getRepositoryLocation()).build();
    git = new Git(repository);
    versionCalculator = GitVersionCalculator.location(scenario.getRepositoryLocation()).setMavenLike(true)
            .setUseDefaultBranchingPolicy(false);

    // reset the head to master
    unchecked(() -> git.checkout().setName("master").call());
}

From source file:fr.brouillard.oss.jgitver.strategy.maven.others.Scenario6WithSpecificFindTagPatternTest.java

License:Apache License

/**
 * Prepare common variables to access the git repository.
 * //from  ww w  .  ja v  a2 s.c  o m
 * @throws IOException if a disk error occurred
 */
@Before
public void init() throws IOException {
    repository = new FileRepositoryBuilder().setGitDir(scenario.getRepositoryLocation()).build();
    git = new Git(repository);
    versionCalculator = GitVersionCalculator.location(scenario.getRepositoryLocation()).setMavenLike(true)
            .setFindTagVersionPattern("a([0-9]\\.[0-9])");

    // reset the head to master
    unchecked(() -> git.checkout().setName("master").call());
}

From source file:fr.brouillard.oss.jgitver.strategy.maven.others.Scenario9WithEmptyRepositoryTest.java

License:Apache License

/**
 * Prepare common variables to access the git repository.
 * /*  w w  w. j  av a 2 s. c  om*/
 * @throws IOException if a disk error occurred
 */
@Before
public void init() throws IOException {
    repository = new FileRepositoryBuilder().setGitDir(scenario.getRepositoryLocation()).build();
    git = new Git(repository);
    versionCalculator = GitVersionCalculator.location(scenario.getRepositoryLocation()).setMavenLike(true);
}

From source file:fr.obeo.ariadne.ide.connector.git.internal.explorer.GitExplorer.java

License:Open Source License

/**
 * Computes all the commits that exists in the given Git repository and map them as Ariadne concepts in
 * the given Ariadne repository.//from www  .  jav a  2s. c  o m
 * 
 * @param gitRepository
 *            The Git repository
 * @param ariadneRepository
 *            The Ariadne repository
 * @param monitor
 *            The progress monitor
 */
private void computeCommits(Repository gitRepository, fr.obeo.ariadne.model.scm.Repository ariadneRepository,
        IProgressMonitor monitor) {
    int maxThreads = Runtime.getRuntime().availableProcessors();
    ExecutorService executorService = Executors.newFixedThreadPool(maxThreads);

    long start = System.currentTimeMillis();

    List<Callable<AriadneCommitExplorerEntry>> callables = new ArrayList<>();

    Git git = new Git(gitRepository);
    LogCommand log = git.log();
    try {
        Iterable<RevCommit> logs = log.call();
        Iterator<RevCommit> logIterator = logs.iterator();
        monitor.subTask(AriadneGitConnectorMessage.getString("GitExplorer.ExploringCommit")); //$NON-NLS-1$
        while (logIterator.hasNext()) {
            monitor.worked(1);

            RevCommit revCommit = logIterator.next();
            // person's settings
            Person committer = this.getOrCreatePerson(ariadneRepository, revCommit.getCommitterIdent());
            Person author = this.getOrCreatePerson(ariadneRepository, revCommit.getAuthorIdent());

            Callable<AriadneCommitExplorerEntry> callable = new AriadneCommitExplorerRunnable(gitRepository,
                    revCommit, committer, author);
            callables.add(callable);
        }
    } catch (NoHeadException e) {
        e.printStackTrace();
    } catch (GitAPIException e) {
        e.printStackTrace();
    }

    try {
        List<Future<AriadneCommitExplorerEntry>> results = executorService.invokeAll(callables);
        executorService.shutdown();

        for (Future<AriadneCommitExplorerEntry> commit : results) {
            try {
                AriadneCommitExplorerEntry ariadneCommitExplorerEntry = commit.get();
                this.commit2ariadneCommit.put(ariadneCommitExplorerEntry.getGitCommit(),
                        ariadneCommitExplorerEntry.getAriadneCommit());
                ariadneRepository.getCommits().add(ariadneCommitExplorerEntry.getAriadneCommit());
            } catch (ExecutionException e) {
                e.printStackTrace();
            }
        }

        long end = System.currentTimeMillis();

        System.out.println(
                "Commits: " + ariadneRepository.getCommits().size() + " Time: " + (end - start) + "ms");
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}

From source file:getgitdata.TestJGit.java

public void init() throws IOException {
    // localPath = "/home/me/repos/mytest";
    localPath = "C:/Users/Masud/Documents/GitHub/tomcat/.git";
    remotePath = "git@github.com:me/mytestrepo.git";
    //localRepo = new FileRepository(localPath + "/.git");
    localRepo = new FileRepository(localPath);
    git = new Git(localRepo);
}