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

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

Introduction

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

Prototype

String R_HEADS

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

Click Source Link

Document

Prefix for branch refs

Usage

From source file:org.eclipse.orion.server.git.jobs.PushJob.java

License:Open Source License

private IStatus doPush() throws IOException, CoreException, URISyntaxException, GitAPIException {
    // /git/remote/{remote}/{branch}/file/{path}
    File gitDir = GitUtils.getGitDir(path.removeFirstSegments(2));
    Repository db = new FileRepository(gitDir);
    Git git = new Git(db);

    PushCommand pushCommand = git.push();

    RemoteConfig remoteConfig = new RemoteConfig(git.getRepository().getConfig(), remote);
    credentials.setUri(remoteConfig.getURIs().get(0));
    pushCommand.setCredentialsProvider(credentials);

    RefSpec spec = new RefSpec(srcRef + ':' + Constants.R_HEADS + branch);
    pushCommand.setRemote(remote).setRefSpecs(spec);
    if (tags)/*from   w  ww  .  j  a  v a  2s. com*/
        pushCommand.setPushTags();
    pushCommand.setForce(force);
    Iterable<PushResult> resultIterable = pushCommand.call();
    PushResult pushResult = resultIterable.iterator().next();
    // this set will contain only OK status or UP_TO_DATE status
    Set<RemoteRefUpdate.Status> statusSet = new HashSet<RemoteRefUpdate.Status>();
    for (final RemoteRefUpdate rru : pushResult.getRemoteUpdates()) {
        final String rm = rru.getRemoteName();
        // check status only for branch given in the URL or tags
        if (branch.equals(Repository.shortenRefName(rm)) || rm.startsWith(Constants.R_TAGS)) {
            RemoteRefUpdate.Status status = rru.getStatus();
            // any status different from UP_TO_DATE and OK should generate warning
            if (status != RemoteRefUpdate.Status.OK && status != RemoteRefUpdate.Status.UP_TO_DATE)
                return new Status(IStatus.WARNING, GitActivator.PI_GIT, status.name(),
                        new Throwable(rru.getMessage()));
            // add OK or UP_TO_DATE status to the set
            statusSet.add(status);
        }
        // TODO: return results for all updated branches once push is available for remote, see bug 352202
    }
    if (statusSet.contains(RemoteRefUpdate.Status.OK))
        // if there is OK status in the set -> something was updated
        return Status.OK_STATUS;
    else
        // if there is no OK status in the set -> only UP_TO_DATE status is possible
        return new Status(IStatus.WARNING, GitActivator.PI_GIT, RemoteRefUpdate.Status.UP_TO_DATE.name());
}

From source file:org.eclipse.orion.server.git.objects.Log.java

License:Open Source License

private JSONObject createJSONObjectForRef(Ref targetRef)
        throws JSONException, URISyntaxException, IOException, CoreException {
    JSONObject result = null;// w  w  w .j a  v a  2s  . co m
    String name = targetRef.getName();
    if (name.startsWith(Constants.R_HEADS)) {
        result = new Branch(cloneLocation, db, targetRef).toJSON();
    } else if (name.startsWith(Constants.R_REMOTES)) {
        Remote remote = findRemote(name);
        String remoteBranchName = computeRemoteBranchName(name, remote);
        result = new RemoteBranch(cloneLocation, db, remote, remoteBranchName).toJSON();
    }
    Assert.isNotNull(result, NLS.bind("Unexpected target Ref: {0}", name));
    return result;
}

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

License:Open Source License

