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

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

Introduction

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

Prototype


public File getDirectory() 

Source Link

Document

Get local metadata directory

Usage

From source file:org.eclipse.egit.gitflow.op.FeatureFinishOperationTest.java

License:Open Source License

@Test
public void testFeatureFinishFastForward() throws Exception {
    String fileName = "theFirstFile.txt";
    Repository repository = testRepository.getRepository();
    GitFlowRepository gfRepo = init("testFeatureFinish\n\nfirst commit\n");

    new FeatureStartOperation(gfRepo, MY_FEATURE).execute(null);
    RevCommit branchCommit = addFileAndCommit(fileName, "adding file on feature branch");
    new FeatureFinishOperation(gfRepo).execute(null);
    assertEquals(gfRepo.getConfig().getDevelopFull(), repository.getFullBranch());

    String branchName = gfRepo.getConfig().getFeatureBranchName(MY_FEATURE);
    assertNull(findBranch(repository, branchName));

    RevCommit developHead = gfRepo.findHead();
    assertEquals(branchCommit, developHead);

    assertEquals(2, countCommits(repository));
    assertTrue(new File(repository.getDirectory() + "/../" + fileName).exists());
}

From source file:org.eclipse.egit.gitflow.op.FeatureFinishOperationTest.java

License:Open Source License

@Test
public void testFeatureFinishSquash() throws Exception {
    String fileName = "theFirstFile.txt";
    String fileName2 = "theSecondFile.txt";

    Repository repository = testRepository.getRepository();
    GitFlowRepository gfRepo = init("testFeatureFinishSquash\n\nfirst commit\n");

    new FeatureStartOperation(gfRepo, MY_FEATURE).execute(null);

    String branchName = gfRepo.getConfig().getFeatureBranchName(MY_FEATURE);
    addFileAndCommit(fileName, "adding first file on feature branch");
    addFileAndCommit(fileName2, "adding second file on feature branch");
    FeatureFinishOperation featureFinishOperation = new FeatureFinishOperation(gfRepo);
    featureFinishOperation.setSquash(true);
    featureFinishOperation.execute(null);
    assertEquals(gfRepo.getConfig().getDevelopFull(), repository.getFullBranch());
    assertEquals(null, findBranch(repository, branchName));

    assertEquals(1, countCommits(repository));
    assertTrue(new File(repository.getDirectory() + "/../" + fileName).exists());
    assertTrue(new File(repository.getDirectory() + "/../" + fileName2).exists());

    Status status = Git.wrap(repository).status().call();
    assertTrue(status.hasUncommittedChanges());
}

From source file:org.eclipse.egit.ui.common.LocalRepositoryTestCase.java

License:Open Source License

protected static File createRemoteRepository(File repositoryDir) throws Exception {
    FileRepository myRepository = lookupRepository(repositoryDir);
    File gitDir = new File(testDirectory, REPO2);
    Repository myRemoteRepository = new FileRepository(gitDir);
    myRemoteRepository.create();/*from   w w  w .  j  a v  a 2  s  .  c om*/
    // double-check that this is bare
    assertTrue(myRemoteRepository.isBare());

    createStableBranch(myRepository);

    // now we configure a pure push destination
    myRepository.getConfig().setString("remote", "push", "pushurl",
            "file:///" + myRemoteRepository.getDirectory().getPath());
    myRepository.getConfig().setString("remote", "push", "push", "+refs/heads/*:refs/heads/*");

    // and a pure fetch destination
    myRepository.getConfig().setString("remote", "fetch", "url",
            "file:///" + myRemoteRepository.getDirectory().getPath());
    myRepository.getConfig().setString("remote", "fetch", "fetch", "+refs/heads/*:refs/heads/*");

    // a destination with both fetch and push urls and specs
    myRepository.getConfig().setString("remote", "both", "pushurl",
            "file:///" + myRemoteRepository.getDirectory().getPath());
    myRepository.getConfig().setString("remote", "both", "push", "+refs/heads/*:refs/heads/*");
    myRepository.getConfig().setString("remote", "both", "url",
            "file:///" + myRemoteRepository.getDirectory().getPath());
    myRepository.getConfig().setString("remote", "both", "fetch", "+refs/heads/*:refs/heads/*");

    // a destination with only a fetch url and push and fetch specs
    myRepository.getConfig().setString("remote", "mixed", "push", "+refs/heads/*:refs/heads/*");
    myRepository.getConfig().setString("remote", "mixed", "url",
            "file:///" + myRemoteRepository.getDirectory().getPath());
    myRepository.getConfig().setString("remote", "mixed", "fetch", "+refs/heads/*:refs/heads/*");

    myRepository.getConfig().save();
    // and push
    PushConfiguredRemoteAction pa = new PushConfiguredRemoteAction(myRepository, "push");

    pa.run(null, false);

    try {
        // delete the stable branch again
        RefUpdate op = myRepository.updateRef("refs/heads/stable");
        op.setRefLogMessage("branch deleted", //$NON-NLS-1$
                false);
        // we set the force update in order
        // to avoid having this rejected
        // due to minor issues
        op.setForceUpdate(true);
        op.delete();
    } catch (IOException ioe) {
        throw new InvocationTargetException(ioe);
    }
    return myRemoteRepository.getDirectory();
}

