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

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

Introduction

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

Prototype

public boolean isBare() 

Source Link

Document

Whether this repository is bare

Usage

From source file:org.eclipse.egit.core.internal.indexdiff.IndexDiffCacheEntry.java

License:Open Source License

/**
 * @param repository/*  w ww. j  ava  2  s.c  om*/
 */
public IndexDiffCacheEntry(Repository repository) {
    this.repository = repository;
    indexChangedListenerHandle = repository.getListenerList()
            .addIndexChangedListener(new IndexChangedListener() {
                public void onIndexChanged(IndexChangedEvent event) {
                    refreshIndexDelta();
                }
            });
    refsChangedListenerHandle = repository.getListenerList().addRefsChangedListener(new RefsChangedListener() {
        public void onRefsChanged(RefsChangedEvent event) {
            scheduleReloadJob("RefsChanged"); //$NON-NLS-1$
        }
    });
    scheduleReloadJob("IndexDiffCacheEntry construction"); //$NON-NLS-1$
    createResourceChangeListener();
    if (!repository.isBare()) {
        try {
            lastIndex = repository.readDirCache();
        } catch (IOException ex) {
            Activator.error(
                    MessageFormat.format(CoreText.IndexDiffCacheEntry_errorCalculatingIndexDelta, repository),
                    ex);
        }
    }
}

From source file:org.eclipse.egit.gitflow.ui.internal.properties.RepositoryPropertyTester.java

License:Open Source License

@Override
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
    if (receiver == null) {
        return false;
    }/*from ww  w . j av a  2  s . com*/
    Repository repository = null;
    if (receiver instanceof String) {
        String gitDir = (String) receiver;
        repository = org.eclipse.egit.core.Activator.getDefault().getRepositoryCache()
                .getRepository(new File(gitDir));
    } else if (receiver instanceof Repository) {
        repository = (Repository) receiver;
    }
    if (repository == null || repository.isBare()) {
        return false;
    }
    GitFlowRepository gitFlowRepository = new GitFlowRepository(repository);
    try {
        if (IS_INITIALIZED.equals(property)) {
            return gitFlowRepository.getConfig().isInitialized();
        } else if (IS_FEATURE.equals(property)) {
            return gitFlowRepository.isFeature();
        } else if (IS_RELEASE.equals(property)) {
            return gitFlowRepository.isRelease();
        } else if (IS_HOTFIX.equals(property)) {
            return gitFlowRepository.isHotfix();
        } else if (IS_DEVELOP.equals(property)) {
            return gitFlowRepository.isDevelop();
        } else if (IS_MASTER.equals(property)) {
            return gitFlowRepository.isMaster();
        } else if (HAS_DEFAULT_REMOTE.equals(property)) {
            return gitFlowRepository.getConfig().hasDefaultRemote();
        }
    } catch (IOException e) {
        Activator.getDefault().getLog().log(error(e.getMessage(), e));
    }
    return false;
}

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();/*  w w w. j a v  a2 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.internal.actions.CleanActionHandler.java

License:Open Source License

@Override
public boolean isEnabled() {
    Repository repository = getRepository();
    return repository != null && !repository.isBare();
}

From source file:org.eclipse.egit.ui.internal.factories.GitAdapterFactory.java

License:Open Source License

@Nullable
private IResource getWorkspaceResourceFromGitPath(IPath gitPath) {
    Repository repository = Activator.getDefault().getRepositoryCache().getRepository(gitPath);
    if (repository == null || repository.isBare()) {
        return null;
    }/*  w  w w .  j  a v a  2  s .c om*/
    try {
        IPath repoRelativePath = gitPath.makeRelativeTo(new Path(repository.getWorkTree().getAbsolutePath()));
        IProject[] projects = ProjectUtil.getProjectsContaining(repository,
                Collections.singleton(repoRelativePath.toString()));
        if (projects.length > 0) {
            IPath projectRelativePath = gitPath.makeRelativeTo(projects[0].getLocation());
            if (projectRelativePath.isEmpty()) {
                return projects[0];
            } else {
                return projects[0].getFile(projectRelativePath);
            }
        }
    } catch (CoreException e) {
        // Ignore and fall through
    }
    return root.getFile(gitPath);
}

