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

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

Introduction

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

Prototype

public static Git wrap(Repository repo) 

Source Link

Document

Wrap repository

Usage

From source file:org.kercoin.magrit.core.dao.BuildDAOImpl.java

License:Open Source License

Git wrap(Repository repo) {
    return Git.wrap(repo);
}

From source file:org.kercoin.magrit.core.utils.GitUtils.java

License:Open Source License

public void fetch(Repository repository, String remote) throws JGitInternalException, InvalidRemoteException {
    Git.wrap(repository).fetch().setRemote(remote).call();
}

From source file:org.kercoin.magrit.core.utils.GitUtils.java

License:Open Source License

public void checkoutAsBranch(Repository repository, String commitSha1, String branchName)
        throws RefNotFoundException, InvalidRefNameException {
    try {/* w  w  w  .j a v a 2  s . c om*/
        Git.wrap(repository).checkout().setCreateBranch(true).setName(branchName).setStartPoint(commitSha1)
                .call();
    } catch (RefAlreadyExistsException e) {
        // It's ok!
    }
}

From source file:org.kercoin.magrit.core.utils.GitUtilsTest.java

License:Open Source License

@Test
public void testAddRemote() throws Exception {
    gitUtils.addRemote(clone, "copy", test);
    Git.wrap(clone).fetch().setRemote("copy").call();
    assertThat(FilesUtils.tail(new File(clone.getWorkTree(), ".git/config"), 3))
            .isEqualTo("[remote \"copy\"]\n" + "\tfetch = +refs/heads/*:refs/remotes/copy/*\n" + "\turl = "
                    + test.getDirectory().getParentFile().getAbsolutePath() + "\n");
}

From source file:org.sonar.plugins.scm.git.JGitBlameCommand.java

License:Open Source License

@Override
public void blame(BlameInput input, BlameOutput output) {
    File basedir = input.fileSystem().baseDir();
    Repository repo = buildRepository(basedir);
    try {/* w w w  .j a va  2  s  .com*/
        Git git = Git.wrap(repo);
        File gitBaseDir = repo.getWorkTree();
        ExecutorService executorService = Executors
                .newFixedThreadPool(Runtime.getRuntime().availableProcessors() + 1);
        List<Future<Void>> tasks = submitTasks(input, output, git, gitBaseDir, executorService);
        waitForTaskToComplete(tasks);
    } finally {
        repo.close();
    }
}

From source file:org.sonarsource.scm.git.JGitBlameCommand.java

License:Open Source License

@Override
public void blame(BlameInput input, BlameOutput output) {
    File basedir = input.fileSystem().baseDir();
    Repository repo = buildRepository(basedir);
    try {//w ww.j  a v a  2s  .  c  o m
        Git git = Git.wrap(repo);
        File gitBaseDir = repo.getWorkTree();
        ExecutorService executorService = Executors
                .newFixedThreadPool(Runtime.getRuntime().availableProcessors());
        List<Future<Void>> tasks = submitTasks(input, output, git, gitBaseDir, executorService);
        waitForTaskToComplete(executorService, tasks);
    } finally {
        repo.close();
    }
}

From source file:pl.project13.jgit.DescribeCommand.java

License:Open Source License

@VisibleForTesting
boolean findDirtyState(Repository repo) throws GitAPIException {
    Git git = Git.wrap(repo);
    Status status = git.status().call();

    // Git describe doesn't mind about untracked files when checking if
    // repo is dirty. JGit does this, so we cannot use the isClean method
    // to get the same behaviour. Instead check dirty state without
    // status.getUntracked().isEmpty()
    boolean isDirty = !(status.getAdded().isEmpty() && status.getChanged().isEmpty()
            && status.getRemoved().isEmpty() && status.getMissing().isEmpty() && status.getModified().isEmpty()
            && status.getConflicting().isEmpty());

    log("Repo is in dirty state [", isDirty, "]");
    return isDirty;
}

From source file:pl.project13.jgit.DescribeCommand.java

License:Open Source License

