List of usage examples for org.eclipse.jgit.api CommitCommand setCommitter
public CommitCommand setCommitter(PersonIdent committer)
From source file:com.google.gerrit.acceptance.git.GitUtil.java
License:Apache License
private static Commit createCommit(Git git, PersonIdent i, String msg, String changeId) throws GitAPIException, IOException { final CommitCommand commitCmd = git.commit(); commitCmd.setAmend(changeId != null); commitCmd.setAuthor(i);//from ww w . j a va 2 s. co m commitCmd.setCommitter(i); if (changeId == null) { ObjectId id = computeChangeId(git, i, msg); changeId = "I" + id.getName(); } msg = ChangeIdUtil.insertId(msg, ObjectId.fromString(changeId.substring(1))); commitCmd.setMessage(msg); RevCommit c = commitCmd.call(); return new Commit(c, changeId); }
From source file:com.google.gerrit.acceptance.git.ssh.GitUtil.java
License:Apache License
public static String createCommit(Git git, PersonIdent i, String msg, boolean insertChangeId) throws GitAPIException, IOException { ObjectId changeId = null;// w ww . j a va2 s.co m if (insertChangeId) { changeId = computeChangeId(git, i, msg); msg = ChangeIdUtil.insertId(msg, changeId); } final CommitCommand commitCmd = git.commit(); commitCmd.setAuthor(i); commitCmd.setCommitter(i); commitCmd.setMessage(msg); commitCmd.call(); return changeId != null ? "I" + changeId.getName() : null; }
From source file:net.polydawn.mdm.commands.MdmReleaseCommand.java
License:Open Source License
public MdmExitMessage call() throws IOException, MdmException, MdmExitMessage { MdmModuleRelease relModule = loadReleaseModule(); Repository relRepo = relModule.getRepo(); relModule.assertPresentsAsReleaseRepo(); assertReleaseRepoDoesntAlreadyContain(relModule, version); assertReleaseRepoClean(relModule);/*from ww w.j ava 2 s. c om*/ List<String> inputFiles = selectInputFiles(); // create a branch for the release commit. depending on whether or not infix mode is enabled, this is either branching from the infix branch, or it's founding a new root of history. boolean infixMode = relRepo.getRef("refs/heads/mdm/infix") != null; if (infixMode) try { new Git(relRepo).checkout().setCreateBranch(true).setStartPoint("mdm/infix") .setName("mdm/release/" + version).call(); } catch (RefAlreadyExistsException e) { return new MdmExitMessage(":'(", "the releases repo already has a release point labeled version " + version + " !"); } catch (RefNotFoundException e) { throw new MdmException("aborted due to concurrent modification of repo"); } catch (InvalidRefNameException e) { return new MdmExitMessage(":(", "you can't use version names that git rejects as branch names."); } catch (CheckoutConflictException e) { throw new MajorBug("an unrecognized problem occurred. please file a bug report.", e); } catch (GitAPIException e) { throw new MajorBug("an unrecognized problem occurred. please file a bug report.", e); } else { Plumbing.createOrphanBranch(relRepo, "mdm/release/" + version); try { new Git(relRepo).checkout().setName("mdm/release/" + version).call(); } catch (GitAPIException e) { throw new MajorBug("an unrecognized problem occurred. please file a bug report.", e); } } // enumerate and copy in artifact files. File inputBase = new File(inputPath).getCanonicalFile(); if (inputBase.isFile()) inputBase = inputBase.getParentFile(); File relRepoFile = new File(relRepoPath).getCanonicalFile(); for (String input : inputFiles) { File inputFull = new File(inputBase, input); File dest = new File(relRepoFile, input); if (inputFull.isDirectory()) FileUtils.copyDirectory(inputFull, dest, new FileFilter() { public boolean accept(File file) { return !(file.isDirectory() && file.listFiles().length == 0); } }, true, false); else FileUtils.copyFile(inputFull, dest, true, false); } // commit the changes try { new Git(relRepo).add().addFilepattern(".").call(); } catch (NoFilepatternException e) { throw new MajorBug(e); // why would an api throw exceptions like this *checked*? } catch (GitAPIException e) { throw new MajorBug("an unrecognized problem occurred. please file a bug report.", e); } try { CommitCommand commit = new Git(relRepo).commit().setMessage("release version " + version); if (!infixMode) { commit.setAmend(true); // because our mechanism for creating an orphan branch starts us with an empty commit. PersonIdent convergenceIdent = new PersonIdent("mdm", "", new Date(0), TimeZone.getTimeZone("GMT")); commit.setAuthor(convergenceIdent); commit.setCommitter(convergenceIdent); } commit.call(); // this tag will be removed in a future release, as it's no longer required for any structural purpose // (long long ago in a galaxy far away, this was used as an easy way for `mdm status` to report version names... but execing `git describe --tags` hasn't been the way we do this anymore for a long time now) new Git(relRepo).tag().setName("release/" + version).setAnnotated(false).call(); } catch (NoHeadException e) { throw new MdmException("your repository is in an invalid state!", e); } catch (ConcurrentRefUpdateException e) { throw new MdmException("aborted due to concurrent modification of repo"); } catch (NoMessageException e) { throw new MajorBug(e); // why would an api throw exceptions like this *checked*? } catch (UnmergedPathsException e) { throw new MajorBug("an unrecognized problem occurred. please file a bug report.", e); } catch (WrongRepositoryStateException e) { throw new MajorBug("an unrecognized problem occurred. please file a bug report.", e); } catch (GitAPIException e) { throw new MajorBug("an unrecognized problem occurred. please file a bug report.", e); } // generate an accumulation commit. do this from the master branch, but don't submit it yet, because when we roll in the artifacts we want them in a subdirectory so that when master is checked out all the versions are splayed out in the working tree at once. try { new Git(relRepo).checkout().setName("master").call(); } catch (RefAlreadyExistsException e) { throw new MajorBug(e); // not even valid unless we're creating a new branch, which we aren't. } catch (RefNotFoundException e) { throw new MajorBug("an unrecognized problem occurred. please file a bug report.", e); } catch (InvalidRefNameException e) { throw new MajorBug("an unrecognized problem occurred. please file a bug report.", e); } catch (CheckoutConflictException e) { throw new MajorBug("an unrecognized problem occurred. please file a bug report.", e); } catch (GitAPIException e) { throw new MajorBug("an unrecognized problem occurred. please file a bug report.", e); } try { new Git(relRepo).merge().include(relRepo.getRef("mdm/release/" + version)) .setFastForward(FastForwardMode.NO_FF).setCommit(false).call(); } catch (NoHeadException e) { throw new MdmException("your repository is in an invalid state!", e); } catch (ConcurrentRefUpdateException e) { throw new MdmException("aborted due to concurrent modification of repo"); } catch (CheckoutConflictException e) { throw new MajorBug("an unrecognized problem occurred. please file a bug report.", e); } catch (InvalidMergeHeadsException e) { throw new MajorBug("an unrecognized problem occurred. please file a bug report.", e); } catch (WrongRepositoryStateException e) { throw new MajorBug("an unrecognized problem occurred. please file a bug report.", e); } catch (NoMessageException e) { throw new MajorBug(e); // why would an api throw exceptions like this *checked*? also, we're not even making a commit here. } catch (GitAPIException e) { throw new MajorBug("an unrecognized problem occurred. please file a bug report.", e); } // move the artifact files into a version-named directory File artifactDestFile = new File(relRepoFile, version); if (!artifactDestFile.mkdir()) return new MdmExitMessage(":'(", "couldn't make the directory named \"" + version + "\" to put the releases into because there was already something there."); for (String input : inputFiles) new File(relRepoFile, input).renameTo(new File(artifactDestFile, input)); // now fire off the accumulation commit, and that commit now becomes head of the master branch. try { RmCommand rmc = new Git(relRepo).rm(); for (String input : inputFiles) rmc.addFilepattern(input); rmc.call(); new Git(relRepo).add().addFilepattern(version).call(); } catch (NoFilepatternException e) { throw new MajorBug(e); // why would an api throw exceptions like this *checked*? } catch (GitAPIException e) { throw new MajorBug("an unrecognized problem occurred. please file a bug report.", e); } try { new Git(relRepo).commit().setMessage("merge release version " + version + " to master").call(); new Git(relRepo).tag().setName("mdm/master/" + version).setAnnotated(false).call(); } catch (NoHeadException e) { throw new MdmException("your repository is in an invalid state!", e); } catch (ConcurrentRefUpdateException e) { throw new MdmException("aborted due to concurrent modification of repo"); } catch (NoMessageException e) { throw new MajorBug(e); // why would an api throw exceptions like this *checked*? } catch (UnmergedPathsException e) { throw new MajorBug("an unrecognized problem occurred. please file a bug report.", e); } catch (WrongRepositoryStateException e) { throw new MajorBug("an unrecognized problem occurred. please file a bug report.", e); } catch (GitAPIException e) { throw new MajorBug("an unrecognized problem occurred. please file a bug report.", e); } // commit the new hash of the releases-repo into the project main repo (if we are operating in a canonically placed releases submodule) if (isInRepoRoot() && relRepoPath.equals("releases") && Plumbing.isCommitedGitlink(repo, "releases")) { try { new Git(repo).commit().setOnly("releases").setMessage("release version " + version).call(); new Git(repo).tag().setName("release/" + version).setAnnotated(false).call(); } catch (NoHeadException e) { throw new MdmException("your repository is in an invalid state!", e); } catch (ConcurrentRefUpdateException e) { throw new MdmException("aborted due to concurrent modification of repo"); } catch (NoMessageException e) { throw new MajorBug(e); // why would an api throw exceptions like this *checked*? } catch (UnmergedPathsException e) { throw new MajorBug("an unrecognized problem occurred. please file a bug report.", e); } catch (WrongRepositoryStateException e) { throw new MajorBug("an unrecognized problem occurred. please file a bug report.", e); } catch (GitAPIException e) { throw new MajorBug("an unrecognized problem occurred. please file a bug report.", e); } } return new MdmExitMessage(":D", "release version " + version + " complete"); }
From source file:org.ajoberstar.gradle.git.tasks.GitCommit.java
License:Apache License
/** * Commits changes to the Git repository. *//*from w w w .ja va 2 s . co m*/ @TaskAction public void commit() { final CommitCommand cmd = getGit().commit(); cmd.setMessage(getMessage()); cmd.setAll(getCommitAll()); if (committer != null) { cmd.setCommitter(getCommitter()); } if (author != null) { cmd.setAuthor(getAuthor()); } if (!patternSet.getExcludes().isEmpty() || !patternSet.getIncludes().isEmpty()) { getSource().visit(new FileVisitor() { public void visitDir(FileVisitDetails arg0) { visitFile(arg0); } public void visitFile(FileVisitDetails arg0) { cmd.setOnly(arg0.getPath()); } }); } try { cmd.call(); } catch (Exception e) { throw new GradleException("Problem committing changes.", e); } }
From source file:org.eclipse.egit.core.test.TestRepository.java
License:Open Source License
/** * Commits the current index// w w w . j a va 2 s.co m * * @param message * commit message * @return commit object * * @throws NoHeadException * @throws NoMessageException * @throws UnmergedPathException * @throws ConcurrentRefUpdateException * @throws JGitInternalException * @throws WrongRepositoryStateException */ public RevCommit commit(String message) throws NoHeadException, NoMessageException, UnmergedPathException, ConcurrentRefUpdateException, JGitInternalException, WrongRepositoryStateException { Git git = new Git(repository); CommitCommand commitCommand = git.commit(); commitCommand.setAuthor("J. Git", "j.git@egit.org"); commitCommand.setCommitter(commitCommand.getAuthor()); commitCommand.setMessage(message); return commitCommand.call(); }
From source file:org.eclipse.emf.compare.diagram.papyrus.tests.egit.fixture.GitTestRepository.java
License:Open Source License
/** * Commits the current index.//from w w w . j a v a 2 s . co m * * @param message * commit message * @return commit object */ public RevCommit commit(String message) throws Exception { Git git = new Git(repository); try { CommitCommand commitCommand = git.commit(); commitCommand.setAuthor("J. Git", "j.git@egit.org"); commitCommand.setCommitter(commitCommand.getAuthor()); commitCommand.setMessage(message); return commitCommand.call(); } finally { git.close(); } }
From source file:org.flowerplatform.web.git.operation.CommitOperation.java
License:Open Source License
public boolean commit(String repositoryLocation, List<CommitResourceDto> files, String author, String committer, String message, boolean amending) { ProgressMonitor monitor = ProgressMonitor .create(GitPlugin.getInstance().getMessage("git.commit.monitor.title"), channel); try {//w w w. j av a2s . co m Repository repo = GitPlugin.getInstance().getUtils().getRepository(new File(repositoryLocation)); Collection<String> notTracked = new HashSet<String>(); Collection<String> resources = new HashSet<String>(); for (CommitResourceDto file : files) { resources.add(file.getPath()); if (file.getState() == CommitResourceDto.UNTRACKED) { notTracked.add(file.getPath()); } } monitor.beginTask(GitPlugin.getInstance().getMessage("git.commit.monitor.message"), 10); addUntracked(notTracked, repo); monitor.worked(1); CommitCommand commitCommand = new Git(repo).commit(); commitCommand.setAmend(amending).setMessage(message); for (String path : resources) { commitCommand.setOnly(path); } Date commitDate = new Date(); TimeZone timeZone = TimeZone.getDefault(); PersonIdent enteredAuthor = RawParseUtils.parsePersonIdent(author); PersonIdent enteredCommitter = RawParseUtils.parsePersonIdent(committer); if (enteredAuthor == null) { channel.appendOrSendCommand(new DisplaySimpleMessageClientCommand( CommonPlugin.getInstance().getMessage("error"), GitPlugin.getInstance() .getMessage("git.commit.errorParsingPersonIdent", new Object[] { author }), DisplaySimpleMessageClientCommand.ICON_ERROR)); return false; } if (enteredCommitter == null) { channel.appendOrSendCommand(new DisplaySimpleMessageClientCommand( CommonPlugin.getInstance().getMessage("error"), GitPlugin.getInstance() .getMessage("git.commit.errorParsingPersonIdent", new Object[] { committer }), DisplaySimpleMessageClientCommand.ICON_ERROR)); return false; } PersonIdent authorIdent = new PersonIdent(enteredAuthor, commitDate, timeZone); PersonIdent committerIdent = new PersonIdent(enteredCommitter, commitDate, timeZone); if (amending) { RevCommit headCommit = GitPlugin.getInstance().getUtils().getHeadCommit(repo); if (headCommit != null) { PersonIdent headAuthor = headCommit.getAuthorIdent(); authorIdent = new PersonIdent(enteredAuthor, headAuthor.getWhen(), headAuthor.getTimeZone()); } } commitCommand.setAuthor(authorIdent); commitCommand.setCommitter(committerIdent); monitor.worked(1); commitCommand.call(); if (monitor.isCanceled()) { return false; } monitor.worked(8); // GitLightweightDecorator.refresh(); // // updateDispatcher.dispatchContentUpdate(null, repo, GitTreeUpdateDispatcher.COMMIT, null); return true; } catch (Exception e) { logger.debug(GitPlugin.getInstance().getMessage("git.commit.error"), e); channel.appendOrSendCommand( new DisplaySimpleMessageClientCommand(CommonPlugin.getInstance().getMessage("error"), e.getMessage(), DisplaySimpleMessageClientCommand.ICON_ERROR)); return false; } finally { monitor.done(); } }
From source file:org.jboss.arquillian.container.openshift.express.util.GitUtil.java
License:Apache License
/** * Commits changes to a local repository * * @param identification The person identification * @param message the commit message//ww w . ja v a 2s . com */ public void commit(PersonIdent identification, String message) { CommitCommand commit = git.commit(); commit.setAuthor(identification); commit.setCommitter(identification); commit.setMessage(message); try { commit.call(); } catch (NoHeadException e) { throw new IllegalStateException("Unable to commit into Git repository", e); } catch (NoMessageException e) { throw new IllegalStateException("Unable to commit into Git repository", e); } catch (UnmergedPathException e) { throw new IllegalStateException("Unable to commit into Git repository", e); } catch (ConcurrentRefUpdateException e) { throw new IllegalStateException("Unable to commit into Git repository", e); } catch (JGitInternalException e) { throw new IllegalStateException("Unable to commit into Git repository", e); } catch (WrongRepositoryStateException e) { throw new IllegalStateException("Unable to commit into Git repository", e); } }
From source file:org.jboss.arquillian.container.openshift.util.GitUtil.java
License:Apache License
/** * Commits changes to a local repository * * @param identification The person identification * @param message the commit message/*from ww w. j a va2s . c om*/ */ public void commit(PersonIdent identification, String message) { CommitCommand commit = git.commit(); commit.setAuthor(identification); commit.setCommitter(identification); commit.setMessage(message); try { commit.call(); } catch (NoHeadException e) { throw new IllegalStateException("Unable to commit into Git repository", e); } catch (NoMessageException e) { throw new IllegalStateException("Unable to commit into Git repository", e); } catch (ConcurrentRefUpdateException e) { throw new IllegalStateException("Unable to commit into Git repository", e); } catch (JGitInternalException e) { throw new IllegalStateException("Unable to commit into Git repository", e); } catch (WrongRepositoryStateException e) { throw new IllegalStateException("Unable to commit into Git repository", e); } catch (UnmergedPathsException e) { throw new IllegalStateException("Unable to commit into Git repository", e); } catch (GitAPIException e) { throw new IllegalStateException("Unable to commit into Git repository", e); } }
From source file:org.jboss.tools.openshift.egit.internal.test.util.TestRepository.java
License:Open Source License
/** * Commits the current index/* w w w . j av a 2 s . c om*/ * * @param message * commit message * @return commit object * * @throws UnmergedPathException * @throws JGitInternalException * @throws GitAPIException * @throws UnmergedPathsException */ public RevCommit commit(String message) throws UnmergedPathException, JGitInternalException, UnmergedPathsException, GitAPIException { Git git = new Git(repository); CommitCommand commitCommand = git.commit(); commitCommand.setAuthor("J. Git", "j.git@egit.org"); commitCommand.setCommitter(commitCommand.getAuthor()); commitCommand.setMessage(message); return commitCommand.call(); }