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.gitflow.ui.internal.actions.InitHandler.java

License:Open Source License

private List<Ref> getBranches(Repository repository) throws ExecutionException {
    List<Ref> branchList;
    try {//w ww. ja v a 2 s.  c om
        branchList = Git.wrap(repository).branchList().call();
    } catch (GitAPIException e) {
        throw new ExecutionException(e.getMessage(), e);
    }
    return branchList;
}

From source file:org.eclipse.egit.ui.gitflow.AbstractGitflowHandlerTest.java

License:Open Source License

protected RevCommit setContentAddAndCommit(String newContent)
        throws Exception, GitAPIException, NoHeadException, NoMessageException, UnmergedPathsException,
        ConcurrentRefUpdateException, WrongRepositoryStateException, AbortedByHookException, IOException {
    setTestFileContent(newContent);/*from w  w w.  ja  va2s.  com*/

    Git git = Git.wrap(repository);
    git.add().addFilepattern(".").call();
    CommitCommand commit = git.commit().setMessage(newContent);
    commit.setAuthor(TestUtil.TESTCOMMITTER_NAME, TestUtil.TESTCOMMITTER_EMAIL);
    commit.setCommitter(TestUtil.TESTCOMMITTER_NAME, TestUtil.TESTCOMMITTER_EMAIL);
    return commit.call();
}

From source file:org.eclipse.egit.ui.gitflow.FeatureFinishSquashHandlerTest.java

License:Open Source License

private int countCommits() throws GitAPIException, NoHeadException, IOException {
    Iterable<RevCommit> commits = Git.wrap(repository).log().all().call();
    Iterator<RevCommit> iterator = commits.iterator();
    int count = 0;

    while (iterator.hasNext()) {
        iterator.next();// w w  w  .  ja v a  2  s .  c  o m
        count++;
    }
    return count;
}

From source file:org.eclipse.egit.ui.gitflow.FeatureRebaseHandlerTest.java

License:Open Source License

@Test
public void testRebaseFailOnConflict() throws Exception {
    disableAutomatedMode();//from ww w .  j a v a 2s  .c o m

    Git git = Git.wrap(repository);

    init();

    createFeature(FEATURE_NAME);
    setContentAddAndCommit("foo");

    checkoutBranch(DEVELOP);
    setContentAddAndCommit("bar");

    checkoutFeature(FEATURE_NAME);

    rebaseFeature();
    acceptError(RebaseResult.Status.STOPPED);

    Status status = git.status().call();
    Object[] conflicting = status.getConflicting().toArray();
    assertEquals(1, conflicting.length);
    assertEquals(FILE1_PATH, conflicting[0]);

    assertEquals("org.eclipse.egit.ui.InteractiveRebaseView", bot.activeView().getReference().getId());
}

From source file:org.eclipse.egit.ui.gitflow.FeatureRebaseHandlerTest.java

License:Open Source License

@Test
public void testRebaseFailOnDirtyWorkingDirectory() throws Exception {
    disableAutomatedMode();/*from  w  w w .  j ava  2s .  com*/

    Git git = Git.wrap(repository);

    init();
    setContentAddAndCommit("bar");

    createFeature(FEATURE_NAME);
    setContentAddAndCommit("foo");

    setTestFileContent("foobar");

    rebaseFeature();
    acceptError(RebaseResult.Status.UNCOMMITTED_CHANGES);

    Status status = git.status().call();
    Object[] uncommitted = status.getUncommittedChanges().toArray();
    assertEquals(1, uncommitted.length);
    assertEquals(FILE1_PATH, uncommitted[0]);
}

From source file:org.eclipse.egit.ui.internal.actions.StashesMenu.java

License:Open Source License

private static Collection<IContributionItem> createStashItems(Repository repository) {
    if (repository == null)
        return Collections.singleton(createNoStashedChangesItem());

    try {/*  w ww .  j a  v a2  s .c om*/
        Collection<RevCommit> stashCommits = Git.wrap(repository).stashList().call();

        if (stashCommits.isEmpty())
            return Collections.singleton(createNoStashedChangesItem());

        List<IContributionItem> items = new ArrayList<>(stashCommits.size());

        int index = 0;
        for (final RevCommit stashCommit : stashCommits)
            items.add(createStashItem(repository, stashCommit, index++));

        return items;
    } catch (GitAPIException e) {
        String repoName = repository.getWorkTree().getName();
        String message = MessageFormat.format(UIText.StashesMenu_StashListError, repoName);
        Activator.logError(message, e);
        return Collections.singleton(createNoStashedChangesItem());
    }
}

From source file:org.eclipse.egit.ui.internal.branch.BranchProjectTrackerTest.java

License:Open Source License

