Example usage for org.eclipse.jgit.lib Constants INFO_EXCLUDE

List of usage examples for org.eclipse.jgit.lib Constants INFO_EXCLUDE

Introduction

In this page you can find the example usage for org.eclipse.jgit.lib Constants INFO_EXCLUDE.

Prototype

String INFO_EXCLUDE

To view the source code for org.eclipse.jgit.lib Constants INFO_EXCLUDE.

Click Source Link

Document

Excludes-file

Usage

From source file:org.eclipse.ptp.internal.rdt.sync.git.core.GitRepo.java

License:Open Source License

/**
 * Upload the file filter from the given JGit repository
 *
 * @param localJGitRepo/*from w  w  w  .j  a  va 2s  .  co m*/
 * @param monitor
 *
 * @throws MissingConnectionException
 *          on missing connection
 * @throws RemoteSyncException
 *          on problems executing remote commands
 */
public void uploadFilter(JGitRepo localJGitRepo, IProgressMonitor monitor)
        throws MissingConnectionException, RemoteSyncException {
    final RecursiveSubMonitor subMon = RecursiveSubMonitor.convert(monitor, 10);
    IRemoteConnection conn = remoteLoc.getConnection();
    Repository repository = localJGitRepo.getRepository();

    try {
        //copy info/exclude to remote
        File exclude = repository.getFS().resolve(repository.getDirectory(), Constants.INFO_EXCLUDE);
        IFileStore local = EFS.getLocalFileSystem().getStore(new Path(exclude.getAbsolutePath()));
        String remoteExclude = remoteLoc.getDirectory() + "/" + GitSyncService.gitDir + "/" //$NON-NLS-1$//$NON-NLS-2$
                + Constants.INFO_EXCLUDE;
        IFileStore remote = conn.getFileManager().getResource(remoteExclude);
        subMon.subTask(Messages.GitRepo_6);
        local.copy(remote, EFS.OVERWRITE, subMon.newChild(3));

        //remove ignored files from index
        if (remoteGitVersion >= 1080102) {
            final String command = gitCommand() + " ls-files -X " + GitSyncService.gitDir + "/" //$NON-NLS-1$//$NON-NLS-2$
                    + Constants.INFO_EXCLUDE + " -i | " + //$NON-NLS-1$
                    gitCommand() + " update-index --force-remove --stdin ; " + //$NON-NLS-1$
                    gitCommand() + " commit --allow-empty -m \"" + GitSyncService.commitMessage + "\""; //$NON-NLS-1$ //$NON-NLS-2$
            subMon.subTask(Messages.GitRepo_7);
            CommandResults commandResults = this.executeRemoteCommand(command, subMon.newChild(7));
            if (commandResults.getExitCode() != 0) {
                throw new RemoteSyncException(Messages.GitRepo_8 + commandResults.getStderr());
            }
        } else {
            final String command = gitCommand() + " rev-parse HEAD"; //$NON-NLS-1$
            subMon.subTask(Messages.GitRepo_9);
            CommandResults commandResults = this.executeRemoteCommand(command, subMon.newChild(2));
            ObjectId objectId = null;
            if (commandResults.getExitCode() == 0)
                objectId = repository.resolve(commandResults.getStdout().trim());
            RevTree ref = null;
            try {
                if (objectId != null)
                    ref = new RevWalk(repository).parseTree(objectId);
            } catch (Exception e) {
                //ignore. Can happen if the local repo doesn't yet have the remote commit
            }
            if (ref != null) {
                Set<String> filesToRemove = localJGitRepo.getFilter().getIgnoredFiles(ref);
                subMon.subTask(Messages.GitRepo_7);
                deleteRemoteFiles(filesToRemove, subMon.newChild(8));
            }
        }
    } catch (RemoteConnectionException e) {
        throw new RemoteSyncException(e);
    } catch (CoreException e) {
        throw new RemoteSyncException(e);
    } catch (IOException e) {
        throw new RemoteSyncException(e);
    } catch (InterruptedException e) {
        throw new RemoteSyncException(e);
    } catch (RemoteExecutionException e) {
        throw new RemoteSyncException(e);
    }
}

