From 5dea46e7fbf9004be65b75d3bc68142f4a990006 Mon Sep 17 00:00:00 2001 From: Gadfly Date: Tue, 13 Jan 2026 19:47:29 +0800 Subject: [PATCH] fix: Use correct null device path on Windows --- src/Commands/Command.cs | 2 +- src/Models/DiffOption.cs | 2 +- src/Models/DiffResult.cs | 2 +- src/Native/OS.cs | 8 ++++++++ src/ViewModels/DiffContext.cs | 4 ++-- 5 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/Commands/Command.cs b/src/Commands/Command.cs index e6e64f054..231aa4131 100644 --- a/src/Commands/Command.cs +++ b/src/Commands/Command.cs @@ -181,7 +181,7 @@ protected ProcessStartInfo CreateGitStartInfo(bool redirect) // If an SSH private key was provided, sets the environment. if (!start.Environment.ContainsKey("GIT_SSH_COMMAND") && !string.IsNullOrEmpty(SSHKey)) - start.Environment.Add("GIT_SSH_COMMAND", $"ssh -i '{SSHKey}' -F '/dev/null'"); + start.Environment.Add("GIT_SSH_COMMAND", $"ssh -i '{SSHKey}' -F '{Native.OS.NullDevice}'"); // Force using en_US.UTF-8 locale if (OperatingSystem.IsLinux()) diff --git a/src/Models/DiffOption.cs b/src/Models/DiffOption.cs index 2ecfe458f..b9606153a 100644 --- a/src/Models/DiffOption.cs +++ b/src/Models/DiffOption.cs @@ -39,7 +39,7 @@ public DiffOption(Change change, bool isUnstaged) case ChangeState.Added: case ChangeState.Untracked: _extra = "--no-index"; - _orgPath = "/dev/null"; + _orgPath = Native.OS.NullDevice; break; } } diff --git a/src/Models/DiffResult.cs b/src/Models/DiffResult.cs index 6c381df35..7a91a123a 100644 --- a/src/Models/DiffResult.cs +++ b/src/Models/DiffResult.cs @@ -106,7 +106,7 @@ public void GenerateNewPatchFromSelection(Change change, string fileBlobGuid, Te if (!revert && !isTracked) writer.WriteLine("new file mode 100644"); writer.WriteLine($"index 00000000...{fileGuid}"); - writer.WriteLine($"--- {(revert || isTracked ? $"a/{change.Path}" : "/dev/null")}"); + writer.WriteLine($"--- {(revert || isTracked ? $"a/{change.Path}" : Native.OS.NullDevice)}"); writer.WriteLine($"+++ b/{change.Path}"); var additions = selection.EndLine - selection.StartLine; diff --git a/src/Native/OS.cs b/src/Native/OS.cs index 1fd4b34d9..4910ed787 100644 --- a/src/Native/OS.cs +++ b/src/Native/OS.cs @@ -27,6 +27,14 @@ public interface IBackend void OpenWithDefaultEditor(string file); } + public static readonly string NullDevice = OperatingSystem.IsWindows() ? "NUL" : "/dev/null"; + + public static bool IsNullDevice(string path) + { + return path.Equals("/dev/null", StringComparison.Ordinal) || + path.Equals("NUL", StringComparison.OrdinalIgnoreCase); + } + public static string DataDir { get; diff --git a/src/ViewModels/DiffContext.cs b/src/ViewModels/DiffContext.cs index c24ee6cec..290fe6e99 100644 --- a/src/ViewModels/DiffContext.cs +++ b/src/ViewModels/DiffContext.cs @@ -97,7 +97,7 @@ public DiffContext(string repo, Models.DiffOption option, DiffContext previous = _info = previous._info; } - if (string.IsNullOrEmpty(_option.OrgPath) || _option.OrgPath == "/dev/null") + if (string.IsNullOrEmpty(_option.OrgPath) || Native.OS.IsNullDevice(_option.OrgPath)) Title = _option.Path; else Title = $"{_option.OrgPath} → {_option.Path}"; @@ -216,7 +216,7 @@ private void LoadContent() } else { - if (!oldPath.Equals("/dev/null", StringComparison.Ordinal)) + if (!Native.OS.IsNullDevice(oldPath)) { var oldImage = await ImageSource.FromRevisionAsync(_repo, "HEAD", oldPath, imgDecoder).ConfigureAwait(false); imgDiff.Old = oldImage.Bitmap;