11using System ;
22using System . Collections . Generic ;
33using System . Diagnostics ;
4+ using System . IO ;
45using System . Text ;
56using System . Text . RegularExpressions ;
67using System . Threading ;
@@ -10,6 +11,24 @@ namespace SourceGit.Commands
1011{
1112 public partial class Command
1213 {
14+ /// <summary>
15+ /// Cached path to the current process executable.
16+ /// Uses Environment.ProcessPath (instead of MainModule.FileName) to avoid
17+ /// the "(deleted)" suffix issue when the binary is overwritten during
18+ /// development (e.g., dotnet build with hot-reload).
19+ /// </summary>
20+ internal static readonly string SelfExecPath = ResolveSelfExecPath ( ) ;
21+
22+ private static string ResolveSelfExecPath ( )
23+ {
24+ var path = Environment . ProcessPath ;
25+ if ( ! string . IsNullOrEmpty ( path ) && File . Exists ( path ) )
26+ return path ;
27+
28+ // fallback to old method
29+ return Process . GetCurrentProcess ( ) . MainModule ! . FileName ;
30+ }
31+
1332 public class Result
1433 {
1534 public bool IsSuccess { get ; set ; } = false ;
@@ -172,8 +191,10 @@ protected ProcessStartInfo CreateGitStartInfo(bool redirect)
172191 }
173192
174193 // Force using this app as SSH askpass program
175- var selfExecFile = Process . GetCurrentProcess ( ) . MainModule ! . FileName ;
176- start . Environment . Add ( "SSH_ASKPASS" , selfExecFile ) ; // Can not use parameter here, because it invoked by SSH with `exec`
194+ // Uses cached SelfExecPath (resolved once at startup via Environment.ProcessPath)
195+ // instead of Process.GetCurrentProcess().MainModule.FileName to avoid
196+ // the "(deleted)" suffix when the binary is overwritten during development.
197+ start . Environment . Add ( "SSH_ASKPASS" , SelfExecPath ) ; // Can not use parameter here, because it invoked by SSH with `exec`
177198 start . Environment . Add ( "SSH_ASKPASS_REQUIRE" , "prefer" ) ;
178199 start . Environment . Add ( "SOURCEGIT_LAUNCH_AS_ASKPASS" , "TRUE" ) ;
179200 if ( ! OperatingSystem . IsLinux ( ) )
@@ -199,10 +220,10 @@ protected ProcessStartInfo CreateGitStartInfo(bool redirect)
199220 switch ( Editor )
200221 {
201222 case EditorType . CoreEditor :
202- builder . Append ( $ """ -c core.editor="\"{ selfExecFile } \" --core-editor" """ ) ;
223+ builder . Append ( $ """ -c core.editor="\"{ SelfExecPath } \" --core-editor" """ ) ;
203224 break ;
204225 case EditorType . RebaseEditor :
205- builder . Append ( $ """ -c core.editor="\"{ selfExecFile } \" --rebase-message-editor" -c sequence.editor="\"{ selfExecFile } \" --rebase-todo-editor" -c rebase.abbreviateCommands=true """ ) ;
226+ builder . Append ( $ """ -c core.editor="\"{ SelfExecPath } \" --rebase-message-editor" -c sequence.editor="\"{ SelfExecPath } \" --rebase-todo-editor" -c rebase.abbreviateCommands=true """ ) ;
206227 break ;
207228 default :
208229 builder . Append ( "-c core.editor=true " ) ;
0 commit comments