@@ -95,7 +95,7 @@ public CommandContext(string appPath)
95
95
SystemPrompts = new WindowsSystemPrompts ( ) ;
96
96
Environment = new WindowsEnvironment ( FileSystem ) ;
97
97
Terminal = new WindowsTerminal ( Trace ) ;
98
- string gitPath = GetGitPath ( Environment , FileSystem ) ;
98
+ string gitPath = GetGitPath ( Environment , FileSystem , Trace ) ;
99
99
Git = new GitProcess (
100
100
Trace ,
101
101
gitPath ,
@@ -111,14 +111,15 @@ public CommandContext(string appPath)
111
111
SystemPrompts = new MacOSSystemPrompts ( ) ;
112
112
Environment = new PosixEnvironment ( FileSystem ) ;
113
113
Terminal = new PosixTerminal ( Trace ) ;
114
- string gitPath = GetGitPath ( Environment , FileSystem ) ;
114
+ string gitPath = GetGitPath ( Environment , FileSystem , Trace ) ;
115
115
Git = new GitProcess (
116
116
Trace ,
117
117
gitPath ,
118
118
FileSystem . GetCurrentDirectory ( )
119
119
) ;
120
120
Settings = new Settings ( Environment , Git ) ;
121
121
CredentialStore = new MacOSKeychain ( Settings . CredentialNamespace ) ;
122
+
122
123
}
123
124
else if ( PlatformUtils . IsLinux ( ) )
124
125
{
@@ -128,17 +129,16 @@ public CommandContext(string appPath)
128
129
SystemPrompts = new LinuxSystemPrompts ( ) ;
129
130
Environment = new PosixEnvironment ( FileSystem ) ;
130
131
Terminal = new PosixTerminal ( Trace ) ;
131
- string gitPath = GetGitPath ( Environment , FileSystem ) ;
132
+ string gitPath = GetGitPath ( Environment , FileSystem , Trace ) ;
132
133
Git = new GitProcess (
133
134
Trace ,
134
135
gitPath ,
135
136
FileSystem . GetCurrentDirectory ( )
136
137
) ;
137
138
Settings = new Settings ( Environment , Git ) ;
138
- IGpg gpg = new Gpg (
139
- Environment . LocateExecutable ( "gpg" ) ,
140
- SessionManager
141
- ) ;
139
+
140
+ string gpgPath = GetGpgPath ( Environment , FileSystem , Trace ) ;
141
+ IGpg gpg = new Gpg ( gpgPath , SessionManager ) ;
142
142
CredentialStore = new LinuxCredentialStore ( FileSystem , Settings , SessionManager , gpg , Environment , Git ) ;
143
143
}
144
144
else
@@ -152,23 +152,62 @@ public CommandContext(string appPath)
152
152
SystemPrompts . ParentWindowId = Settings . ParentWindowId ;
153
153
}
154
154
155
- private static string GetGitPath ( IEnvironment environment , IFileSystem fileSystem )
155
+ private static string GetGitPath ( IEnvironment environment , IFileSystem fileSystem , ITrace trace )
156
156
{
157
+ string gitExecPath ;
157
158
string programName = PlatformUtils . IsWindows ( ) ? "git.exe" : "git" ;
158
159
159
160
// Use the GIT_EXEC_PATH environment variable if set
160
161
if ( environment . Variables . TryGetValue ( Constants . EnvironmentVariables . GitExecutablePath ,
161
- out string gitExecPath ) )
162
+ out gitExecPath ) )
162
163
{
163
164
string candidatePath = Path . Combine ( gitExecPath , programName ) ;
164
165
if ( fileSystem . FileExists ( candidatePath ) )
165
166
{
167
+ trace . WriteLine ( $ "Using Git executable from GIT_EXEC_PATH: { candidatePath } ") ;
166
168
return candidatePath ;
167
169
}
168
170
}
169
171
170
172
// Otherwise try to locate the git(.exe) on the current PATH
171
- return environment . LocateExecutable ( programName ) ;
173
+ gitExecPath = environment . LocateExecutable ( programName ) ;
174
+ trace . WriteLine ( $ "Using PATH-located Git executable: { gitExecPath } ") ;
175
+ return gitExecPath ;
176
+ }
177
+
178
+ private static string GetGpgPath ( IEnvironment environment , IFileSystem fileSystem , ITrace trace )
179
+ {
180
+ string gpgPath ;
181
+
182
+ // Use the GCM_GPG_PATH environment variable if set
183
+ if ( environment . Variables . TryGetValue ( Constants . EnvironmentVariables . GpgExecutablePath ,
184
+ out gpgPath ) )
185
+ {
186
+ if ( fileSystem . FileExists ( gpgPath ) )
187
+ {
188
+ trace . WriteLine ( $ "Using Git executable from GCM_GPG_PATH: { gpgPath } ") ;
189
+ return gpgPath ;
190
+ }
191
+ else
192
+ {
193
+ throw new Exception ( $ "GPG executable does not exist with path '{ gpgPath } '") ;
194
+ }
195
+
196
+ }
197
+
198
+ // If no explicit GPG path is specified, mimic the way `pass`
199
+ // determines GPG dependency (use gpg2 if available, otherwise gpg)
200
+ if ( environment . TryLocateExecutable ( "gpg2" , out string gpg2Path ) )
201
+ {
202
+ trace . WriteLine ( $ "Using PATH-located GPG (gpg2) executable: { gpg2Path } ") ;
203
+ return gpg2Path ;
204
+ }
205
+ else
206
+ {
207
+ gpgPath = environment . LocateExecutable ( "gpg" ) ;
208
+ trace . WriteLine ( $ "Using PATH-located GPG (gpg) executable: { gpgPath } ") ;
209
+ return gpgPath ;
210
+ }
172
211
}
173
212
174
213
#region ICommandContext
0 commit comments