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

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

Introduction

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

Prototype

public RmCommand rm() 

Source Link

Document

Return a command object to execute a rm command

Usage

From source file:io.hawt.git.GitFacadeSupport.java

License:Apache License

protected RevCommit doRemove(Git git, File rootDir, String branch, String path, String commitMessage,
        PersonIdent personIdent) throws Exception {
    File file = getFile(rootDir, path);
    if (file.exists()) {
        Files.recursiveDelete(file);

        String filePattern = getFilePattern(path);
        git.rm().addFilepattern(filePattern).call();
        CommitCommand commit = git.commit().setAll(true).setAuthor(personIdent).setMessage(commitMessage);
        return commitThenPush(git, branch, commit);
    } else {//from w  w  w  .  j a  va 2 s. c  o m
        return null;
    }
}

From source file:org.craftercms.studio.impl.v1.deployment.EnvironmentStoreGitBranchDeployer.java

License:Open Source License

@Override
public void deleteFile(String site, String path) {
    try {//  www  . ja v  a  2 s .  c  om
        Repository repo = getEnvironmentStoreRepositoryInstance(site);
        Git git = new Git(repo);
        git.rm().addFilepattern(getGitPath(path)).setCached(false).call();

        RevCommit commit = git.commit().setOnly(getGitPath(path)).setMessage(StringUtils.EMPTY).call();
    } catch (GitAPIException | IOException | JGitInternalException e) {
        logger.error("Error while deleting content from environment store for site: " + site + " path: " + path
                + " environment: " + environment, e);
    }
}

From source file:org.eclipse.egit.core.op.RemoveFromIndexOperation.java

License:Open Source License

private static GitCommand<?> prepareCommand(Repository repository, Collection<String> paths) {
    Git git = new Git(repository);
    if (hasHead(repository)) {
        ResetCommand resetCommand = git.reset();
        resetCommand.setRef(HEAD);/*from   w w  w  .jav  a  2  s.  c o  m*/
        for (String path : paths)
            resetCommand.addPath(getCommandPath(path));
        return resetCommand;
    } else {
        RmCommand rmCommand = git.rm();
        rmCommand.setCached(true);
        for (String path : paths)
            rmCommand.addFilepattern(getCommandPath(path));
        return rmCommand;
    }
}

From source file:org.eclipse.egit.core.synchronize.StagedChangeCacheTest.java

License:Open Source License

@Test
public void shouldListSingleWorkspaceDeletion() throws Exception {
    // given//from w w  w.java  2 s  .  co  m
    Git git = new Git(db);
    writeTrashFile(db, "a.txt", "trash");
    git.add().addFilepattern("a.txt").call();
    git.commit().setMessage("initial add").call();
    git.rm().addFilepattern("a.txt").call();

    // when
    Map<String, Change> result = StagedChangeCache.build(db);

    // then
    assertThat(result.size(), is(1));
    assertFileDeletion(result, "a.txt", "a.txt");
}

From source file:org.eclipse.egit.core.synchronize.StagedChangeCacheTest.java

License:Open Source License

@Test
public void shouldListTwoWorkspaceDeletions() throws Exception {
    // given//from ww w.  ja  v a 2  s .  com
    Git git = new Git(db);
    writeTrashFile(db, "a.txt", "trash");
    writeTrashFile(db, "b.txt", "trash");
    git.add().addFilepattern("a.txt").addFilepattern("b.txt").call();
    git.commit().setMessage("new commit").call();
    git.rm().addFilepattern("a.txt").addFilepattern("b.txt").call();

    // when
    Map<String, Change> result = StagedChangeCache.build(db);

    // then
    assertThat(result.size(), is(2));
    assertFileDeletion(result, "a.txt", "a.txt");
    assertFileDeletion(result, "b.txt", "b.txt");
}

From source file:org.eclipse.egit.core.synchronize.StagedChangeCacheTest.java

License:Open Source License

@Test
public void shouldListSingleWorkspaceDeletionInFolder() throws Exception {
    // given//from  w w  w  .  jav a  2 s  . c o m
    Git git = new Git(db);
    writeTrashFile(db, "folder/a.txt", "trash");
    git.add().addFilepattern("folder/a.txt").call();
    git.commit().setMessage("new commit").call();
    git.rm().addFilepattern("folder/a.txt").call();

    // when
    Map<String, Change> result = StagedChangeCache.build(db);

    // then
    assertThat(result.size(), is(1));
    assertFileDeletion(result, "folder/a.txt", "a.txt");
}

From source file:org.eclipse.egit.core.synchronize.StagedChangeCacheTest.java