private Map<ObjectId, List<String>> findTagObjectIds(@NotNull Repository repo, boolean tagsFlag) {
    Map<ObjectId, List<DatedRevTag>> commitIdsToTags = newHashMap();

    RevWalk walk = new RevWalk(repo);
    try {/*  w  w w  .  java  2 s. c  o m*/
        walk.markStart(walk.parseCommit(repo.resolve("HEAD")));

        List<Ref> tagRefs = Git.wrap(repo).tagList().call();
        String matchPattern = createMatchPattern();
        Pattern regex = Pattern.compile(matchPattern);
        log("Tag refs [", tagRefs, "]");

        for (Ref tagRef : tagRefs) {
            walk.reset();
            String name = tagRef.getName();
            if (!regex.matcher(name).matches()) {
                log("Skipping tagRef with name [", name, "] as it doesn't match [", matchPattern, "]");
                continue;
            }
            ObjectId resolvedCommitId = repo.resolve(name);

            // todo that's a bit of a hack...
            try {
                final RevTag revTag = walk.parseTag(resolvedCommitId);
                ObjectId taggedCommitId = revTag.getObject().getId();
                log("Resolved tag [", revTag.getTagName(), "] [", revTag.getTaggerIdent(), "], points at [",
                        taggedCommitId, "] ");

                // sometimes a tag, may point to another tag, so we need to unpack it
                while (isTagId(taggedCommitId)) {
                    taggedCommitId = walk.parseTag(taggedCommitId).getObject().getId();
                }

                if (commitIdsToTags.containsKey(taggedCommitId)) {
                    commitIdsToTags.get(taggedCommitId).add(new DatedRevTag(revTag));
                } else {
                    commitIdsToTags.put(taggedCommitId, newArrayList(new DatedRevTag(revTag)));
                }

            } catch (IncorrectObjectTypeException ex) {
                // it's an lightweight tag! (yeah, really)
                if (tagsFlag) {
                    // --tags means "include lightweight tags"
                    log("Including lightweight tag [", name, "]");

                    DatedRevTag datedRevTag = new DatedRevTag(resolvedCommitId, name);

                    if (commitIdsToTags.containsKey(resolvedCommitId)) {
                        commitIdsToTags.get(resolvedCommitId).add(datedRevTag);
                    } else {
                        commitIdsToTags.put(resolvedCommitId, newArrayList(datedRevTag));
                    }
                }
            } catch (Exception ignored) {
                error("Failed while parsing [", tagRef, "] -- ", Throwables.getStackTraceAsString(ignored));
            }
        }

        for (Map.Entry<ObjectId, List<DatedRevTag>> entry : commitIdsToTags.entrySet()) {
            log("key [", entry.getKey(), "], tags => [", entry.getValue(), "] ");
        }

        Map<ObjectId, List<String>> commitIdsToTagNames = transformRevTagsMapToDateSortedTagNames(
                commitIdsToTags);

        log("Created map: [", commitIdsToTagNames, "] ");

        return commitIdsToTagNames;
    } catch (Exception e) {
        log("Unable to locate tags\n[", Throwables.getStackTraceAsString(e), "]");
    } finally {
        walk.release();
    }

    return Collections.emptyMap();
}

From source file:pl.project13.jgit.DescribeCommandIntegrationTest.java

License:Open Source License

@Test
public void shouldGiveTagWithDistanceToCurrentCommitAndItsId() throws Exception {
    // given//from   w ww  .  j ava  2 s. com
    mavenSandbox.withParentProject(PROJECT_NAME, "jar").withNoChildProject()
            .withGitRepoInParent(AvailableGitTestRepo.GIT_COMMIT_ID)
            .create(FileSystemMavenSandbox.CleanUp.CLEANUP_FIRST);

    Repository repo = git().getRepository();
    Git.wrap(repo).reset().setMode(ResetCommand.ResetType.HARD).call();

    // when
    DescribeCommand command = DescribeCommand.on(repo);
    command.setVerbose(true);
    DescribeResult res = command.call();

    // then
    assertThat(res).isNotNull();
    RevCommit HEAD = git().log().call().iterator().next();
    assertThat(res.toString()).isEqualTo("v2.0.4-25-g" + abbrev(HEAD.getName()));
}

From source file:pl.project13.jgit.DescribeCommandIntegrationTest.java

License:Open Source License

@Test
public void shouldGiveLightweightTagWithDirtyMarker() throws Exception {
    // given//w ww.  j  av a  2  s  . c o  m
    mavenSandbox.withParentProject(PROJECT_NAME, "jar").withNoChildProject()
            .withGitRepoInParent(AvailableGitTestRepo.ON_A_TAG_DIRTY)
            .create(FileSystemMavenSandbox.CleanUp.CLEANUP_FIRST);

    Repository repo = git().getRepository();

    Git.wrap(repo).reset().setMode(ResetCommand.ResetType.HARD).call();

    // when
    DescribeResult res = DescribeCommand.on(repo).tags().setVerbose(true).call();

    // then
    assertThat(res).isNotNull();

    assertThat(res.toString()).isEqualTo("v1.0.0");
}