From source file:org.eclipse.egit.ui.common.LocalRepositoryTestCase.java

License:Open Source License

protected static File createChildRepository(File repositoryDir) throws Exception {
    Repository myRepository = lookupRepository(repositoryDir);
    URIish uri = new URIish("file:///" + myRepository.getDirectory());
    File workdir = new File(testDirectory, CHILDREPO);
    CloneOperation clop = new CloneOperation(uri, true, null, workdir, "refs/heads/master", "origin", 0);
    clop.run(null);/*ww w . j a v  a  2  s . c o m*/
    return new File(workdir, Constants.DOT_GIT);
}

From source file:org.eclipse.egit.ui.common.LocalRepositoryTestCase.java

License:Open Source License

protected void shareProjects(File repositoryDir) throws Exception {
    Repository myRepository = lookupRepository(repositoryDir);
    FilenameFilter projectFilter = new FilenameFilter() {
        public boolean accept(File dir, String name) {
            return name.equals(".project");
        }/*from  w  ww .java  2 s .  c om*/
    };
    for (File file : myRepository.getWorkTree().listFiles()) {
        if (file.isDirectory()) {
            if (file.list(projectFilter).length > 0) {
                IProjectDescription desc = ResourcesPlugin.getWorkspace().newProjectDescription(file.getName());
                desc.setLocation(new Path(file.getPath()));
                IProject prj = ResourcesPlugin.getWorkspace().getRoot().getProject(file.getName());
                prj.create(desc, null);
                prj.open(null);

                new ConnectProviderOperation(prj, myRepository.getDirectory()).execute(null);
            }
        }
    }
}

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

License:Open Source License

private void buildIndexHeadDiffList(IProject[] selectedProjects, IProgressMonitor monitor)
        throws IOException, OperationCanceledException {
    HashMap<Repository, HashSet<IProject>> repositories = new HashMap<Repository, HashSet<IProject>>();

    for (IProject project : selectedProjects) {
        RepositoryMapping repositoryMapping = RepositoryMapping.getMapping(project);
        assert repositoryMapping != null;

        Repository repository = repositoryMapping.getRepository();

        HashSet<IProject> projects = repositories.get(repository);

        if (projects == null) {
            projects = new HashSet<IProject>();
            repositories.put(repository, projects);
        }//from   www . ja  v  a2  s .  c  om

        projects.add(project);
    }

    monitor.beginTask(UIText.CommitActionHandler_caculatingChanges, repositories.size());
    for (Map.Entry<Repository, HashSet<IProject>> entry : repositories.entrySet()) {
        Repository repository = entry.getKey();
        monitor.subTask(NLS.bind(UIText.CommitActionHandler_repository, repository.getDirectory().getPath()));
        HashSet<IProject> projects = entry.getValue();

        IndexDiff indexDiff = new IndexDiff(repository, Constants.HEAD,
                IteratorService.createInitialIterator(repository));
        indexDiff.diff();
        indexDiffs.put(repository, indexDiff);

        for (IProject project : projects) {
            includeList(project, indexDiff.getAdded(), indexChanges);
            includeList(project, indexDiff.getChanged(), indexChanges);
            includeList(project, indexDiff.getRemoved(), indexChanges);
            includeList(project, indexDiff.getMissing(), notIndexed);
            includeList(project, indexDiff.getModified(), notIndexed);
            includeList(project, indexDiff.getUntracked(), notTracked);
        }
        if (monitor.isCanceled())
            throw new OperationCanceledException();
        monitor.worked(1);
    }
    monitor.done();
}

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

License:Open Source License

private String getMergeResolveMessage(Repository mergeRepository, ExecutionEvent event)
        throws ExecutionException {
    File mergeMsg = new File(mergeRepository.getDirectory(), Constants.MERGE_MSG);
    FileReader reader;/*  ww  w.  ja v a 2  s  . com*/
    try {
        reader = new FileReader(mergeMsg);
        BufferedReader br = new BufferedReader(reader);
        try {
            StringBuilder message = new StringBuilder();
            String s;
            String newLine = newLine();
            while ((s = br.readLine()) != null) {
                message.append(s).append(newLine);
            }
            return message.toString();
        } catch (IOException e) {
            MessageDialog.openError(getShell(event), UIText.CommitAction_MergeHeadErrorTitle,
                    UIText.CommitAction_ErrorReadingMergeMsg);
            throw new IllegalStateException(e);
        } finally {
            try {
                br.close();
            } catch (IOException e) {
                // Empty
            }
        }
    } catch (FileNotFoundException e) {
        MessageDialog.openError(getShell(event), UIText.CommitAction_MergeHeadErrorTitle,
                UIText.CommitAction_MergeHeadErrorMessage);
        throw new IllegalStateException(e);
    }
}

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

