Example usage for org.eclipse.jgit.lib Repository resolve

List of usage examples for org.eclipse.jgit.lib Repository resolve

Introduction

In this page you can find the example usage for org.eclipse.jgit.lib Repository resolve.

Prototype

@Nullable
public ObjectId resolve(String revstr)
        throws AmbiguousObjectException, IncorrectObjectTypeException, RevisionSyntaxException, IOException 

Source Link

Document

Parse a git revision string and return an object id.

Usage

From source file:org.eclipse.orion.server.git.servlets.GitCommitHandlerV1.java

License:Open Source License

private boolean rebase(HttpServletRequest request, HttpServletResponse response, Repository db,
        String commitToRebase, String rebaseOperation)
        throws ServletException, JSONException, AmbiguousObjectException, IOException {
    JSONObject result = new JSONObject();
    try {// w  w w . java  2s. co  m
        Git git = new Git(db);
        RebaseCommand rebase = git.rebase();
        Operation operation;
        if (rebaseOperation != null) {
            operation = Operation.valueOf(rebaseOperation);
        } else {
            operation = Operation.BEGIN;
        }
        if (commitToRebase != null && !commitToRebase.isEmpty()) {
            ObjectId objectId = db.resolve(commitToRebase);
            rebase.setUpstream(objectId);
        } else if (operation.equals(Operation.BEGIN)) {
            return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR,
                    HttpServletResponse.SC_BAD_REQUEST, "Missing commit refId.", null));
        }
        rebase.setOperation(operation);
        RebaseResult rebaseResult = rebase.call();
        result.put(GitConstants.KEY_RESULT, rebaseResult.getStatus().name());
    } catch (UnmergedPathsException e) {
        // this error should be handled by client, so return a proper status
        result.put(GitConstants.KEY_RESULT, AdditionalRebaseStatus.FAILED_UNMERGED_PATHS.name());
    } catch (WrongRepositoryStateException e) {
        // this error should be handled by client, so return a proper status
        result.put(GitConstants.KEY_RESULT, AdditionalRebaseStatus.FAILED_WRONG_REPOSITORY_STATE.name());
    } catch (IllegalArgumentException e) {
        return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR,
                HttpServletResponse.SC_BAD_REQUEST, "Invalid rebase operation.", e));
    } catch (GitAPIException e) {
        return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR,
                HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "An error occured when rebasing.", e));
    } catch (JGitInternalException e) {
        // get cause and try to handle 
        if (e.getCause() instanceof org.eclipse.jgit.errors.CheckoutConflictException) {
            // this error should be handled by client, so return a proper status
            result.put(GitConstants.KEY_RESULT, AdditionalRebaseStatus.FAILED_PENDING_CHANGES.name());
        } else {
            return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR,
                    HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "An error occured when rebasing.", e));
        }
    }
    OrionServlet.writeJSONResponse(request, response, result);
    return true;
}

From source file:org.eclipse.orion.server.git.servlets.GitCommitHandlerV1.java

License:Open Source License

private boolean cherryPick(HttpServletRequest request, HttpServletResponse response, Repository db,
        String commitToCherryPick) throws ServletException, JSONException {
    try {/*  w  ww  . j a  va  2 s. c  om*/
        ObjectId objectId = db.resolve(commitToCherryPick);
        Git git = new Git(db);
        CherryPickResult cherryPickResult = git.cherryPick().include(objectId).call();
        JSONObject result = new JSONObject();
        result.put(GitConstants.KEY_RESULT, cherryPickResult.getStatus().name());
        OrionServlet.writeJSONResponse(request, response, result);
        return true;
    } catch (IOException e) {
        return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR,
                HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "An error occured when cherry-picking.", e));
    } catch (GitAPIException e) {
        return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR,
                HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "An error occured when cherry-picking.", e));
    } catch (JGitInternalException e) {
        return statusHandler.handleRequest(request, response,
                new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
                        "An error occured when cherry-picking.", e.getCause()));
    }
}

From source file:org.eclipse.orion.server.git.servlets.GitCommitHandlerV1.java

License:Open Source License

private boolean tag(HttpServletRequest request, HttpServletResponse response, Repository db, String commitId,
        String tagName, boolean isRoot) throws AmbiguousObjectException, IOException, JGitInternalException,
        GitAPIException, JSONException, URISyntaxException {
    Git git = new Git(db);
    ObjectId objectId = db.resolve(commitId);

    RevWalk walk = new RevWalk(db);
    RevCommit revCommit = walk.lookupCommit(objectId);
    walk.parseBody(revCommit);/*from   w  w w  . j  a va2s. c  o m*/

    GitTagHandlerV1.tag(git, revCommit, tagName);
    Map<ObjectId, JSONArray> commitToBranchMap = getCommitToBranchMap(db);

    JSONObject result = toJSON(db, revCommit, commitToBranchMap, OrionServlet.getURI(request), null, isRoot);
    OrionServlet.writeJSONResponse(request, response, result);
    walk.dispose();
    return true;
}