private IStatus doFetch()
        throws IOException, CoreException, JGitInternalException, InvalidRemoteException, URISyntaxException {
    Repository db = getRepository();/*from  w w  w. j  a v a2 s . c o m*/
    String branch = getRemoteBranch();

    Git git = new Git(db);
    FetchCommand fc = git.fetch();

    RemoteConfig remoteConfig = new RemoteConfig(git.getRepository().getConfig(), remote);
    credentials.setUri(remoteConfig.getURIs().get(0));

    fc.setCredentialsProvider(credentials);
    fc.setRemote(remote);
    if (branch != null) {
        // refs/heads/{branch}:refs/remotes/{remote}/{branch}
        RefSpec spec = new RefSpec(
                Constants.R_HEADS + branch + ":" + Constants.R_REMOTES + remote + "/" + branch); //$NON-NLS-1$ //$NON-NLS-2$
        spec = spec.setForceUpdate(force);
        fc.setRefSpecs(spec);
    }
    FetchResult fetchResult = fc.call();

    // handle result
    for (TrackingRefUpdate updateRes : fetchResult.getTrackingRefUpdates()) {
        Result res = updateRes.getResult();
        // handle status for given ref
        switch (res) {
        case NOT_ATTEMPTED:
        case NO_CHANGE:
        case NEW:
        case FORCED:
        case FAST_FORWARD:
        case RENAMED:
            // do nothing, as these statuses are OK
            break;
        case REJECTED:
        case REJECTED_CURRENT_BRANCH:
            // show warning, as only force fetch can finish successfully 
            return new Status(IStatus.WARNING, GitActivator.PI_GIT, res.name());
        default:
            return new Status(IStatus.ERROR, GitActivator.PI_GIT, res.name());
        }
    }
    return Status.OK_STATUS;
}

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

License:Open Source License

private boolean handleGetCommitLog(HttpServletRequest request, HttpServletResponse response, Repository db,
        String refIdsRange, String path) throws AmbiguousObjectException, IOException, ServletException,
        JSONException, URISyntaxException, CoreException {
    int page = request.getParameter("page") != null ? new Integer(request.getParameter("page")).intValue() : 0; //$NON-NLS-1$ //$NON-NLS-2$
    int pageSize = request.getParameter("pageSize") != null //$NON-NLS-1$
            ? new Integer(request.getParameter("pageSize")).intValue() //$NON-NLS-1$
            : PAGE_SIZE;/*from  w ww. ja  v  a 2  s.com*/

    ObjectId toObjectId = null;
    ObjectId fromObjectId = null;

    Ref toRefId = null;
    Ref fromRefId = null;

    Git git = new Git(db);
    LogCommand log = git.log();

    if (refIdsRange != null) {
        // git log <since>..<until>
        if (refIdsRange.contains("..")) { //$NON-NLS-1$
            String[] commits = refIdsRange.split("\\.\\."); //$NON-NLS-1$
            if (commits.length != 2) {
                String msg = NLS.bind("Failed to generate commit log for ref {0}", refIdsRange);
                return statusHandler.handleRequest(request, response,
                        new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, msg, null));
            }

            fromObjectId = db.resolve(commits[0]);
            fromRefId = db.getRef(commits[0]);
            if (fromObjectId == null) {
                String msg = NLS.bind("Failed to generate commit log for ref {0}", commits[0]);
                return statusHandler.handleRequest(request, response,
                        new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, msg, null));
            }

            toObjectId = db.resolve(commits[1]);
            toRefId = db.getRef(commits[1]);
            if (toObjectId == null) {
                String msg = NLS.bind("No ref or commit found: {0}", commits[1]);
                return statusHandler.handleRequest(request, response,
                        new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_NOT_FOUND, msg, null));
            }
        } else {
            toObjectId = db.resolve(refIdsRange);
            toRefId = db.getRef(refIdsRange);
            if (toObjectId == null) {
                String msg = NLS.bind("No ref or commit found: {0}", refIdsRange);
                return statusHandler.handleRequest(request, response,
                        new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_NOT_FOUND, msg, null));
            }
        }

        // set the commit range
        log.add(toObjectId);

        if (fromObjectId != null)
            log.not(fromObjectId);
    } else {
        // git log --all
        // workaround for git log --all - see bug 353310
        List<Ref> branches = git.branchList().setListMode(ListMode.ALL).call();
        for (Ref branch : branches) {
            log.add(branch.getObjectId());
        }
    }

    // set the path filter
    TreeFilter filter = null;

    boolean isRoot = true;
    if (path != null && !"".equals(path)) { //$NON-NLS-1$
        filter = AndTreeFilter.create(PathFilterGroup.createFromStrings(Collections.singleton(path)),
                TreeFilter.ANY_DIFF);
        log.addPath(path);
        isRoot = false;
    }

    try {
        Iterable<RevCommit> commits = log.call();
        Map<ObjectId, JSONArray> commitToBranchMap = getCommitToBranchMap(db);
        JSONObject result = toJSON(db, OrionServlet.getURI(request), commits, commitToBranchMap, page, pageSize,
                filter, isRoot);

        result.put(GitConstants.KEY_REPOSITORY_PATH, isRoot ? "" : path); //$NON-NLS-1$
        if (refIdsRange == null)
            result.put(GitConstants.KEY_CLONE,
                    BaseToCloneConverter.getCloneLocation(getURI(request), BaseToCloneConverter.COMMIT));
        else
            result.put(GitConstants.KEY_CLONE, BaseToCloneConverter.getCloneLocation(getURI(request),
                    BaseToCloneConverter.COMMIT_REFRANGE));

        if (toRefId != null) {
            result.put(GitConstants.KEY_REMOTE, BaseToRemoteConverter.getRemoteBranchLocation(getURI(request),
                    Repository.shortenRefName(toRefId.getName()), db, BaseToRemoteConverter.REMOVE_FIRST_3));

            String refTargetName = toRefId.getTarget().getName();
            if (refTargetName.startsWith(Constants.R_HEADS)) {
                // this is a branch
                result.put(GitConstants.KEY_LOG_TO_REF,
                        BranchToJSONConverter.toJSON(toRefId.getTarget(), db, getURI(request), 3));
            }
        }
        if (fromRefId != null) {
            String refTargetName = fromRefId.getTarget().getName();
            if (refTargetName.startsWith(Constants.R_HEADS)) {
                // this is a branch
                result.put(GitConstants.KEY_LOG_FROM_REF,
                        BranchToJSONConverter.toJSON(fromRefId.getTarget(), db, getURI(request), 3));
            }
        }

        OrionServlet.writeJSONResponse(request, response, result);
        return true;
    } catch (NoHeadException e) {
        String msg = NLS.bind("No HEAD reference found when generating log for ref {0}", refIdsRange);
        return statusHandler.handleRequest(request, response,
                new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg, e));
    } catch (JGitInternalException e) {
        String msg = NLS.bind("An internal error occured when generating log for ref {0}", refIdsRange);
        return statusHandler.handleRequest(request, response,
                new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg, e));
    }
}

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

