Search in sources :

Example 1 with NoFilepatternException

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

the class GitManager method addAndCommitPaths.

public GitManager addAndCommitPaths(final ChangeSummary summary, final Collection<String> paths) throws GitSubsystemException {
    lockAnd(me -> {
        if (!verifyChangesExist(paths)) {
            logger.info("No actual changes in:\n  {}\n\nSkipping commit.", join(paths, "\n  "));
            return this;
        }
        try {
            final AddCommand add = git.add();
            final CommitCommand commit = git.commit();
            for (final String filepath : paths) {
                add.addFilepattern(filepath);
            }
            logger.info("Adding:\n  " + join(paths, "\n  ") + "\n\nSummary: " + summary);
            add.call();
            commit.setMessage(buildMessage(summary, paths)).setAuthor(summary.getUser(), email).call();
        } catch (final NoFilepatternException e) {
            throw new GitSubsystemException("Cannot add to git: " + e.getMessage(), e);
        } catch (final GitAPIException e) {
            throw new GitSubsystemException("Cannot add to git: " + e.getMessage(), e);
        }
        return me;
    });
    return this;
}
Also used : GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) NoFilepatternException(org.eclipse.jgit.api.errors.NoFilepatternException) CommitCommand(org.eclipse.jgit.api.CommitCommand) JoinString(org.commonjava.maven.atlas.ident.util.JoinString) AddCommand(org.eclipse.jgit.api.AddCommand)

Example 2 with NoFilepatternException

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

the class GitManager method deleteAndCommitPaths.

public GitManager deleteAndCommitPaths(final ChangeSummary summary, final Collection<String> paths) throws GitSubsystemException {
    lockAnd(me -> {
        try {
            RmCommand rm = git.rm();
            CommitCommand commit = git.commit();
            for (final String path : paths) {
                rm = rm.addFilepattern(path);
                commit = commit.setOnly(path);
            }
            logger.info("Deleting:\n  " + join(paths, "\n  ") + "\n\nSummary: " + summary);
            rm.call();
            commit.setMessage(buildMessage(summary, paths)).setAuthor(summary.getUser(), email).call();
        } catch (final NoFilepatternException e) {
            throw new GitSubsystemException("Cannot remove from git: " + e.getMessage(), e);
        } catch (final JGitInternalException | GitAPIException e) {
            throw new GitSubsystemException("Cannot remove from git: " + e.getMessage(), e);
        }
        return me;
    });
    return this;
}
Also used : GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) NoFilepatternException(org.eclipse.jgit.api.errors.NoFilepatternException) JGitInternalException(org.eclipse.jgit.api.errors.JGitInternalException) RmCommand(org.eclipse.jgit.api.RmCommand) CommitCommand(org.eclipse.jgit.api.CommitCommand) JoinString(org.commonjava.maven.atlas.ident.util.JoinString)

Aggregations

JoinString (org.commonjava.maven.atlas.ident.util.JoinString)2 CommitCommand (org.eclipse.jgit.api.CommitCommand)2 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)2 NoFilepatternException (org.eclipse.jgit.api.errors.NoFilepatternException)2 AddCommand (org.eclipse.jgit.api.AddCommand)1 RmCommand (org.eclipse.jgit.api.RmCommand)1 JGitInternalException (org.eclipse.jgit.api.errors.JGitInternalException)1