From source file:org.eclipse.orion.server.git.servlets.GitDiffHandlerV1.java

License:Open Source License

private URI getBaseLocation(URI location, Repository db, Path path) throws URISyntaxException, IOException {
    String scope = path.segment(0);
    if (scope.contains("..")) { //$NON-NLS-1$
        String[] commits = scope.split("\\.\\."); //$NON-NLS-1$
        if (commits.length != 2) {
            // TODO:
            throw new IllegalArgumentException();
        }/*www. j a va2s. c o  m*/
        // TODO: decode commits[]

        ThreeWayMerger merger = new ResolveMerger(db) {
            protected boolean mergeImpl() throws IOException {
                // do nothing
                return false;
            }
        };
        // use #merge to set sourceObjects
        merger.merge(new ObjectId[] { db.resolve(commits[0]), db.resolve(commits[1]) });
        RevCommit baseCommit = merger.getBaseCommit(0, 1);

        IPath p = new Path(GitServlet.GIT_URI + '/' + GitConstants.COMMIT_RESOURCE)
                .append(baseCommit.getId().getName()).append(path.removeFirstSegments(1));
        return new URI(location.getScheme(), location.getUserInfo(), location.getHost(), location.getPort(),
                p.toString(), "parts=body", null); //$NON-NLS-1$
    } else if (scope.equals(GitConstants.KEY_DIFF_CACHED)) {
        // HEAD is the base
        IPath p = new Path(GitServlet.GIT_URI + '/' + GitConstants.COMMIT_RESOURCE).append(Constants.HEAD)
                .append(path.removeFirstSegments(1));
        return new URI(location.getScheme(), location.getUserInfo(), location.getHost(), location.getPort(),
                p.toString(), "parts=body", null); //$NON-NLS-1$
    } else {
        // index is the base
        IPath p = new Path(GitServlet.GIT_URI + '/' + GitConstants.INDEX_RESOURCE)
                .append(path.removeFirstSegments(1));
        return new URI(location.getScheme(), location.getUserInfo(), location.getHost(), location.getPort(),
                p.toString(), null, null);
    }
}

From source file:org.eclipse.orion.server.git.servlets.GitTagHandlerV1.java

License:Open Source License

private boolean handlePost(HttpServletRequest request, HttpServletResponse response, String path)
        throws IOException, JSONException, CoreException, JGitInternalException, GitAPIException {
    IPath p = new Path(path);
    File gitDir = GitUtils.getGitDir(p);
    Repository db = new FileRepository(gitDir);
    Git git = new Git(db);
    JSONObject toPut = OrionServlet.readJSONRequest(request);
    String tagName = toPut.getString(ProtocolConstants.KEY_NAME);
    String commitId = toPut.getString(GitConstants.KEY_TAG_COMMIT);
    ObjectId objectId = db.resolve(commitId);

    RevWalk walk = new RevWalk(db);
    RevCommit revCommit = walk.lookupCommit(objectId);

    RevTag revTag = tag(git, revCommit, tagName);
    JSONObject result = new JSONObject();
    result.put(ProtocolConstants.KEY_NAME, revTag.getTagName());
    result.put(ProtocolConstants.KEY_CONTENT_LOCATION, OrionServlet.getURI(request));
    OrionServlet.writeJSONResponse(request, response, result);
    walk.dispose();// ww w  . j  av a 2  s  . c o  m
    return true;
}

From source file:org.eclipse.orion.server.git.servlets.GitTreeHandlerV1.java

License:Open Source License