From source file:org.eclipse.ptp.internal.rdt.sync.git.core.GitRepo.java

License:Open Source License

/**
 * Commit changed files on the remote to the remote Git repository
 *
 * @param monitor//from   w w w  .ja v  a2 s .  c om
 *
 * @throws MissingConnectionException
 *          if the connection is unresolved
 * @throws RemoteSyncException
 *          on problems executing the necessary remote commands.
 */
public void commitRemoteFiles(IProgressMonitor monitor) throws MissingConnectionException, RemoteSyncException {
    try {
        final String command = gitCommand() + " ls-files -X " + GitSyncService.gitDir + "/" //$NON-NLS-1$//$NON-NLS-2$
                + Constants.INFO_EXCLUDE + " -o -m | " + //$NON-NLS-1$
                gitCommand() + " update-index --add --remove --stdin ; " + //$NON-NLS-1$
                gitCommand() + " commit -m \"" + GitSyncService.commitMessage + "\""; //$NON-NLS-1$ //$NON-NLS-2$
        CommandResults commandResults = this.executeRemoteCommand(command, monitor);
        if (commandResults.getExitCode() != 0 && !commandResults.getStdout().contains("nothing to commit")) { //$NON-NLS-1$
            throw new RemoteSyncException(Messages.GitRepo_11 + commandResults.getStderr());
        }
    } catch (final InterruptedException e) {
        throw new RemoteSyncException(e);
    } catch (RemoteConnectionException e) {
        throw new RemoteSyncException(e);
    } catch (IOException e) {
        throw new RemoteSyncException(e);
    } catch (CoreException e) {
        throw new RemoteSyncException(e);
    } finally {
        if (monitor != null) {
            monitor.done();
        }
    }
}

From source file:org.eclipse.ptp.internal.rdt.sync.git.core.GitSyncFileFilter.java

License:Open Source License

@Override
public void saveFilter() throws IOException {
    Repository repo = jgitRepo.getRepository();
    File exclude = repo.getFS().resolve(repo.getDirectory(), Constants.INFO_EXCLUDE);
    exclude.getParentFile().mkdirs();// w  ww  . ja v  a  2s.c o  m
    FileOutputStream file = new FileOutputStream(exclude);
    BufferedWriter out = new BufferedWriter(new OutputStreamWriter(file, Constants.CHARSET));
    try {
        for (AbstractIgnoreRule rule : rules) {
            out.write(rule.toString());
            out.newLine();
        }
    } finally {
        out.close();
    }
    final RmCommand rmCommand = new RmCommand(repo);
    rmCommand.setCached(true);
    for (String fileName : getIgnoredFiles(null)) {
        rmCommand.addFilepattern(fileName);
    }
    try {
        rmCommand.call();
    } catch (NoFilepatternException e) {
        new IOException(e); // TODO: a bit ugly to wrap it into IOExcpetion
    } catch (GitAPIException e) {
        new IOException(e);
    }
}

From source file:org.eclipse.ptp.internal.rdt.sync.git.core.GitSyncFileFilter.java

License:Open Source License

/**
 * Load filtering rules from the file system
 * @throws IOException//  w  ww  .  j a v  a  2s.  c o m
 *          on problems reading from the file system
 */
public void loadFilter() throws IOException {
    Repository repo = jgitRepo.getRepository();
    File exclude = repo.getFS().resolve(repo.getDirectory(), Constants.INFO_EXCLUDE);
    if (exclude.exists()) {
        FileInputStream in = new FileInputStream(exclude);
        try {
            IgnoreNode node = new IgnoreNode();
            node.parse(in);
            for (org.eclipse.jgit.ignore.IgnoreRule rule : node.getRules()) {
                rules.add(new GitIgnoreRule(rule));
            }
        } finally {
            in.close();
        }
    } else {
        initialize(SyncManager.getDefaultFileFilter());
    }
}