Skip to content

Commit

Permalink
Team: Git: fix gpg signer enable condition
Browse files Browse the repository at this point in the history
Signed-off-by: Hiroshi Miura <[email protected]>
  • Loading branch information
miurahr committed Sep 2, 2022
1 parent 2343eec commit 86e709f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
26 changes: 17 additions & 9 deletions src/org/omegat/core/team2/impl/GITExternalGpgSigner.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
with fuzzy matching, translation memory, keyword search,
glossaries, and translation leveraging into updated projects.
Copyright (C) 2021 Hiroshi Miura, Thomas Wolf and others.
Copyright (C) 2021-2022 Hiroshi Miura, Thomas Wolf and others.
This is ported from EGit (Apache-2.0)
Home page: http://www.omegat.org/
Support center: https://omegat.org/support
Expand Down Expand Up @@ -40,6 +40,7 @@ This is ported from EGit (Apache-2.0)
import org.eclipse.jgit.api.errors.CanceledException;
import org.eclipse.jgit.api.errors.JGitInternalException;
import org.eclipse.jgit.lib.CommitBuilder;
import org.eclipse.jgit.lib.Config;
import org.eclipse.jgit.lib.GpgConfig;
import org.eclipse.jgit.lib.GpgSignature;
import org.eclipse.jgit.lib.GpgSignatureVerifier;
Expand Down Expand Up @@ -177,23 +178,30 @@ private static String toString(final TemporaryBuffer b) {
* passphrase)
*/
@Override
public void sign(final CommitBuilder commit, final String gpgSigningKey, final PersonIdent committer,
public void sign(final CommitBuilder commit, final String gpgSigningKey,
final PersonIdent committer,
final CredentialsProvider credentialsProvider) throws CanceledException {
signObject(commit, gpgSigningKey, committer, null, null);
signObject(commit, gpgSigningKey, committer, credentialsProvider);
}

private void signObject(final ObjectBuilder object, final String gpgSigningKey,
final PersonIdent committer, final CredentialsProvider credentialsProvider,
final GpgConfig config) throws CanceledException {
final PersonIdent committer, final CredentialsProvider credentialsProvider)
throws CanceledException {
// Ignore the CredentialsProvider. We let GPG handle all this.
try {
String keySpec = gpgSigningKey;
if (StringUtils.isEmptyOrNull(gpgSigningKey)) {
if (StringUtils.isEmptyOrNull(keySpec)) {
// fallback
if (committer == null) {
throw new CanceledException("Cannot determine signature key");
}
keySpec = '<' + committer.getEmailAddress() + '>';
}
String program = config != null ? config.getProgram() : null;
object.setGpgSignature(new GpgSignature(
signWithGpg(object.build(), keySpec, program)));
// git config gpg.program
// Use this custom program instead of "gpg" found on $PATH when making or verifying a PGP signature.
GpgConfig config = new GpgConfig(new Config());
String program = config.getProgram();
object.setGpgSignature(new GpgSignature(signWithGpg(object.build(), keySpec, program)));
} catch (IOException e) {
throw new JGitInternalException(e.getMessage(), e);
}
Expand Down
6 changes: 4 additions & 2 deletions src/org/omegat/core/team2/impl/GITRemoteRepository2.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Copyright (C) 2012 Alex Buloichik
2014 Alex Buloichik, Aaron Madlon-Kay
2022 Hiroshi Miura
Home page: http://www.omegat.org/
Support center: https://omegat.org/support
Expand Down Expand Up @@ -76,6 +77,7 @@
import org.omegat.core.team2.IRemoteRepository2;
import org.omegat.core.team2.ProjectTeamSettings;
import org.omegat.util.Log;
import org.omegat.util.StringUtil;

import gen.core.project.RepositoryDefinition;

Expand Down Expand Up @@ -175,8 +177,8 @@ public void init(RepositoryDefinition repo, File dir, ProjectTeamSettings teamSe
Log.logInfoRB("GIT_FINISH", "clone");
}

String externalGpg = repository.getConfig().getString("user", null, "program");
if ("gpg".equalsIgnoreCase(externalGpg)) {
String signingkey = repository.getConfig().getString("user", null, "signingkey");
if (!StringUtil.isEmpty(signingkey)) {
GpgSigner.setDefault(new GITExternalGpgSigner());
}

Expand Down

0 comments on commit 86e709f

Please sign in to comment.