@Override
protected boolean handleGet(RequestInfo requestInfo) throws ServletException {
    HttpServletRequest request = requestInfo.request;
    HttpServletResponse response = requestInfo.response;
    String gitSegment = requestInfo.gitSegment;
    Repository repo = requestInfo.db;
    String pattern = requestInfo.relativePath;
    IPath filePath = requestInfo.filePath;
    String meta = request.getParameter("parts"); //$NON-NLS-1$
    RevWalk walk = null;/*from www .  ja va 2s  . c  o m*/
    TreeWalk treeWalk = null;
    IPath filterPath = new Path(pattern);
    try {
        if (filterPath.segmentCount() == 0) {
            JSONArray children = new JSONArray();
            URI baseLocation = getURI(request);
            List<Ref> call = new Git(repo).branchList().setListMode(ListMode.ALL).call();
            for (Ref ref : call) {
                String branchName = Repository.shortenRefName(ref.getName());
                JSONObject branch = listEntry(branchName, 0, true, 0, baseLocation,
                        GitUtils.encode(branchName));
                children.put(branch);
            }
            JSONObject result = listEntry(filePath.segment(0), 0, true, 0, baseLocation, null);
            result.put(ProtocolConstants.KEY_CHILDREN, children);
            OrionServlet.writeJSONResponse(request, response, result,
                    JsonURIUnqualificationStrategy.ALL_NO_GIT);
            return true;
        }

        gitSegment = GitUtils.decode(filterPath.segment(0));
        filterPath = filterPath.removeFirstSegments(1);
        pattern = filterPath.toPortableString();
        ObjectId head = repo.resolve(gitSegment);
        if (head == null) {
            throw new Exception("Missing ref in git segment");
        }
        walk = new RevWalk(repo);
        // add try catch to catch failures

        RevCommit commit = walk.parseCommit(head);
        RevTree tree = commit.getTree();
        treeWalk = new TreeWalk(repo);
        treeWalk.addTree(tree);
        treeWalk.setRecursive(false);
        if (!pattern.equals("")) { //$NON-NLS-1$
            PathFilter pathFilter = PathFilter.create(pattern);
            treeWalk.setFilter(pathFilter);
        }
        JSONArray contents = new JSONArray();
        JSONObject result = null;
        ArrayList<JSONObject> parents = new ArrayList<JSONObject>();

        URI baseLocation = ServletResourceHandler.getURI(request);
        Path basePath = new Path(baseLocation.getPath());
        IPath tmp = new Path("/"); //$NON-NLS-1$
        for (int i = 0; i < 5; i++) {
            tmp = tmp.append(basePath.segment(i));
        }
        URI cloneLocation = new URI(baseLocation.getScheme(), baseLocation.getAuthority(),
                tmp.toPortableString(), null, baseLocation.getFragment());
        JSONObject ref = listEntry(gitSegment, 0, true, 0, cloneLocation, GitUtils.encode(gitSegment));

        parents.add(ref);
        parents.add(
                listEntry(new Path(cloneLocation.getPath()).lastSegment(), 0, true, 0, cloneLocation, null));
        URI locationWalk = URIUtil.append(cloneLocation, GitUtils.encode(gitSegment));
        while (treeWalk.next()) {
            if (treeWalk.isSubtree()) {
                if (treeWalk.getPathLength() > pattern.length()) {
                    String name = treeWalk.getNameString();
                    contents.put(listEntry(name, 0, true, 0, locationWalk, name));
                }
                if (treeWalk.getPathLength() <= pattern.length()) {
                    locationWalk = URIUtil.append(locationWalk, treeWalk.getNameString());
                    parents.add(0, listEntry(treeWalk.getNameString(), 0, true, 0, locationWalk, null));
                    treeWalk.enterSubtree();
                }
            } else {
                ObjectId objId = treeWalk.getObjectId(0);
                ObjectLoader loader = repo.open(objId);
                long size = loader.getSize();
                if (treeWalk.getPathLength() == pattern.length()) {
                    if ("meta".equals(meta)) { //$NON-NLS-1$
                        result = listEntry(treeWalk.getNameString(), 0, false, 0, locationWalk,
                                treeWalk.getNameString());
                    } else {
                        return getFileContents(request, response, repo, treeWalk, tree);
                    }
                } else {
                    String name = treeWalk.getNameString();
                    contents.put(listEntry(name, 0, false, size, locationWalk, name));
                }
            }
        }
        if (result == null) {
            result = parents.remove(0);
            result.put("Children", contents); //$NON-NLS-1$
        }
        result.put("Parents", new JSONArray(parents)); //$NON-NLS-1$
        response.setContentType("application/json"); //$NON-NLS-1$
        response.setHeader("Cache-Control", "no-cache"); //$NON-NLS-1$
        response.setHeader("ETag", "\"" + tree.getId().getName() + "\""); //$NON-NLS-1$
        OrionServlet.writeJSONResponse(request, response, result);
        return true;
    } catch (Exception e) {
        return statusHandler.handleRequest(request, response,
                new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
                        "An error occured when requesting commit info.", e));
    } finally {
        if (walk != null)
            walk.release();
        if (treeWalk != null)
            treeWalk.release();
    }
}