License:Open Source License

@Test
public void shouldListTwoWorkspaceDeletionsInFolder() throws Exception {
    // given/* w  ww.jav  a 2 s.c om*/
    Git git = new Git(db);
    writeTrashFile(db, "folder/a.txt", "trash");
    writeTrashFile(db, "folder/b.txt", "trash");
    git.add().addFilepattern("folder/a.txt").addFilepattern("folder/b.txt").call();
    git.commit().setMessage("new commit").call();
    git.rm().addFilepattern("folder/a.txt").call();
    git.rm().addFilepattern("folder/b.txt").call();

    // when
    Map<String, Change> result = StagedChangeCache.build(db);

    // then
    assertThat(result.size(), is(2));
    assertFileDeletion(result, "folder/a.txt", "a.txt");
    assertFileDeletion(result, "folder/b.txt", "b.txt");
}

From source file:org.eclipse.egit.ui.internal.staging.StagingView.java

License:Open Source License

private void stage(IStructuredSelection selection) {
    Git git = new Git(currentRepository);
    RmCommand rm = null;// w w w . j a  va 2s.  co m
    Iterator iterator = selection.iterator();
    List<String> addPaths = new ArrayList<String>();
    while (iterator.hasNext()) {
        Object element = iterator.next();
        if (element instanceof StagingEntry) {
            StagingEntry entry = (StagingEntry) element;
            switch (entry.getState()) {
            case ADDED:
            case CHANGED:
            case REMOVED:
                // already staged
                break;
            case CONFLICTING:
            case MODIFIED:
            case PARTIALLY_MODIFIED:
            case UNTRACKED:
                addPaths.add(entry.getPath());
                break;
            case MISSING:
                if (rm == null)
                    rm = git.rm().setCached(true);
                rm.addFilepattern(entry.getPath());
                break;
            }
        } else {
            IResource resource = AdapterUtils.adapt(element, IResource.class);
            if (resource != null) {
                RepositoryMapping mapping = RepositoryMapping.getMapping(resource);
                if (mapping != null && mapping.getRepository() == currentRepository) {
                    String path = mapping.getRepoRelativePath(resource);
                    // If resource corresponds to root of working directory
                    if ("".equals(path)) //$NON-NLS-1$
                        addPaths.add("."); //$NON-NLS-1$
                    else
                        addPaths.add(path);
                }
            }
        }
    }

    if (!addPaths.isEmpty())
        try {
            AddCommand add = git.add();
            for (String addPath : addPaths)
                add.addFilepattern(addPath);
            add.call();
        } catch (NoFilepatternException e1) {
            // cannot happen
        } catch (JGitInternalException e1) {
            Activator.handleError(e1.getCause().getMessage(), e1.getCause(), true);
        } catch (Exception e1) {
            Activator.handleError(e1.getMessage(), e1, true);
        }
    if (rm != null)
        try {
            rm.call();
        } catch (NoFilepatternException e) {
            // cannot happen
        } catch (JGitInternalException e) {
            Activator.handleError(e.getCause().getMessage(), e.getCause(), true);
        } catch (Exception e) {
            Activator.handleError(e.getMessage(), e, true);
        }
}

From source file:org.eclipse.emf.compare.diagram.papyrus.tests.egit.fixture.GitTestRepository.java

License:Open Source License

/**
 * Adds all missing or deleted files to the index.
 * /*from  www. ja va 2 s.co  m*/
 * @throws Exception
 *             if anything goes wrong.
 */
public void addDeletedFiles() throws Exception {
    Git git = new Git(repository);
    try {
        Status status = git.status().call();
        if (!status.getMissing().isEmpty() || !status.getRemoved().isEmpty()) {
            RmCommand rm = git.rm();
            for (String deletedFile : Iterables.concat(status.getMissing(), status.getRemoved())) {
                rm.addFilepattern(deletedFile);
            }
            rm.call();
        }
    } finally {
        git.close();
    }
}

From source file:org.eclipse.emf.compare.diagram.papyrus.tests.egit.fixture.GitTestRepository.java

License:Open Source License

/**
 * Adds the given resources to the index
 * /*w ww.  j a  v  a 2  s . com*/
 * @param resources
 *            Resources to add to the index.
 */
public void removeFromIndex(IResource... resources)
        throws CoreException, IOException, NoFilepatternException, GitAPIException {
    Git git = new Git(repository);
    try {
        for (IResource resource : resources) {
            String repoPath = getRepoRelativePath(resource.getLocation().toString());
            git.rm().addFilepattern(repoPath).call();
        }
    } finally {
        git.close();
    }
}