Skip to content

Commit 5dea46e

Browse files
committed
fix: Use correct null device path on Windows
1 parent a546bec commit 5dea46e

File tree

5 files changed

+13
-5
lines changed

5 files changed

+13
-5
lines changed

src/Commands/Command.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ protected ProcessStartInfo CreateGitStartInfo(bool redirect)
181181

182182
// If an SSH private key was provided, sets the environment.
183183
if (!start.Environment.ContainsKey("GIT_SSH_COMMAND") && !string.IsNullOrEmpty(SSHKey))
184-
start.Environment.Add("GIT_SSH_COMMAND", $"ssh -i '{SSHKey}' -F '/dev/null'");
184+
start.Environment.Add("GIT_SSH_COMMAND", $"ssh -i '{SSHKey}' -F '{Native.OS.NullDevice}'");
185185

186186
// Force using en_US.UTF-8 locale
187187
if (OperatingSystem.IsLinux())

src/Models/DiffOption.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public DiffOption(Change change, bool isUnstaged)
3939
case ChangeState.Added:
4040
case ChangeState.Untracked:
4141
_extra = "--no-index";
42-
_orgPath = "/dev/null";
42+
_orgPath = Native.OS.NullDevice;
4343
break;
4444
}
4545
}

src/Models/DiffResult.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public void GenerateNewPatchFromSelection(Change change, string fileBlobGuid, Te
106106
if (!revert && !isTracked)
107107
writer.WriteLine("new file mode 100644");
108108
writer.WriteLine($"index 00000000...{fileGuid}");
109-
writer.WriteLine($"--- {(revert || isTracked ? $"a/{change.Path}" : "/dev/null")}");
109+
writer.WriteLine($"--- {(revert || isTracked ? $"a/{change.Path}" : Native.OS.NullDevice)}");
110110
writer.WriteLine($"+++ b/{change.Path}");
111111

112112
var additions = selection.EndLine - selection.StartLine;

src/Native/OS.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ public interface IBackend
2727
void OpenWithDefaultEditor(string file);
2828
}
2929

30+
public static readonly string NullDevice = OperatingSystem.IsWindows() ? "NUL" : "/dev/null";
31+
32+
public static bool IsNullDevice(string path)
33+
{
34+
return path.Equals("/dev/null", StringComparison.Ordinal) ||
35+
path.Equals("NUL", StringComparison.OrdinalIgnoreCase);
36+
}
37+
3038
public static string DataDir
3139
{
3240
get;

src/ViewModels/DiffContext.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public DiffContext(string repo, Models.DiffOption option, DiffContext previous =
9797
_info = previous._info;
9898
}
9999

100-
if (string.IsNullOrEmpty(_option.OrgPath) || _option.OrgPath == "/dev/null")
100+
if (string.IsNullOrEmpty(_option.OrgPath) || Native.OS.IsNullDevice(_option.OrgPath))
101101
Title = _option.Path;
102102
else
103103
Title = $"{_option.OrgPath}{_option.Path}";
@@ -216,7 +216,7 @@ private void LoadContent()
216216
}
217217
else
218218
{
219-
if (!oldPath.Equals("/dev/null", StringComparison.Ordinal))
219+
if (!Native.OS.IsNullDevice(oldPath))
220220
{
221221
var oldImage = await ImageSource.FromRevisionAsync(_repo, "HEAD", oldPath, imgDecoder).ConfigureAwait(false);
222222
imgDiff.Old = oldImage.Bitmap;

0 commit comments

Comments
 (0)