@@ -95,7 +95,7 @@ public CommandContext(string appPath)
9595 SystemPrompts = new WindowsSystemPrompts ( ) ;
9696 Environment = new WindowsEnvironment ( FileSystem ) ;
9797 Terminal = new WindowsTerminal ( Trace ) ;
98- string gitPath = GetGitPath ( Environment , FileSystem ) ;
98+ string gitPath = GetGitPath ( Environment , FileSystem , Trace ) ;
9999 Git = new GitProcess (
100100 Trace ,
101101 gitPath ,
@@ -111,14 +111,15 @@ public CommandContext(string appPath)
111111 SystemPrompts = new MacOSSystemPrompts ( ) ;
112112 Environment = new PosixEnvironment ( FileSystem ) ;
113113 Terminal = new PosixTerminal ( Trace ) ;
114- string gitPath = GetGitPath ( Environment , FileSystem ) ;
114+ string gitPath = GetGitPath ( Environment , FileSystem , Trace ) ;
115115 Git = new GitProcess (
116116 Trace ,
117117 gitPath ,
118118 FileSystem . GetCurrentDirectory ( )
119119 ) ;
120120 Settings = new Settings ( Environment , Git ) ;
121121 CredentialStore = new MacOSKeychain ( Settings . CredentialNamespace ) ;
122+
122123 }
123124 else if ( PlatformUtils . IsLinux ( ) )
124125 {
@@ -128,17 +129,16 @@ public CommandContext(string appPath)
128129 SystemPrompts = new LinuxSystemPrompts ( ) ;
129130 Environment = new PosixEnvironment ( FileSystem ) ;
130131 Terminal = new PosixTerminal ( Trace ) ;
131- string gitPath = GetGitPath ( Environment , FileSystem ) ;
132+ string gitPath = GetGitPath ( Environment , FileSystem , Trace ) ;
132133 Git = new GitProcess (
133134 Trace ,
134135 gitPath ,
135136 FileSystem . GetCurrentDirectory ( )
136137 ) ;
137138 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 ) ;
142142 CredentialStore = new LinuxCredentialStore ( FileSystem , Settings , SessionManager , gpg , Environment , Git ) ;
143143 }
144144 else
@@ -152,23 +152,62 @@ public CommandContext(string appPath)
152152 SystemPrompts . ParentWindowId = Settings . ParentWindowId ;
153153 }
154154
155- private static string GetGitPath ( IEnvironment environment , IFileSystem fileSystem )
155+ private static string GetGitPath ( IEnvironment environment , IFileSystem fileSystem , ITrace trace )
156156 {
157+ string gitExecPath ;
157158 string programName = PlatformUtils . IsWindows ( ) ? "git.exe" : "git" ;
158159
159160 // Use the GIT_EXEC_PATH environment variable if set
160161 if ( environment . Variables . TryGetValue ( Constants . EnvironmentVariables . GitExecutablePath ,
161- out string gitExecPath ) )
162+ out gitExecPath ) )
162163 {
163164 string candidatePath = Path . Combine ( gitExecPath , programName ) ;
164165 if ( fileSystem . FileExists ( candidatePath ) )
165166 {
167+ trace . WriteLine ( $ "Using Git executable from GIT_EXEC_PATH: { candidatePath } ") ;
166168 return candidatePath ;
167169 }
168170 }
169171
170172 // 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+ }
172211 }
173212
174213 #region ICommandContext
0 commit comments