diff --git a/src/App.axaml.cs b/src/App.axaml.cs index a4efa41a..f5c0559a 100644 --- a/src/App.axaml.cs +++ b/src/App.axaml.cs @@ -618,8 +618,7 @@ namespace SourceGit try { // Fetch latest release information. - using var client = new HttpClient(); - client.Timeout = TimeSpan.FromSeconds(5); + using var client = new HttpClient() { Timeout = TimeSpan.FromSeconds(5) }; var data = await client.GetStringAsync("https://sourcegit-scm.github.io/data/version.json"); // Parse JSON into Models.Version. diff --git a/src/Commands/Command.cs b/src/Commands/Command.cs index 9a6f27cb..f54d24b2 100644 --- a/src/Commands/Command.cs +++ b/src/Commands/Command.cs @@ -55,9 +55,9 @@ namespace SourceGit.Commands Log?.AppendLine($"$ git {Args}\n"); var errs = new List(); + using var proc = new Process(); proc.StartInfo = CreateGitStartInfo(true); - proc.OutputDataReceived += (_, e) => HandleOutput(e.Data, errs); proc.ErrorDataReceived += (_, e) => HandleOutput(e.Data, errs); @@ -129,8 +129,7 @@ namespace SourceGit.Commands protected async Task ReadToEndAsync() { - using var proc = new Process(); - proc.StartInfo = CreateGitStartInfo(true); + using var proc = new Process() { StartInfo = CreateGitStartInfo(true) }; try { diff --git a/src/Commands/QueryFileContent.cs b/src/Commands/QueryFileContent.cs index 193614f9..0bb8605a 100644 --- a/src/Commands/QueryFileContent.cs +++ b/src/Commands/QueryFileContent.cs @@ -24,14 +24,13 @@ namespace SourceGit.Commands using var proc = Process.Start(starter); await proc.StandardOutput.BaseStream.CopyToAsync(stream).ConfigureAwait(false); await proc.WaitForExitAsync().ConfigureAwait(false); - - stream.Position = 0; } catch (Exception e) { App.RaiseException(repo, $"Failed to query file content: {e}"); } + stream.Position = 0; return stream; } @@ -56,14 +55,13 @@ namespace SourceGit.Commands await proc.StandardInput.WriteLineAsync($"size {size}").ConfigureAwait(false); await proc.StandardOutput.BaseStream.CopyToAsync(stream).ConfigureAwait(false); await proc.WaitForExitAsync().ConfigureAwait(false); - - stream.Position = 0; } catch (Exception e) { App.RaiseException(repo, $"Failed to query file content: {e}"); } + stream.Position = 0; return stream; } } diff --git a/src/Commands/SaveRevisionFile.cs b/src/Commands/SaveRevisionFile.cs index 42163d6c..f1482a7e 100644 --- a/src/Commands/SaveRevisionFile.cs +++ b/src/Commands/SaveRevisionFile.cs @@ -43,10 +43,15 @@ namespace SourceGit.Commands try { using var proc = Process.Start(starter); + if (input != null) - await proc.StandardInput.WriteAsync(await new StreamReader(input).ReadToEndAsync()); - await proc.StandardOutput.BaseStream.CopyToAsync(sw); - await proc.WaitForExitAsync(); + { + var inputString = await new StreamReader(input).ReadToEndAsync().ConfigureAwait(false); + await proc.StandardInput.WriteAsync(inputString).ConfigureAwait(false); + } + + await proc.StandardOutput.BaseStream.CopyToAsync(sw).ConfigureAwait(false); + await proc.WaitForExitAsync().ConfigureAwait(false); } catch (Exception e) { diff --git a/src/Native/Linux.cs b/src/Native/Linux.cs index e5684345..04391fde 100644 --- a/src/Native/Linux.cs +++ b/src/Native/Linux.cs @@ -48,13 +48,14 @@ namespace SourceGit.Native public List FindExternalTools() { + var localAppDataDir = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); var finder = new Models.ExternalToolsFinder(); finder.VSCode(() => FindExecutable("code")); finder.VSCodeInsiders(() => FindExecutable("code-insiders")); finder.VSCodium(() => FindExecutable("codium")); finder.Cursor(() => FindExecutable("cursor")); - finder.Fleet(FindJetBrainsFleet); - finder.FindJetBrainsFromToolbox(() => Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "JetBrains/Toolbox")); + finder.Fleet(() => FindJetBrainsFleet(localAppDataDir)); + finder.FindJetBrainsFromToolbox(() => Path.Combine(localAppDataDir, "JetBrains/Toolbox")); finder.SublimeText(() => FindExecutable("subl")); finder.Zed(() => FindExecutable("zeditor")); return finder.Tools; @@ -132,9 +133,9 @@ namespace SourceGit.Native return string.Empty; } - private string FindJetBrainsFleet() + private string FindJetBrainsFleet(string localAppDataDir) { - var path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "JetBrains/Toolbox/apps/fleet/bin/Fleet"); + var path = Path.Combine(localAppDataDir, "JetBrains/Toolbox/apps/fleet/bin/Fleet"); return File.Exists(path) ? path : FindExecutable("fleet"); } } diff --git a/src/Native/MacOS.cs b/src/Native/MacOS.cs index 38a073e6..5741e404 100644 --- a/src/Native/MacOS.cs +++ b/src/Native/MacOS.cs @@ -70,13 +70,14 @@ namespace SourceGit.Native public List FindExternalTools() { + var home = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); var finder = new Models.ExternalToolsFinder(); finder.VSCode(() => "/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code"); finder.VSCodeInsiders(() => "/Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/bin/code"); finder.VSCodium(() => "/Applications/VSCodium.app/Contents/Resources/app/bin/codium"); finder.Cursor(() => "/Applications/Cursor.app/Contents/Resources/app/bin/cursor"); - finder.Fleet(() => Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Applications/Fleet.app/Contents/MacOS/Fleet")); - finder.FindJetBrainsFromToolbox(() => Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Library/Application Support/JetBrains/Toolbox")); + finder.Fleet(() => Path.Combine(home, "Applications/Fleet.app/Contents/MacOS/Fleet")); + finder.FindJetBrainsFromToolbox(() => Path.Combine(home, "Library/Application Support/JetBrains/Toolbox")); finder.SublimeText(() => "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl"); finder.Zed(() => File.Exists("/usr/local/bin/zed") ? "/usr/local/bin/zed" : "/Applications/Zed.app/Contents/MacOS/cli"); return finder.Tools; diff --git a/src/Native/Windows.cs b/src/Native/Windows.cs index 9c21903e..92aef8b5 100644 --- a/src/Native/Windows.cs +++ b/src/Native/Windows.cs @@ -180,13 +180,14 @@ namespace SourceGit.Native public List FindExternalTools() { + var localAppDataDir = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); var finder = new Models.ExternalToolsFinder(); finder.VSCode(FindVSCode); finder.VSCodeInsiders(FindVSCodeInsiders); finder.VSCodium(FindVSCodium); finder.Cursor(FindCursor); - finder.Fleet(() => Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), @"Programs\Fleet\Fleet.exe")); - finder.FindJetBrainsFromToolbox(() => Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), @"JetBrains\Toolbox")); + finder.Fleet(() => Path.Combine(localAppDataDir, @"Programs\Fleet\Fleet.exe")); + finder.FindJetBrainsFromToolbox(() => Path.Combine(localAppDataDir, @"JetBrains\Toolbox")); finder.SublimeText(FindSublimeText); finder.TryAdd("Visual Studio", "vs", FindVisualStudio, GenerateCommandlineArgsForVisualStudio); return finder.Tools; diff --git a/src/ViewModels/ConventionalCommitMessageBuilder.cs b/src/ViewModels/ConventionalCommitMessageBuilder.cs index 824d0a86..d002a77d 100644 --- a/src/ViewModels/ConventionalCommitMessageBuilder.cs +++ b/src/ViewModels/ConventionalCommitMessageBuilder.cs @@ -77,19 +77,19 @@ namespace SourceGit.ViewModels builder.Append(": "); builder.Append(_description); - builder.AppendLine("\n"); + builder.AppendLine().AppendLine(); if (!string.IsNullOrEmpty(_detail)) { builder.Append(_detail); - builder.AppendLine("\n"); + builder.AppendLine().AppendLine(); } if (!string.IsNullOrEmpty(_breakingChanges)) { builder.Append("BREAKING CHANGE: "); builder.Append(_breakingChanges); - builder.AppendLine("\n"); + builder.AppendLine().AppendLine(); } if (!string.IsNullOrEmpty(_closedIssue)) diff --git a/src/ViewModels/ExecuteCustomAction.cs b/src/ViewModels/ExecuteCustomAction.cs index 4c070841..fb0f2f81 100644 --- a/src/ViewModels/ExecuteCustomAction.cs +++ b/src/ViewModels/ExecuteCustomAction.cs @@ -250,8 +250,7 @@ namespace SourceGit.ViewModels start.StandardErrorEncoding = Encoding.UTF8; start.WorkingDirectory = _repo.FullPath; - using var proc = new Process(); - proc.StartInfo = start; + using var proc = new Process() { StartInfo = start }; var builder = new StringBuilder(); proc.OutputDataReceived += (_, e) => diff --git a/src/ViewModels/Histories.cs b/src/ViewModels/Histories.cs index 6e56b9cf..f0bf8bef 100644 --- a/src/ViewModels/Histories.cs +++ b/src/ViewModels/Histories.cs @@ -272,6 +272,7 @@ namespace SourceGit.ViewModels _repo.CheckoutBranch(b); return; } + if (d.Type == Models.DecoratorType.RemoteBranchHead) { var rb = _repo.Branches.Find(x => x.FriendlyName == d.Name);