From source file:org.eclipse.orion.server.tests.servlets.git.GitFetchTest.java

License:Open Source License

@Test
public void testPushCommitAndFetch() throws Exception {
    URI workspaceLocation = createWorkspace(getMethodName());

    // clone1//from   w w w . ja  v  a 2 s  . com
    JSONObject project1 = createProjectOrLink(workspaceLocation, getMethodName() + "1", null);
    IPath clonePath1 = new Path("file").append(project1.getString(ProtocolConstants.KEY_ID)).makeAbsolute();
    String contentLocation1 = clone(clonePath1).getString(ProtocolConstants.KEY_CONTENT_LOCATION);

    // get project1 metadata
    WebRequest request = getGetFilesRequest(project1.getString(ProtocolConstants.KEY_CONTENT_LOCATION));
    WebResponse response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
    project1 = new JSONObject(response.getText());
    JSONObject gitSection1 = project1.optJSONObject(GitConstants.KEY_GIT);
    assertNotNull(gitSection1);
    String gitRemoteUri1 = gitSection1.getString(GitConstants.KEY_REMOTE);

    // clone2
    JSONObject project2 = createProjectOrLink(workspaceLocation, getMethodName() + "2", null);
    String projectId2 = project2.getString(ProtocolConstants.KEY_ID);
    IPath clonePath2 = new Path("file").append(project2.getString(ProtocolConstants.KEY_ID)).makeAbsolute();
    clone(clonePath2);

    // get project2 metadata
    request = getGetFilesRequest(project2.getString(ProtocolConstants.KEY_CONTENT_LOCATION));
    response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
    project2 = new JSONObject(response.getText());
    JSONObject gitSection2 = project2.optJSONObject(GitConstants.KEY_GIT);
    assertNotNull(gitSection2);
    String gitRemoteUri2 = gitSection2.getString(GitConstants.KEY_REMOTE);
    String gitIndexUri2 = gitSection2.getString(GitConstants.KEY_INDEX);
    String gitHeadUri2 = gitSection2.getString(GitConstants.KEY_HEAD);

    // clone2: change
    request = getPutFileRequest(projectId2 + "/test.txt", "incoming change");
    response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());

    // clone2: add
    request = GitAddTest.getPutGitIndexRequest(gitIndexUri2);
    response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());

    // clone2: commit
    request = GitCommitTest.getPostGitCommitRequest(gitHeadUri2, "incoming change commit", false);
    response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());

    // clone2: push
    ServerStatus pushStatus = push(gitRemoteUri2, 1, 0, Constants.MASTER, Constants.HEAD, false);
    assertEquals(true, pushStatus.isOK());

    JSONObject masterDetails = getRemoteBranch(gitRemoteUri1, 1, 0, Constants.MASTER);
    String refId1 = masterDetails.getString(ProtocolConstants.KEY_ID);
    String remoteBranchLocation = masterDetails.getString(ProtocolConstants.KEY_LOCATION);

    // clone1: fetch
    fetch(remoteBranchLocation);

    masterDetails = getRemoteBranch(gitRemoteUri1, 1, 0, Constants.MASTER);
    String newRefId1 = masterDetails.getString(ProtocolConstants.KEY_ID);
    assertFalse(newRefId1.equals(refId1));

    // clone1: log master..origin/master
    // TODO replace with tests methods from GitLogTest, bug 340051
    Repository db1 = getRepositoryForContentLocation(contentLocation1);
    ObjectId master = db1.resolve(Constants.MASTER);
    ObjectId originMaster = db1
            .resolve(Constants.R_REMOTES + Constants.DEFAULT_REMOTE_NAME + '/' + Constants.MASTER);
    Git git = new Git(db1);
    Iterable<RevCommit> commits = git.log().addRange(master, originMaster).call();
    int c = 0;
    for (RevCommit commit : commits) {
        assertEquals("incoming change commit", commit.getFullMessage());
        c++;
    }
    // a single incoming commit
    assertEquals(1, c);
}

From source file:org.eclipse.orion.server.tests.servlets.git.GitFetchTest.java

License:Open Source License

