Search in sources :

Example 1 with StageState

use of org.eclipse.jgit.lib.IndexDiff.StageState 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)

Aggregations

HashSet (java.util.HashSet)1 JoinString (org.commonjava.maven.atlas.ident.util.JoinString)1 Status (org.eclipse.jgit.api.Status)1 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)1 NoWorkTreeException (org.eclipse.jgit.errors.NoWorkTreeException)1 StageState (org.eclipse.jgit.lib.IndexDiff.StageState)1