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:com.madgag.agit.RepoDeleter.java

License:Open Source License

RepoDeleter(Repository repository, Context context) {
    this.gitdir = repository.getDirectory();
    this.topFolderToDelete = repository.isBare() ? repository.getDirectory() : repository.getWorkTree();
    this.context = context;
}

From source file:com.madgag.agit.Repos.java

License:Open Source License

public static String niceNameFor(Repository repo) {
    return niceNameFromNameDirectory(repo.isBare() ? repo.getDirectory() : repo.getWorkTree());
}

From source file:com.microsoft.gittf.client.clc.commands.framework.Command.java

License:Open Source License

protected void verifyNonBareRepo() throws Exception {
    Repository repository = getRepository();

    if (repository.isBare()) {
        throw new Exception(Messages.getString("Command.CommandNeedsNonBare")); //$NON-NLS-1$
    }//from w w w. jav a 2s  .  co m
}

From source file:com.microsoft.gittf.core.util.TfsBranchUtil.java

License:Open Source License

/**
 * //from  w ww . j  a va2 s .co  m
 * Creates a remote tracking ref for tfs. If the repo is bare a regular
 * branch is created too.
 * 
 * @param repository
 * @param startPoint
 * @throws RefAlreadyExistsException
 * @throws RefNotFoundException
 * @throws InvalidRefNameException
 * @throws GitAPIException
 * @throws IOException
 */
public static void create(Repository repository, String startPoint) throws RefAlreadyExistsException,
        RefNotFoundException, InvalidRefNameException, GitAPIException, IOException {
    if (repository.isBare()) {
        CreateBranchCommand createBranch = new Git(repository).branchCreate();
        createBranch.setName(GitTFConstants.GIT_TF_BRANCHNAME);
        createBranch.setForce(true);
        if (startPoint != null && startPoint.length() > 0) {
            createBranch.setStartPoint(startPoint);
        }
        createBranch.call();
    }

    TfsRemoteReferenceUpdate remoteRefUpdate = new TfsRemoteReferenceUpdate(repository, startPoint);
    remoteRefUpdate.update();
}

From source file:com.microsoft.gittf.core.util.TfsBranchUtil.java

License:Open Source License

/**
 * Updates the remote tracking branch and branch to point at the commit
 * specified.// ww  w.j  a  v a2s .c o m
 * 
 * @param repository
 * @param commitId
 * @throws IOException
 * @throws RefAlreadyExistsException
 * @throws RefNotFoundException
 * @throws InvalidRefNameException
 * @throws GitAPIException
 */
public static void update(Repository repository, ObjectId commitId) throws IOException,
        RefAlreadyExistsException, RefNotFoundException, InvalidRefNameException, GitAPIException {
    if (repository.isBare()) {
        Ref tfsBranchRef = repository.getRef(Constants.R_HEADS + GitTFConstants.GIT_TF_BRANCHNAME);
        if (tfsBranchRef == null) {
            create(repository);
        }

        RefUpdate ref = repository.updateRef(Constants.R_HEADS + GitTFConstants.GIT_TF_BRANCHNAME);
        ref.setNewObjectId(commitId);
        ref.setForceUpdate(true);
        ref.update();
    }

    TfsRemoteReferenceUpdate remoteRefUpdate = new TfsRemoteReferenceUpdate(repository, commitId.name());
    remoteRefUpdate.update();

}

From source file:edu.nju.cs.inform.jgit.unfinished.TestSubmodules.java

License:Apache License

private static Repository openMainRepo(File mainRepoDir) throws IOException {
    FileRepositoryBuilder builder = new FileRepositoryBuilder();

    Repository mainRepo = builder.setGitDir(new File(mainRepoDir.getAbsolutePath(), ".git")).readEnvironment() // scan environment GIT_* variables
            .findGitDir() // scan up the file system tree
            .build();//from w  ww.  java 2 s  .c o  m

    if (mainRepo.isBare()) {
        throw new IllegalStateException("Repository at " + mainRepoDir + " should not be bare");
    }
    return mainRepo;
}

From source file:models.PullRequestTest.java

License:Apache License