@Test
public void testPushAndFetchWithPrivateKeyAndPassphrase() throws Exception {

    Assume.assumeTrue(sshRepo2 != null);
    Assume.assumeTrue(knownHosts2 != null);
    Assume.assumeTrue(privateKey != null);
    Assume.assumeTrue(passphrase != null);

    URI workspaceLocation = createWorkspace(getMethodName());
    URIish uri = new URIish(sshRepo2);

    // clone1: create
    JSONObject project1 = createProjectOrLink(workspaceLocation, getMethodName() + "1", null);
    IPath clonePath = new Path("file").append(project1.getString(ProtocolConstants.KEY_ID)).makeAbsolute();
    WebRequest request = new PostGitCloneRequest().setURIish(uri).setFilePath(clonePath)
            .setKnownHosts(knownHosts2).setPrivateKey(privateKey).setPublicKey(publicKey)
            .setPassphrase(passphrase).getWebRequest();
    String cloneContentLocation1 = clone(request);

    // clone1: get project/folder metadata
    request = getGetFilesRequest(cloneContentLocation1);
    WebResponse response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
    project1 = new JSONObject(response.getText());

    // clone1: get git links
    JSONObject gitSection1 = project1.getJSONObject(GitConstants.KEY_GIT);
    String gitRemoteUri1 = gitSection1.getString(GitConstants.KEY_REMOTE);

    // clone2: create
    JSONObject project2 = createProjectOrLink(workspaceLocation, getMethodName() + "2", null);
    String projectId2 = project2.getString(ProtocolConstants.KEY_ID);
    clonePath = new Path("file").append(projectId2).makeAbsolute();
    request = new PostGitCloneRequest().setURIish(uri).setFilePath(clonePath).setKnownHosts(knownHosts2)
            .setPrivateKey(privateKey).setPublicKey(publicKey).setPassphrase(passphrase).getWebRequest();
    String cloneContentLocation2 = clone(request);

    // clone2: get project/folder metadata
    request = getGetFilesRequest(cloneContentLocation2);
    response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
    project2 = new JSONObject(response.getText());

    // clone2: get git links
    JSONObject gitSection2 = project2.getJSONObject(GitConstants.KEY_GIT);
    String gitRemoteUri2 = gitSection2.getString(GitConstants.KEY_REMOTE);
    String gitIndexUri2 = gitSection2.getString(GitConstants.KEY_INDEX);
    String gitHeadUri2 = gitSection2.getString(GitConstants.KEY_HEAD);

    // clone2: change
    request = getPutFileRequest(projectId2 + "/test.txt", "incoming change");
    response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());

    // clone2: add
    request = GitAddTest.getPutGitIndexRequest(gitIndexUri2);
    response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());

    // clone2: commit
    request = GitCommitTest.getPostGitCommitRequest(gitHeadUri2, "incoming change commit", false);
    response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());

    // clone2: push
    ServerStatus pushStatus = push(gitRemoteUri2, 1, 0, Constants.MASTER, Constants.HEAD, false, null,
            knownHosts2, privateKey, publicKey, passphrase, true);
    assertEquals(true, pushStatus.isOK());

    JSONObject details = getRemoteBranch(gitRemoteUri1, 1, 0, Constants.MASTER);
    String refId1 = details.getString(ProtocolConstants.KEY_ID);
    String remoteBranchLocation = details.getString(ProtocolConstants.KEY_LOCATION);

    // clone1: fetch
    fetch(remoteBranchLocation, null, knownHosts2, privateKey, publicKey, passphrase, true);

    details = getRemoteBranch(gitRemoteUri1, 1, 0, Constants.MASTER);
    String newRefId1 = details.getString(ProtocolConstants.KEY_ID);
    assertFalse(newRefId1.equals(refId1));

    // clone1: log master..origin/master
    // TODO replace with tests methods from GitLogTest, bug 340051
    Repository db1 = getRepositoryForContentLocation(cloneContentLocation1);
    ObjectId master = db1.resolve(Constants.MASTER);
    ObjectId originMaster = db1//from  w  ww .  j a  va  2 s . c  o m
            .resolve(Constants.R_REMOTES + Constants.DEFAULT_REMOTE_NAME + '/' + Constants.MASTER);
    Git git = new Git(db1);
    Iterable<RevCommit> commits = git.log().addRange(master, originMaster).call();
    int c = 0;
    for (RevCommit commit : commits) {
        assertEquals("incoming change commit", commit.getFullMessage());
        c++;
    }
    // a single incoming commit
    assertEquals(1, c);
}

From source file:org.eclipse.osee.ote.version.git.GitVersionBase.java

License:Open Source License

protected Repository buildRepository(File gitFolder) throws IOException {
    FileRepositoryBuilder builder = new FileRepositoryBuilder();
    Repository repository = builder.setGitDir(gitFolder).readEnvironment().findGitDir().build();
    repository.resolve("HEAD");
    return repository;
}

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/*  w  w  w .j a v a  2s.  c  o 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);
    }
}