License:Open Source License

private IStatus doPush() throws IOException, CoreException, JGitInternalException, InvalidRemoteException,
        URISyntaxException, JSONException {
    // /git/remote/{remote}/{branch}/file/{path}
    File gitDir = GitUtils.getGitDir(path.removeFirstSegments(2));
    Repository db = new FileRepository(gitDir);
    Git git = new Git(db);

    PushCommand pushCommand = git.push();

    RemoteConfig remoteConfig = new RemoteConfig(git.getRepository().getConfig(), path.segment(0));
    credentials.setUri(remoteConfig.getURIs().get(0));
    pushCommand.setCredentialsProvider(credentials);

    // ObjectId ref = db.resolve(srcRef);
    RefSpec spec = new RefSpec(srcRef + ":" + Constants.R_HEADS + path.segment(1)); //$NON-NLS-1$
    pushCommand.setRemote(path.segment(0)).setRefSpecs(spec);
    if (tags)//from w  ww  .  ja  v  a2 s .  co m
        pushCommand.setPushTags();
    pushCommand.setForce(force);
    Iterable<PushResult> resultIterable = pushCommand.call();
    PushResult pushResult = resultIterable.iterator().next();
    // this set will contain only OK status or UP_TO_DATE status
    Set<RemoteRefUpdate.Status> statusSet = new HashSet<RemoteRefUpdate.Status>();
    for (final RemoteRefUpdate rru : pushResult.getRemoteUpdates()) {
        final String rm = rru.getRemoteName();
        // final String sr = rru.isDelete() ? null : rru.getSrcRef();
        // check status only for branch given in the URL or tags
        if (path.segment(1).equals(Repository.shortenRefName(rm)) || rm.startsWith(Constants.R_TAGS)) {
            RemoteRefUpdate.Status status = rru.getStatus();
            // any status different from UP_TO_DATE and OK should generate warning
            if (status != RemoteRefUpdate.Status.OK && status != RemoteRefUpdate.Status.UP_TO_DATE)
                return new Status(IStatus.WARNING, GitActivator.PI_GIT, status.name());
            // add OK or UP_TO_DATE status to the set
            statusSet.add(status);
        }
        // TODO: return results for all updated branches once push is available for remote, see bug 342727, comment 1
    }
    if (statusSet.contains(RemoteRefUpdate.Status.OK))
        // if there is OK status in the set -> something was updated
        return Status.OK_STATUS;
    else
        // if there is no OK status in the set -> only UP_TO_DATE status is possible
        return new Status(IStatus.WARNING, GitActivator.PI_GIT, RemoteRefUpdate.Status.UP_TO_DATE.name());
}

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

