diff options
Diffstat (limited to 'org.eclipse.egit.core/src/org/eclipse/egit/core/op/CommitOperation.java')
-rw-r--r-- | org.eclipse.egit.core/src/org/eclipse/egit/core/op/CommitOperation.java | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/op/CommitOperation.java b/org.eclipse.egit.core/src/org/eclipse/egit/core/op/CommitOperation.java index 61483a8b84..661ad8c6f3 100644 --- a/org.eclipse.egit.core/src/org/eclipse/egit/core/op/CommitOperation.java +++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/op/CommitOperation.java @@ -18,6 +18,7 @@ package org.eclipse.egit.core.op; import static java.lang.Boolean.FALSE; import static java.lang.Boolean.TRUE; +import java.io.File; import java.io.IOException; import java.util.Arrays; import java.util.Collection; @@ -38,12 +39,15 @@ import org.eclipse.egit.core.Activator; import org.eclipse.egit.core.RepositoryUtil; import org.eclipse.egit.core.internal.CoreText; import org.eclipse.egit.core.internal.job.RuleUtil; +import org.eclipse.egit.core.internal.signing.GpgConfigurationException; import org.eclipse.egit.core.project.RepositoryMapping; +import org.eclipse.egit.core.settings.GitSettings; import org.eclipse.jgit.api.AddCommand; import org.eclipse.jgit.api.CommitCommand; import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.api.errors.JGitInternalException; +import org.eclipse.jgit.lib.GpgConfig; import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.PersonIdent; import org.eclipse.jgit.lib.Repository; @@ -253,6 +257,8 @@ public class CommitOperation implements IEGitOperation { for(String path:commitFileList) commitCommand.setOnly(path); commit = commitCommand.call(); + } catch (GpgConfigurationException e) { + throw new TeamException(e.getLocalizedMessage(), e); } catch (Exception e) { throw new TeamException( CoreText.MergeOperation_InternalError, e); @@ -346,8 +352,8 @@ public class CommitOperation implements IEGitOperation { final PersonIdent committerIdent = new PersonIdent(enteredCommitter, commitDate, timeZone); if (amending) { - RepositoryUtil repoUtil = Activator.getDefault().getRepositoryUtil(); - RevCommit headCommit = repoUtil.parseHeadCommit(repo); + RevCommit headCommit = RepositoryUtil.INSTANCE + .parseHeadCommit(repo); if (headCommit != null) { final PersonIdent headAuthor = headCommit.getAuthorIdent(); authorIdent = new PersonIdent(enteredAuthor, @@ -358,5 +364,19 @@ public class CommitOperation implements IEGitOperation { commitCommand.setAuthor(authorIdent); commitCommand.setCommitter(committerIdent); commitCommand.setSign(sign ? TRUE : FALSE); + if (sign) { + // Ensure the Eclipse preference, if set, overrides the git config + File gpg = GitSettings.getGpgExecutable(); + if (gpg != null) { + GpgConfig cfg = new GpgConfig(repo.getConfig()) { + + @Override + public String getProgram() { + return gpg.getAbsolutePath(); + } + }; + commitCommand.setGpgConfig(cfg); + } + } } } |