License:Open Source License

@Override
protected void execute(IAction action) throws InvocationTargetException, InterruptedException {
    Repository[] repos = getRepositories();

    if (repos.length != repos.length)
        return;//from  www.  j  av  a  2 s.co m

    GitSynchronizeDataSet gsdSet = new GitSynchronizeDataSet();
    for (Repository repo : repos) {
        List<SyncRepoEntity> syncRepoEntitys = createSyncRepoEntitys(repo);
        SelectSynchronizeResourceDialog dialog = new SelectSynchronizeResourceDialog(getShell(),
                repo.getDirectory(), syncRepoEntitys);

        if (dialog.open() != IDialogConstants.OK_ID)
            return;

        gsdSet.add(new GitSynchronizeData(repo, dialog.getSrcRef(), dialog.getDstRef(),
                dialog.shouldIncludeLocal()));
    }

    new GitSynchronize(gsdSet);
}

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

License:Open Source License

public Object execute(ExecutionEvent event) throws ExecutionException {
    Repository[] repos = getRepositories(event);

    if (repos.length != repos.length)
        return null;

    GitSynchronizeDataSet gsdSet = new GitSynchronizeDataSet();
    for (Repository repo : repos) {
        try {// ww  w  . j ava2 s.c  o m
            List<SyncRepoEntity> syncRepoEntitys = createSyncRepoEntitys(repo);
            SelectSynchronizeResourceDialog dialog = new SelectSynchronizeResourceDialog(getShell(event),
                    repo.getDirectory(), syncRepoEntitys);

            if (dialog.open() != IDialogConstants.OK_ID)
                return null;

            gsdSet.add(new GitSynchronizeData(repo, dialog.getSrcRef(), dialog.getDstRef(),
                    dialog.shouldIncludeLocal()));
        } catch (URISyntaxException e) {
            Activator.handleError(e.getMessage(), e, true);
        } catch (IOException e) {
            Activator.handleError(e.getMessage(), e, true);
        }
    }

    GitModelSynchronize.launch(gsdSet, getSelectedResources(event));

    return null;
}

From source file:org.eclipse.egit.ui.internal.clone.ProjectUtils.java

License:Open Source License

/**
 * @param projectsToCreate/*ww w .j  a  v a2 s  .c  om*/
 *            the projects to create
 * @param open
 *            true to open existing projects, false to leave in current
 *            state
 * @param repository
 *            if not null, the projects will be automatically shared
 * @param selectedWorkingSets
 *            the workings sets to add the created projects to, may be null
 *            or empty
 * @param monitor
 * @throws InvocationTargetException
 * @throws InterruptedException
 */
public static void createProjects(final Set<ProjectRecord> projectsToCreate, final boolean open,
        final Repository repository, final IWorkingSet[] selectedWorkingSets, IProgressMonitor monitor)
        throws InvocationTargetException, InterruptedException {
    IWorkspaceRunnable wsr = new IWorkspaceRunnable() {
        public void run(IProgressMonitor actMonitor) throws CoreException {
            IWorkingSetManager workingSetManager = PlatformUI.getWorkbench().getWorkingSetManager();
            try {
                actMonitor.beginTask("", projectsToCreate.size()); //$NON-NLS-1$
                if (actMonitor.isCanceled())
                    throw new OperationCanceledException();
                for (ProjectRecord projectRecord : projectsToCreate) {
                    if (actMonitor.isCanceled())
                        throw new OperationCanceledException();
                    actMonitor.setTaskName(projectRecord.getProjectLabel());
                    IProject project = createExistingProject(projectRecord, open,
                            new SubProgressMonitor(actMonitor, 1));
                    if (project == null)
                        continue;
                    if (repository != null) {
                        ConnectProviderOperation connectProviderOperation = new ConnectProviderOperation(
                                project, repository.getDirectory());
                        connectProviderOperation.execute(actMonitor);
                    }
                    if (selectedWorkingSets != null && selectedWorkingSets.length > 0)
                        workingSetManager.addToWorkingSets(project, selectedWorkingSets);
                }
            } finally {
                actMonitor.done();
            }
        }
    };
    try {
        ResourcesPlugin.getWorkspace().run(wsr, monitor);
    } catch (OperationCanceledException e) {
        throw new InterruptedException();
    } catch (CoreException e) {
        throw new InvocationTargetException(e);
    }
}