License:Open Source License

@Test
public void testLogWithBranch() throws Exception {
    URI workspaceLocation = createWorkspace(getMethodName());
    JSONObject projectTop = createProjectOrLink(workspaceLocation, getMethodName() + "-top", null);
    IPath clonePathTop = new Path("file").append(projectTop.getString(ProtocolConstants.KEY_ID)).makeAbsolute();

    JSONObject projectFolder = createProjectOrLink(workspaceLocation, getMethodName() + "-folder", null);
    IPath clonePathFolder = new Path("file").append(projectFolder.getString(ProtocolConstants.KEY_ID))
            .append("folder").makeAbsolute();

    IPath[] clonePaths = new IPath[] { clonePathTop, clonePathFolder };

    for (IPath clonePath : clonePaths) {
        // clone a  repo
        JSONObject clone = clone(clonePath);
        String cloneContentLocation = clone.getString(ProtocolConstants.KEY_CONTENT_LOCATION);
        String branchesLocation = clone.getString(GitConstants.KEY_BRANCH);

        // get project metadata
        WebRequest request = getGetFilesRequest(cloneContentLocation);
        WebResponse response = webConversation.getResponse(request);
        assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
        JSONObject project = new JSONObject(response.getText());

        JSONObject gitSection = project.getJSONObject(GitConstants.KEY_GIT);
        String gitCommitUri = gitSection.getString(GitConstants.KEY_COMMIT);

        JSONArray commitsArray = log(gitCommitUri, true);
        assertEquals(1, commitsArray.length());

        branch(branchesLocation, "branch");

        commitsArray = log(gitCommitUri, true);
        assertEquals(1, commitsArray.length());

        JSONArray branchesArray = commitsArray.getJSONObject(0).getJSONArray(GitConstants.KEY_BRANCHES);
        assertEquals(3, branchesArray.length());
        assertEquals(Constants.R_HEADS + "branch",
                branchesArray.getJSONObject(0).get(ProtocolConstants.KEY_FULL_NAME));
        assertEquals(Constants.R_HEADS + Constants.MASTER,
                branchesArray.getJSONObject(1).get(ProtocolConstants.KEY_FULL_NAME));
        assertEquals(Constants.R_REMOTES + Constants.DEFAULT_REMOTE_NAME + "/" + Constants.MASTER,
                branchesArray.getJSONObject(2).get(ProtocolConstants.KEY_FULL_NAME));
    }//  w w w  .  j a  v  a  2 s.  c  o  m
}

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

License:Open Source License