@Test
public void twoProjectsWithOnlyOneOnBranch() throws Exception {
    BranchProjectTracker tracker = new BranchProjectTracker(repository);
    String[] paths = tracker.getProjectPaths();
    assertNotNull(paths);//  w w w . jav a  2  s .com
    assertEquals(0, paths.length);
    assertNotNull(Git.wrap(repository).branchCreate().setName(BRANCH).call());
    BranchOperationUI.checkout(repository, BRANCH).start();
    TestUtil.joinJobs(JobFamilies.CHECKOUT);

    paths = tracker.getProjectPaths(Constants.MASTER);
    assertNotNull(paths);
    assertEquals(2, paths.length);

    IProject project1 = ResourcesPlugin.getWorkspace().getRoot().getProject(PROJ1);
    IProject project2 = ResourcesPlugin.getWorkspace().getRoot().getProject(PROJ2);
    assertTrue(project1.exists());
    assertTrue(project2.exists());
    project1.delete(true, true, new NullProgressMonitor());
    assertNotNull(Git.wrap(repository).commit().setAll(true).setMessage("deleting project").call());
    assertFalse(project1.exists());

    BranchOperationUI.checkout(repository, Constants.MASTER).start();
    TestUtil.joinJobs(JobFamilies.CHECKOUT);

    paths = tracker.getProjectPaths(BRANCH);
    assertNotNull(paths);
    assertEquals(1, paths.length);

    assertTrue(project1.exists());
    assertTrue(project2.exists());

    BranchOperationUI.checkout(repository, BRANCH).start();
    TestUtil.joinJobs(JobFamilies.CHECKOUT);

    assertTrue(project1.exists());
    assertFalse(project1.isOpen());
    assertTrue(project2.exists());
    assertTrue(project2.isOpen());

    BranchOperationUI.checkout(repository, Constants.MASTER).start();
    TestUtil.joinJobs(JobFamilies.CHECKOUT);

    assertTrue(project1.exists());
    assertTrue(project1.isOpen());
    assertTrue(project2.exists());
    assertTrue(project2.isOpen());
}

From source file:org.eclipse.egit.ui.internal.clean.CleanRepositoryPage.java

License:Open Source License

private void updateCleanItems() {
    try {/* w w  w . j a  v a  2  s .c o m*/
        getContainer().run(true, false, new IRunnableWithProgress() {
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                monitor.beginTask(UIText.CleanRepositoryPage_findingItems, IProgressMonitor.UNKNOWN);

                Git git = Git.wrap(repository);
                CleanCommand command = git.clean().setDryRun(true);
                command.setCleanDirectories(cleanDirectories);
                command.setIgnore(!includeIgnored);
                try {
                    final Set<String> paths = command.call();

                    getShell().getDisplay().syncExec(new Runnable() {
                        public void run() {
                            cleanTable.setInput(paths);
                        }
                    });
                } catch (GitAPIException ex) {
                    Activator.logError("cannot call clean command!", ex); //$NON-NLS-1$
                }

                monitor.done();
            }
        });
    } catch (InvocationTargetException e) {
        Activator.logError("Unexpected exception while finding items to clean", e); //$NON-NLS-1$
        clearPage();
    } catch (InterruptedException e) {
        clearPage();
    }
}

From source file:org.eclipse.egit.ui.internal.clean.CleanRepositoryPage.java

License:Open Source License

/**
 * Do the cleaning with the selected values.
 *///from ww w. j  a  v  a 2  s  .co m
public void finish() {
    try {
        final Set<String> itemsToClean = getItemsToClean();

        getContainer().run(true, false, new IRunnableWithProgress() {
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                monitor.beginTask(UIText.CleanRepositoryPage_cleaningItems, IProgressMonitor.UNKNOWN);

                Git git = Git.wrap(repository);
                CleanCommand command = git.clean().setDryRun(false);
                command.setCleanDirectories(cleanDirectories);
                command.setIgnore(!includeIgnored);
                command.setPaths(itemsToClean);
                try {
                    command.call();
                } catch (GitAPIException ex) {
                    Activator.logError("cannot call clean command!", ex); //$NON-NLS-1$
                }

                try {
                    IProject[] projects = ProjectUtil.getProjectsContaining(repository, itemsToClean);
                    ProjectUtil.refreshResources(projects, new SubProgressMonitor(monitor, 1));
                } catch (CoreException e) {
                    // could not refresh... not a "real" problem
                }

                monitor.done();
            }
        });
    } catch (Exception e) {
        Activator.logError("Unexpected exception while cleaning", e); //$NON-NLS-1$
    }
}

From source file:org.eclipse.egit.ui.internal.commit.command.StashDropHandler.java

License:Open Source License

private int getStashIndex(Repository repo, ObjectId id) throws ExecutionException {
    int index = 0;
    try {//from  w ww  . ja  v  a2 s  . c  o m
        for (RevCommit commit : Git.wrap(repo).stashList().call())
            if (commit.getId().equals(id))
                return index;
            else
                index++;
        throw new IllegalStateException(
                MessageFormat.format(UIText.StashDropCommand_stashCommitNotFound, id.name()));
    } catch (Exception e) {
        String message = MessageFormat.format(UIText.StashDropCommand_dropFailed, id.name());
        Activator.showError(message, e);
        throw new ExecutionException(message, e);
    }
}