@Before
public void initRepositories() throws Exception {
    GitRepository.setRepoPrefix(REPO_PREFIX);

    app = support.Helpers.makeTestApplication();
    Helpers.start(app);//  ww  w  .  j av  a2 s .c  o m

    Project project = Project.findByOwnerAndProjectName("yobi", "projectYobi");
    forkedProject = Project.findByOwnerAndProjectName("yobi", "projectYobi-1");

    // 1. projectYobi  
    RepositoryService.createRepository(project);

    // 2. projectYobi ?  
    {
        String localRepoPath = LOCAL_REPO_PREFIX + project.name;
        Git git = Git.cloneRepository().setURI(GitRepository.getGitDirectoryURL(project))
                .setDirectory(new File(localRepoPath)).call();
        Repository repo = git.getRepository();
        baseCommit = support.Git.commit(repo, "test.txt", "apple\nbanana\ncat\n", "commit 1");
        git.push().setRefSpecs(new RefSpec("+refs/heads/master:refs/heads/master")).call();
    }

    // 3. ??? ? ??  
    GitRepository.cloneLocalRepository(project, forkedProject);

    // 4. ??? ?     ? ? ? 
    {
        String localRepoPath = LOCAL_REPO_PREFIX + forkedProject.name;
        Git git = Git.cloneRepository().setURI(GitRepository.getGitDirectoryURL(forkedProject))
                .setDirectory(new File(localRepoPath)).call();
        git.branchCreate().setName("fix/1").call();
        git.checkout().setName("fix/1").call();
        Repository repo = git.getRepository();
        assertThat(repo.isBare()).describedAs("projectYobi-1 must be non-bare").isFalse();
        firstCommit = support.Git.commit(repo, "test.txt", "apple\nbanana\ncorn\n", "commit 1");
        secondCommit = support.Git.commit(repo, "test.txt", "apple\nbanana\ncake\n", "commit 2");
        git.push().setRefSpecs(new RefSpec("+refs/heads/fix/1:refs/heads/fix/1")).call();
    }

    // 5.   projectYobi? pullrequest .
    pullRequest = PullRequest.createNewPullRequest(forkedProject, project, "refs/heads/fix/1",
            "refs/heads/master");
    pullRequest.save();

    // 6. attempt merge
    boolean isConflict = pullRequest.updateMerge().conflicts();

    assertThat(isConflict).isFalse();
}

From source file:org.eclipse.egit.core.internal.CompareCoreUtils.java

License:Open Source License

/**
 * Determine the encoding used by Eclipse for the resource which belongs to
 * repoPath in the eclipse workspace or null if no resource is found
 *
 * @param db//  w ww  .  j a  v  a2s . c  o m
 *            the repository
 * @param repoPath
 *            the path in the git repository
 * @return the encoding used in eclipse for the resource or null if
 *
 */
public static String getResourceEncoding(Repository db, String repoPath) {
    if (db.isBare())
        return null;
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    IWorkspaceRoot root = workspace.getRoot();
    IPath absolutePath = new Path(db.getWorkTree().getAbsolutePath()).append(repoPath);
    IResource resource = root.getFileForLocation(absolutePath);
    if (resource == null)
        return null;

    return getResourceEncoding(resource);
}

From source file:org.eclipse.egit.core.internal.gerrit.GerritUtil.java

License:Open Source License

/**
 * If the repository is not bare and looks like it might be a Gerrit
 * repository, try to configure it such that EGit's Gerrit support is
 * enabled./*  w  w w .j  av a2 s .c  om*/
 *
 * @param repository
 *            to try to configure
 */
public static void tryToAutoConfigureForGerrit(@NonNull Repository repository) {
    if (repository.isBare()) {
        return;
    }
    StoredConfig config = repository.getConfig();
    boolean isGerrit = false;
    boolean changed = false;
    try {
        for (RemoteConfig remote : RemoteConfig.getAllRemoteConfigs(config)) {
            if (isGerritPush(remote)) {
                isGerrit = true;
                if (configureFetchNotes(remote)) {
                    changed = true;
                    remote.update(config);
                }
            }
        }
    } catch (URISyntaxException ignored) {
        // Ignore it here -- we're just trying to set up Gerrit support.
    }
    if (isGerrit) {
        if (config.getString(ConfigConstants.CONFIG_GERRIT_SECTION, null,
                ConfigConstants.CONFIG_KEY_CREATECHANGEID) != null) {
            // Already configured.
        } else {
            setCreateChangeId(config);
            changed = true;
        }
        if (changed) {
            try {
                config.save();
            } catch (IOException e) {
                Activator.logError(
                        MessageFormat.format(CoreText.GerritUtil_ConfigSaveError, repository.getDirectory()),
                        e);
            }
        }
    }
}

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

License:Open Source License

/**
 * @param repository/*from   w w w  .  j  a  va2  s.com*/
 * @return cache entry
 */
public IndexDiffCacheEntry getIndexDiffCacheEntry(Repository repository) {
    IndexDiffCacheEntry entry;
    synchronized (entries) {
        entry = entries.get(repository);
        if (entry != null)
            return entry;
        if (repository.isBare())
            return null;
        entry = new IndexDiffCacheEntry(repository);
        entries.put(repository, entry);
    }
    entry.addIndexDiffChangedListener(globalListener);
    return entry;
}