@Test
public void testLogAllBranches() throws Exception {
    URI workspaceLocation = createWorkspace(getMethodName());
    JSONObject projectTop = createProjectOrLink(workspaceLocation, getMethodName() + "-top", null);
    IPath clonePathTop = new Path("file").append(projectTop.getString(ProtocolConstants.KEY_ID)).makeAbsolute();

    JSONObject projectFolder = createProjectOrLink(workspaceLocation, getMethodName() + "-folder", null);
    IPath clonePathFolder = new Path("file").append(projectFolder.getString(ProtocolConstants.KEY_ID))
            .append("folder").makeAbsolute();

    IPath[] clonePaths = new IPath[] { clonePathTop, clonePathFolder };

    for (IPath clonePath : clonePaths) {
        // clone a repo
        JSONObject clone = clone(clonePath);
        String cloneLocation = clone.getString(ProtocolConstants.KEY_LOCATION);
        String cloneContentLocation = clone.getString(ProtocolConstants.KEY_CONTENT_LOCATION);
        String branchesLocation = clone.getString(GitConstants.KEY_BRANCH);
        String gitCommitUri = clone.getString(GitConstants.KEY_COMMIT);

        // get project metadata
        WebRequest request = getGetFilesRequest(cloneContentLocation);
        WebResponse response = webConversation.getResponse(request);
        assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
        JSONObject project = new JSONObject(response.getText());
        JSONObject gitSection = project.getJSONObject(GitConstants.KEY_GIT);
        String gitIndexUri = gitSection.getString(GitConstants.KEY_INDEX);
        String gitHeadUri = gitSection.getString(GitConstants.KEY_HEAD);

        // create branch
        final String newBranchName = "branch";
        branch(branchesLocation, newBranchName);

        // modify
        String projectLocation = project.getString(ProtocolConstants.KEY_LOCATION);
        request = getPutFileRequest(projectLocation + "test.txt", "first change");
        response = webConversation.getResponse(request);
        assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());

        // add//w  w  w . ja v  a 2 s .com
        request = GitAddTest.getPutGitIndexRequest(gitIndexUri + "test.txt");
        response = webConversation.getResponse(request);
        assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());

        // commit1
        request = GitCommitTest.getPostGitCommitRequest(gitHeadUri, "commit1", false);
        response = webConversation.getResponse(request);
        assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());

        // checkout "branch"
        checkoutBranch(cloneLocation, newBranchName);

        // modify again
        request = getPutFileRequest(projectLocation + "test.txt", "second change");
        response = webConversation.getResponse(request);
        assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());

        // add
        request = GitAddTest.getPutGitIndexRequest(gitIndexUri + "test.txt");
        response = webConversation.getResponse(request);
        assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());

        // commit2
        request = GitCommitTest.getPostGitCommitRequest(gitHeadUri, "commit2", false);
        response = webConversation.getResponse(request);
        assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());

        // get standard log for HEAD - only init and commit2 should be visible
        JSONArray commitsArray = log(gitHeadUri, false);
        assertEquals(2, commitsArray.length());

        JSONObject commit = commitsArray.getJSONObject(0);
        assertEquals("commit2", commit.get(GitConstants.KEY_COMMIT_MESSAGE));

        commit = commitsArray.getJSONObject(1);
        assertEquals("Initial commit", commit.get(GitConstants.KEY_COMMIT_MESSAGE));

        // get log for all branches - initial commit, commit1 and commit2 should be visible
        commitsArray = log(gitCommitUri, false);
        assertEquals(3, commitsArray.length());

        commit = commitsArray.getJSONObject(0);
        assertEquals("commit2", commit.get(GitConstants.KEY_COMMIT_MESSAGE));
        JSONArray branchesArray = commit.getJSONArray(GitConstants.KEY_BRANCHES);
        assertEquals(1, branchesArray.length());
        assertEquals(Constants.R_HEADS + newBranchName,
                branchesArray.getJSONObject(0).get(ProtocolConstants.KEY_FULL_NAME));

        commit = commitsArray.getJSONObject(1);
        assertEquals("commit1", commit.get(GitConstants.KEY_COMMIT_MESSAGE));
        branchesArray = commit.getJSONArray(GitConstants.KEY_BRANCHES);
        assertEquals(1, branchesArray.length());
        assertEquals(Constants.R_HEADS + Constants.MASTER,
                branchesArray.getJSONObject(0).get(ProtocolConstants.KEY_FULL_NAME));

        commit = commitsArray.getJSONObject(2);
        assertEquals("Initial commit", commit.get(GitConstants.KEY_COMMIT_MESSAGE));
        branchesArray = commit.getJSONArray(GitConstants.KEY_BRANCHES);
        assertEquals(1, branchesArray.length());
        assertEquals(Constants.R_REMOTES + Constants.DEFAULT_REMOTE_NAME + "/" + Constants.MASTER,
                branchesArray.getJSONObject(0).get(ProtocolConstants.KEY_FULL_NAME));
    }
}

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

