Skip to content

Commit 3a61db0

Browse files
committed
fix: use cached SelfExecPath to avoid '(deleted)' editor issue
eg : dotnet build with hot-reload "~/data/home/gits/sourcegit/src/bin/Debug/net10.0/SourceGit (deleted)" --rebase-todo-editor: 1: ~/gits/sourcegit/src/bin/Debug/net10.0/SourceGit (deleted): not found error: There was a problem with the editor '"~/gits/sourcegit/src/bin/Debug/net10.0/SourceGit (deleted)" --rebase-todo-editor'.
1 parent 1c7d855 commit 3a61db0

1 file changed

Lines changed: 25 additions & 4 deletions

File tree

src/Commands/Command.cs

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Diagnostics;
4+
using System.IO;
45
using System.Text;
56
using System.Text.RegularExpressions;
67
using 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

Comments
 (0)