Search in sources :

Example 1 with NoWorkTreeException

use of org.eclipse.jgit.errors.NoWorkTreeException in project fuse-karaf by jboss-fuse.

the class GitPatchRepositoryIT method mainRepository.

@Test
public void mainRepository() throws IOException, GitAPIException {
    Git main = repository.findOrCreateMainGitRepository();
    assertNotNull(main);
    assertTrue(main.getRepository().isBare());
    try {
        main.getRepository().getWorkTree();
        fail("Should not contain working tree");
    } catch (NoWorkTreeException ignored) /* expected */
    {
    }
    assertThat("Should contain single ref", new File(main.getRepository().getDirectory(), "refs/heads").listFiles().length, equalTo(1));
    File theOnlyHead = new File(main.getRepository().getDirectory(), "refs/heads/" + GitPatchRepository.HISTORY_BRANCH);
    assertTrue(theOnlyHead.exists());
}
Also used : Git(org.eclipse.jgit.api.Git) NoWorkTreeException(org.eclipse.jgit.errors.NoWorkTreeException) File(java.io.File) Test(org.junit.Test)

Example 2 with NoWorkTreeException

use of org.eclipse.jgit.errors.NoWorkTreeException in project indy by Commonjava.

the class GitManager method getStatus.

private Status getStatus() throws GitSubsystemException {
    Status status;
    try {
        status = git.status().call();
    } catch (NoWorkTreeException | GitAPIException e) {
        throw new GitSubsystemException("Failed to retrieve status of: %s. Reason: %s", e, rootDir, e.getMessage());
    }
    final Map<String, StageState> css = status.getConflictingStageState();
    if (!css.isEmpty()) {
        throw new GitSubsystemException("%s contains conflicts. Cannot auto-commit.\n  %s", rootDir, new JoinString("\n  ", css.entrySet()));
    }
    return status;
}
Also used : Status(org.eclipse.jgit.api.Status) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) JoinString(org.commonjava.atlas.maven.ident.util.JoinString) NoWorkTreeException(org.eclipse.jgit.errors.NoWorkTreeException) StageState(org.eclipse.jgit.lib.IndexDiff.StageState) JoinString(org.commonjava.atlas.maven.ident.util.JoinString)

Example 3 with NoWorkTreeException

use of org.eclipse.jgit.errors.NoWorkTreeException in project indy by Commonjava.

the class GitManager method commitModifiedFiles.

public GitManager commitModifiedFiles(final ChangeSummary changeSummary) throws GitSubsystemException {
    lockAnd((me) -> {
        Status status;
        try {
            status = git.status().call();
        } catch (NoWorkTreeException | GitAPIException e) {
            throw new GitSubsystemException("Failed to retrieve status of: %s. Reason: %s", e, rootDir, e.getMessage());
        }
        final Map<String, StageState> css = status.getConflictingStageState();
        if (!css.isEmpty()) {
            throw new GitSubsystemException("%s contains conflicts. Cannot auto-commit.\n  %s", rootDir, new JoinString("\n  ", css.entrySet()));
        }
        final Set<String> toAdd = new HashSet<>();
        final Set<String> modified = status.getModified();
        if (modified != null && !modified.isEmpty()) {
            toAdd.addAll(modified);
        }
        final Set<String> untracked = status.getUntracked();
        if (untracked != null && !untracked.isEmpty()) {
            toAdd.addAll(untracked);
        }
        final Set<String> untrackedFolders = status.getUntrackedFolders();
        if (untrackedFolders != null && !untrackedFolders.isEmpty()) {
            toAdd.addAll(untrackedFolders);
        //            for ( String folderPath : untrackedFolders )
        //            {
        //                File dir = new File( rootDir, folderPath );
        //                Files.walkFileTree( null, null )
        //            }
        }
        if (!toAdd.isEmpty()) {
            addAndCommitPaths(changeSummary, toAdd);
        }
        return me;
    });
    return this;
}
Also used : Status(org.eclipse.jgit.api.Status) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) JoinString(org.commonjava.maven.atlas.ident.util.JoinString) NoWorkTreeException(org.eclipse.jgit.errors.NoWorkTreeException) StageState(org.eclipse.jgit.lib.IndexDiff.StageState) JoinString(org.commonjava.maven.atlas.ident.util.JoinString) HashSet(java.util.HashSet)

Example 4 with NoWorkTreeException

use of org.eclipse.jgit.errors.NoWorkTreeException in project fabric8 by jboss-fuse.

the class GitPatchRepositoryIT method mainRepository.

@Test
public void mainRepository() throws IOException, GitAPIException {
    Git main = repository.findOrCreateMainGitRepository();
    assertNotNull(main);
    assertTrue(main.getRepository().isBare());
    try {
        main.getRepository().getWorkTree();
        fail("Should not contain working tree");
    } catch (NoWorkTreeException expected) {
    }
    assertThat("Should contain single ref", new File(main.getRepository().getDirectory(), "refs/heads").listFiles().length, equalTo(1));
    File theOnlyHead = new File(main.getRepository().getDirectory(), "refs/heads/" + GitPatchRepository.HISTORY_BRANCH);
    assertTrue(theOnlyHead.exists());
}
Also used : Git(org.eclipse.jgit.api.Git) NoWorkTreeException(org.eclipse.jgit.errors.NoWorkTreeException) File(java.io.File) Test(org.junit.Test)

Aggregations

NoWorkTreeException (org.eclipse.jgit.errors.NoWorkTreeException)4 File (java.io.File)2 Git (org.eclipse.jgit.api.Git)2 Status (org.eclipse.jgit.api.Status)2 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)2 StageState (org.eclipse.jgit.lib.IndexDiff.StageState)2 Test (org.junit.Test)2 HashSet (java.util.HashSet)1 JoinString (org.commonjava.atlas.maven.ident.util.JoinString)1 JoinString (org.commonjava.maven.atlas.ident.util.JoinString)1