License:Open Source License

static void assertBranchExist(Git git, String branch) {
    List<Ref> list = git.branchList().call();
    for (Ref ref : list) {
        if (ref.getName().equals(Constants.R_HEADS + branch)) {
            return; // found
        }/*from ww w  . ja  va 2 s . c o  m*/
    }
    fail("branch '" + branch + "' doesn't exist locally");
}

From source file:org.fedoraproject.eclipse.packager.git.api.ConvertLocalToRemoteCommand.java

License:Open Source License

/**
 * Adds the corresponding remote repository as the default name 'origin' to
 * the existing local repository (uses the JGit API)
 *
 * @param uri/*from   w  w w. j  a  v  a  2  s .c o  m*/
 * @param monitor
 * @throws LocalProjectConversionFailedException
 */
private void addRemoteRepository(String uri, IProgressMonitor monitor)
        throws LocalProjectConversionFailedException {

    try {
        RemoteConfig config = new RemoteConfig(git.getRepository().getConfig(), "origin"); //$NON-NLS-1$
        config.addURI(new URIish(uri));
        String dst = Constants.R_REMOTES + config.getName();
        RefSpec refSpec = new RefSpec();
        refSpec = refSpec.setForceUpdate(true);
        refSpec = refSpec.setSourceDestination(Constants.R_HEADS + "*", dst + "/*"); //$NON-NLS-1$ //$NON-NLS-2$

        config.addFetchRefSpec(refSpec);
        config.update(git.getRepository().getConfig());
        git.getRepository().getConfig().save();

        // fetch all the remote branches,
        // create corresponding branches locally and merge them
        FetchCommand fetch = git.fetch();
        fetch.setRemote("origin"); //$NON-NLS-1$
        fetch.setTimeout(0);
        fetch.setRefSpecs(refSpec);
        if (monitor.isCanceled()) {
            throw new OperationCanceledException();
        }
        fetch.call();

    } catch (Exception e) {
        throw new LocalProjectConversionFailedException(e.getCause().getMessage(), e);
    }
}

From source file:org.fedoraproject.eclipse.packager.git.FedoraPackagerGitCloneOperation.java

License:Open Source License

/**
 * Execute the clone including local branch name creation.
 * //from  w ww. j a va2s.  com
 * @param monitor
 * @throws IllegalStateException
 * @throws InvocationTargetException
 * @throws InterruptedException
 * @throws CoreException
 * @throws IOException
 * @return A Git API instance.
 */
public Git run(IProgressMonitor monitor) throws IllegalStateException, InvocationTargetException,
        InterruptedException, CoreException, IOException {
    if (!runnable || hasRun) {
        throw new IllegalStateException(
                NLS.bind(FedoraPackagerGitText.FedoraPackagerGitCloneOperation_operationMisconfiguredError,
                        this.getClass().getName()));
    }

    final CloneOperation clone = new CloneOperation(uri, true, null,
            ResourcesPlugin.getWorkspace().getRoot().getLocation().append(packageName).toFile(),
            Constants.R_HEADS + Constants.MASTER, "origin", 0); //$NON-NLS-1$
    clone.run(monitor);
    if (monitor.isCanceled()) {
        throw new InterruptedException();
    }

    // Find repo we've just created and set gitRepo
    RepositoryCache repoCache = org.eclipse.egit.core.Activator.getDefault().getRepositoryCache();
    Git git = new Git(repoCache.lookupRepository(clone.getGitDir()));

    createLocalBranches(git, monitor);

    // Add cloned repository to the list of Git repositories so that it
    // shows up in the Git repositories view.
    final RepositoryUtil config = org.eclipse.egit.core.Activator.getDefault().getRepositoryUtil();
    config.addConfiguredRepository(clone.getGitDir());

    this.hasRun = true; // disallow two runs of the same instance

    return git;
}