From source file:org.eclipse.egit.ui.internal.GitLabelProvider.java

License:Open Source License

/**
 * @param repository/* w ww  . j  a v a2s.  c om*/
 * @return a styled string for the repository
 * @throws IOException
 */
protected StyledString getStyledTextFor(Repository repository) throws IOException {
    File directory = repository.getDirectory();
    StyledString string = new StyledString();
    if (!repository.isBare())
        string.append(directory.getParentFile().getName());
    else
        string.append(directory.getName());

    String branch = Activator.getDefault().getRepositoryUtil().getShortBranch(repository);
    if (branch != null) {
        string.append(' ');
        string.append('[', StyledString.DECORATIONS_STYLER);
        string.append(branch, StyledString.DECORATIONS_STYLER);

        RepositoryState repositoryState = repository.getRepositoryState();
        if (repositoryState != RepositoryState.SAFE) {
            string.append(" - ", StyledString.DECORATIONS_STYLER); //$NON-NLS-1$
            string.append(repositoryState.getDescription(), StyledString.DECORATIONS_STYLER);
        }

        BranchTrackingStatus trackingStatus = BranchTrackingStatus.of(repository, branch);
        if (trackingStatus != null
                && (trackingStatus.getAheadCount() != 0 || trackingStatus.getBehindCount() != 0)) {
            String formattedTrackingStatus = formatBranchTrackingStatus(trackingStatus);
            string.append(' ');
            string.append(formattedTrackingStatus, StyledString.DECORATIONS_STYLER);
        }
        string.append(']', StyledString.DECORATIONS_STYLER);
    }

    string.append(" - ", StyledString.QUALIFIER_STYLER); //$NON-NLS-1$
    string.append(directory.getAbsolutePath(), StyledString.QUALIFIER_STYLER);

    return string;
}

From source file:org.eclipse.egit.ui.internal.GitLabelProvider.java

License:Open Source License

private String getSimpleTextFor(Repository repository) {
    File directory;//from   w  w w  .  j ava2s.  c  o m
    if (!repository.isBare())
        directory = repository.getDirectory().getParentFile();
    else
        directory = repository.getDirectory();
    StringBuilder sb = new StringBuilder();
    sb.append(directory.getName());
    sb.append(" - "); //$NON-NLS-1$
    sb.append(directory.getAbsolutePath());
    return sb.toString();
}

From source file:org.eclipse.egit.ui.internal.push.PushBranchWizardTest.java

License:Open Source License

private Repository createRemoteRepository() throws IOException {
    File gitDir = new File(getTestDirectory(), "pushbranchremote");
    Repository repo = FileRepositoryBuilder.create(gitDir);
    repo.create(true);//from w  w w  . j a v a 2 s . c o  m
    assertTrue(repo.isBare());
    return repo;
}

From source file:org.eclipse.egit.ui.internal.rebase.RebaseInteractiveView.java

License:Open Source License

private boolean isValidRepo(final Repository repository) {
    return repository != null && !repository.isBare() && repository.getWorkTree().exists();
}

From source file:org.eclipse.egit.ui.internal.repository.tree.command.GarbageCollectCommand.java

License:Open Source License

private String getRepositoryName(Repository repository) {
    File directory;//from   w  ww. j  a  va2  s . c  o  m
    if (!repository.isBare())
        directory = repository.getDirectory().getParentFile();
    else
        directory = repository.getDirectory();
    StringBuilder sb = new StringBuilder();
    sb.append(directory.getName());
    sb.append(" - "); //$NON-NLS-1$
    sb.append(directory.getAbsolutePath());
    return sb.toString();
}