use of org.eclipse.jgit.api.CommitCommand 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;
}
use of org.eclipse.jgit.api.CommitCommand in project MGit by maks.
the class CommitChangesTask method commit.
public static void commit(Repo repo, boolean stageAll, boolean isAmend, String msg, String authorName, String authorEmail) throws Exception, NoHeadException, NoMessageException, UnmergedPathsException, ConcurrentRefUpdateException, WrongRepositoryStateException, GitAPIException, StopTaskException {
Context context = SGitApplication.getContext();
StoredConfig config = repo.getGit().getRepository().getConfig();
String committerEmail = config.getString("user", null, "email");
String committerName = config.getString("user", null, "name");
if (committerName == null || committerName.equals("")) {
committerName = Profile.getUsername(context);
}
if (committerEmail == null || committerEmail.equals("")) {
committerEmail = Profile.getEmail(context);
}
if (committerName.isEmpty() || committerEmail.isEmpty()) {
throw new Exception("Please set your name and email");
}
if (msg.isEmpty()) {
throw new Exception("Please include a commit message");
}
CommitCommand cc = repo.getGit().commit().setCommitter(committerName, committerEmail).setAll(stageAll).setAmend(isAmend).setMessage(msg);
if (authorName != null && authorEmail != null) {
cc.setAuthor(authorName, authorEmail);
}
cc.call();
repo.updateLatestCommitInfo();
}
use of org.eclipse.jgit.api.CommitCommand in project archi-modelrepository-plugin by archi-contribs.
the class ArchiRepository method commitChanges.
@Override
public RevCommit commitChanges(String commitMessage, boolean amend) throws GitAPIException, IOException {
try (Git git = Git.open(getLocalRepositoryFolder())) {
Status status = git.status().call();
// Nothing changed
if (status.isClean()) {
return null;
}
// Add modified files to index
AddCommand addCommand = git.add();
// $NON-NLS-1$
addCommand.addFilepattern(".");
addCommand.setUpdate(false);
addCommand.call();
// Add missing files to index
for (String s : status.getMissing()) {
git.rm().addFilepattern(s).call();
}
// Commit
CommitCommand commitCommand = git.commit();
PersonIdent userDetails = getUserDetails();
commitCommand.setAuthor(userDetails);
commitCommand.setMessage(commitMessage);
commitCommand.setAmend(amend);
return commitCommand.call();
}
}
use of org.eclipse.jgit.api.CommitCommand in project archi-modelrepository-plugin by archi-contribs.
the class MergeConflictHandler method mergeAndCommit.
public void mergeAndCommit(String commitMessage, boolean amend) throws IOException, GitAPIException {
merge();
try (Git git = Git.open(fArchiRepo.getLocalRepositoryFolder())) {
// Add to index all files
AddCommand addCommand = git.add();
// $NON-NLS-1$
addCommand.addFilepattern(".");
addCommand.setUpdate(false);
addCommand.call();
// Commit
CommitCommand commitCommand = git.commit();
PersonIdent userDetails = fArchiRepo.getUserDetails();
commitCommand.setAuthor(userDetails);
commitCommand.setMessage(commitMessage);
commitCommand.setAmend(amend);
commitCommand.call();
}
}
use of org.eclipse.jgit.api.CommitCommand in project egit by eclipse.
the class CommitOperation method commit.
private void commit() throws TeamException {
try (Git git = new Git(repo)) {
CommitCommand commitCommand = git.commit();
setAuthorAndCommitter(commitCommand);
commitCommand.setAmend(amending).setMessage(message).setInsertChangeId(createChangeId);
if (!commitIndex)
for (String path : commitFileList) commitCommand.setOnly(path);
commit = commitCommand.call();
} catch (Exception e) {
throw new TeamException(CoreText.MergeOperation_InternalError, e);
}
}
Aggregations