Skip to content

Commit 101b738

Browse files
committed
Read gpg program from git config gpg.program ; ported from fork by alanrossmachinery
Modified-By: Andrew Ayer <agwa@andrewayer.name> * Make whitespace conform to project conventions Closes AGWA#89 Closes AGWA#65
1 parent 934914c commit 101b738

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

commands.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ static std::string get_internal_key_path (const char* key_name)
254254
return path;
255255
}
256256

257-
static std::string get_git_config (const std::string& name)
257+
std::string get_git_config (const std::string& name)
258258
{
259259
// git config --get
260260
std::vector<std::string> command;

commands.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,7 @@ void help_migrate_key (std::ostream&);
7070
void help_refresh (std::ostream&);
7171
void help_status (std::ostream&);
7272

73+
// other
74+
std::string get_git_config (const std::string& name);
75+
7376
#endif

gpg.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,18 @@
3030

3131
#include "gpg.hpp"
3232
#include "util.hpp"
33+
#include "commands.hpp"
3334
#include <sstream>
3435

36+
static std::string gpg_get_executable()
37+
{
38+
std::string gpgbin = "gpg";
39+
try {
40+
gpgbin = get_git_config("gpg.program");
41+
} catch (...) {
42+
}
43+
return gpgbin;
44+
}
3545
static std::string gpg_nth_column (const std::string& line, unsigned int col)
3646
{
3747
std::string::size_type pos = 0;
@@ -62,7 +72,7 @@ std::string gpg_get_uid (const std::string& fingerprint)
6272
{
6373
// gpg --batch --with-colons --fixed-list-mode --list-keys 0x7A399B2DB06D039020CD1CE1D0F3702D61489532
6474
std::vector<std::string> command;
65-
command.push_back("gpg");
75+
command.push_back(gpg_get_executable());
6676
command.push_back("--batch");
6777
command.push_back("--with-colons");
6878
command.push_back("--fixed-list-mode");
@@ -94,7 +104,7 @@ std::vector<std::string> gpg_lookup_key (const std::string& query)
94104

95105
// gpg --batch --with-colons --fingerprint --list-keys jsmith@example.com
96106
std::vector<std::string> command;
97-
command.push_back("gpg");
107+
command.push_back(gpg_get_executable());
98108
command.push_back("--batch");
99109
command.push_back("--with-colons");
100110
command.push_back("--fingerprint");
@@ -125,7 +135,7 @@ std::vector<std::string> gpg_list_secret_keys ()
125135
{
126136
// gpg --batch --with-colons --list-secret-keys --fingerprint
127137
std::vector<std::string> command;
128-
command.push_back("gpg");
138+
command.push_back(gpg_get_executable());
129139
command.push_back("--batch");
130140
command.push_back("--with-colons");
131141
command.push_back("--list-secret-keys");
@@ -154,7 +164,7 @@ void gpg_encrypt_to_file (const std::string& filename, const std::string& recipi
154164
{
155165
// gpg --batch -o FILENAME -r RECIPIENT -e
156166
std::vector<std::string> command;
157-
command.push_back("gpg");
167+
command.push_back(gpg_get_executable());
158168
command.push_back("--batch");
159169
if (key_is_trusted) {
160170
command.push_back("--trust-model");
@@ -174,7 +184,7 @@ void gpg_decrypt_from_file (const std::string& filename, std::ostream& output)
174184
{
175185
// gpg -q -d FILENAME
176186
std::vector<std::string> command;
177-
command.push_back("gpg");
187+
command.push_back(gpg_get_executable());
178188
command.push_back("-q");
179189
command.push_back("-d");
180190
command.push_back(filename);

0 commit comments

Comments
 (0)