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.eclipse.egit.core.test.SubmoduleAndContainerTreeIteratorTest.java

License:Open Source License

@Test
public void testCleanStateAfterInit() throws NoWorkTreeException, GitAPIException {
    Git parentGit = Git.wrap(parentRepository.getRepository());

    Status status = parentGit.status().setWorkingTreeIt(treeIt).call();
    assertTrue(status.isClean());//from  w w  w .  ja  v a2  s  . c  o m
}

From source file:org.eclipse.egit.core.test.SubmoduleAndContainerTreeIteratorTest.java

License:Open Source License

@Test
public void testCleanStateFirstCommit()
        throws NoWorkTreeException, GitAPIException, IOException, CoreException, InterruptedException {
    testUtils.changeContentOfFile(parentProject, parentFile, "new content");
    RepositoryTestCase.fsTick(null);//from   ww w .  ja  va  2 s .  co m
    parentRepository.trackAllFiles(parentProject);
    parentRepository.commit("modified parent.txt");
    Git parentGit = Git.wrap(parentRepository.getRepository());

    Status status = parentGit.status().setWorkingTreeIt(treeIt).call();
    assertTrue(status.isClean());
}

From source file:org.eclipse.egit.gitflow.BranchNameValidator.java

License:Open Source License

private static boolean branchExists(GitFlowRepository repository, String fullBranchName) throws CoreException {
    List<Ref> branches;
    try {/*from  w w w  .ja v a 2 s  . co m*/
        branches = Git.wrap(repository.getRepository()).branchList().call();
    } catch (GitAPIException e) {
        throw new CoreException(error(e.getMessage(), e));
    }
    for (Ref ref : branches) {
        if (fullBranchName.equals(ref.getTarget().getName())) {
            return true;
        }
    }

    return false;
}

From source file:org.eclipse.egit.gitflow.GitFlowRepository.java

License:Open Source License

/**
 * @return Whether or not this repository has branches.
 *//* w  ww.j  av a2s  . c om*/
public boolean hasBranches() {
    List<Ref> branches;
    try {
        branches = Git.wrap(repository).branchList().call();
        return !branches.isEmpty();
    } catch (GitAPIException e) {
        throw new RuntimeException(e);
    }
}

From source file:org.eclipse.egit.gitflow.GitFlowRepository.java

License:Open Source License

/**
 * @param branch/* www .  j a  v a  2  s  .c o  m*/
 * @return Whether or not branch exists in this repository.
 * @throws GitAPIException
 */
public boolean hasBranch(String branch) throws GitAPIException {
    String fullBranchName = R_HEADS + branch;
    List<Ref> branchList = Git.wrap(repository).branchList().call();
    for (Ref ref : branchList) {
        if (fullBranchName.equals(ref.getTarget().getName())) {
            return true;
        }
    }

    return false;
}

From source file:org.eclipse.egit.gitflow.GitFlowRepository.java

License:Open Source License

private List<Ref> getPrefixBranches(String prefix) {
    try {/*from w w w  .j  av  a 2s . c o  m*/
        List<Ref> branches = Git.wrap(repository).branchList().call();
        List<Ref> prefixBranches = new ArrayList<Ref>();
        for (Ref ref : branches) {
            if (ref.getName().startsWith(prefix)) {
                prefixBranches.add(ref);
            }
        }

        return prefixBranches;
    } catch (GitAPIException e) {
        throw new RuntimeException(e);
    }
}

From source file:org.eclipse.egit.gitflow.GitFlowRepository.java

License:Open Source License

private boolean isOnBranch(RevCommit commit, String fullBranch) throws IOException {
    Ref branchRef = repository.exactRef(fullBranch);
    if (branchRef == null) {
        return false;
    }// w w w.j a va  2s .c om
    try {
        List<Ref> list = Git.wrap(repository).branchList().setContains(commit.name()).call();

        return list.contains(branchRef);
    } catch (GitAPIException e) {
        // ListBranchCommand can only throw a wrapped IOException
        throw new IOException(e);
    }
}

From source file:org.eclipse.egit.gitflow.op.AbstractFeatureOperationTest.java

License:Open Source License

protected int countCommits(Repository repository) throws GitAPIException, NoHeadException {
    int count = 0;
    Iterable<RevCommit> commits = Git.wrap(repository).log().call();
    Iterator<RevCommit> iterator = commits.iterator();
    while (iterator.hasNext()) {
        iterator.next();/* w  w w  . j  a  v  a 2  s . com*/
        count++;
    }
    return count;
}

From source file:org.eclipse.egit.gitflow.op.FeatureFinishOperationTest.java

License:Open Source License

@Test
public void testFeatureFinishSquash() throws Exception {
    String fileName = "theFirstFile.txt";
    String fileName2 = "theSecondFile.txt";

    Repository repository = testRepository.getRepository();
    GitFlowRepository gfRepo = init("testFeatureFinishSquash\n\nfirst commit\n");

    new FeatureStartOperation(gfRepo, MY_FEATURE).execute(null);

    String branchName = gfRepo.getConfig().getFeatureBranchName(MY_FEATURE);
    addFileAndCommit(fileName, "adding first file on feature branch");
    addFileAndCommit(fileName2, "adding second file on feature branch");
    FeatureFinishOperation featureFinishOperation = new FeatureFinishOperation(gfRepo);
    featureFinishOperation.setSquash(true);
    featureFinishOperation.execute(null);
    assertEquals(gfRepo.getConfig().getDevelopFull(), repository.getFullBranch());
    assertEquals(null, findBranch(repository, branchName));

    assertEquals(1, countCommits(repository));
    assertTrue(new File(repository.getDirectory() + "/../" + fileName).exists());
    assertTrue(new File(repository.getDirectory() + "/../" + fileName2).exists());

    Status status = Git.wrap(repository).status().call();
    assertTrue(status.hasUncommittedChanges());
}

From source file:org.eclipse.egit.gitflow.op.ReleaseFinishOperationTest.java

License:Open Source License

private RevCommit getPreviousCommit(Repository repository, int count) throws GitAPIException, NoHeadException {
    Iterable<RevCommit> logs = Git.wrap(repository).log().call();
    Iterator<RevCommit> i = logs.iterator();
    for (int j = 0; j < count; j++) {
        i.next();//ww w .  ja  va 2s .  c  o  m
    }
    RevCommit next = i.next();
    return next;
}