From 67b6a6d9d55b1e0a90cbd2aeb3f557cbf5e88801 Mon Sep 17 00:00:00 2001 From: leo Date: Mon, 21 Oct 2024 15:31:13 +0800 Subject: [PATCH 01/42] refactor: using custom `PATH` instead of reading it from `zsh` (#581) * run `echo $PATH > ~/Library/Application\ Support/SourceGit/PATH` to generate to custom PATH file for SourceGit --- README.md | 1 + src/Commands/Command.cs | 4 ++++ src/Native/MacOS.cs | 28 +++------------------------- src/Native/OS.cs | 1 + 4 files changed, 9 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index c2dee8c5..b0434ebe 100644 --- a/README.md +++ b/README.md @@ -81,6 +81,7 @@ For **macOS** users: * Make sure your mac trusts all software from anywhere. For more information, search `spctl --master-disable`. * Make sure [git-credential-manager](https://github.com/git-ecosystem/git-credential-manager/releases) is installed on your mac. * You may need to run `sudo xattr -cr /Applications/SourceGit.app` to make sure the software works. +* You man need to run `echo $PATH > ~/Library/Application\ Support/SourceGit/PATH` to introduce `PATH` env to SourceGit. For **Linux** users: diff --git a/src/Commands/Command.cs b/src/Commands/Command.cs index d774fa09..8d304410 100644 --- a/src/Commands/Command.cs +++ b/src/Commands/Command.cs @@ -195,6 +195,10 @@ namespace SourceGit.Commands if (OperatingSystem.IsLinux()) start.Environment.Add("LANG", "en_US.UTF-8"); + // Fix macOS `PATH` env + if (OperatingSystem.IsMacOS() && !string.IsNullOrEmpty(Native.OS.CustomPathEnv)) + start.Environment.Add("PATH", Native.OS.CustomPathEnv); + // Force using this app as git editor. switch (Editor) { diff --git a/src/Native/MacOS.cs b/src/Native/MacOS.cs index 316e509c..9660920d 100644 --- a/src/Native/MacOS.cs +++ b/src/Native/MacOS.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Runtime.Versioning; -using System.Text; using Avalonia; @@ -19,30 +18,9 @@ namespace SourceGit.Native DisableDefaultApplicationMenuItems = true, }); - { - var startInfo = new ProcessStartInfo(); - startInfo.FileName = "zsh"; - startInfo.Arguments = "--login -c \"echo $PATH\""; - startInfo.UseShellExecute = false; - startInfo.CreateNoWindow = true; - startInfo.RedirectStandardOutput = true; - startInfo.StandardOutputEncoding = Encoding.UTF8; - - try - { - var proc = new Process() { StartInfo = startInfo }; - proc.Start(); - var pathData = proc.StandardOutput.ReadToEnd(); - proc.WaitForExit(); - if (proc.ExitCode == 0) - Environment.SetEnvironmentVariable("PATH", pathData); - proc.Close(); - } - catch - { - // Ignore error. - } - } + var customPathFile = Path.Combine(OS.DataDir, "PATH"); + if (File.Exists(customPathFile)) + OS.CustomPathEnv = File.ReadAllText(customPathFile).Trim(); } public string FindGitExecutable() diff --git a/src/Native/OS.cs b/src/Native/OS.cs index bc9c5403..b53f81d9 100644 --- a/src/Native/OS.cs +++ b/src/Native/OS.cs @@ -26,6 +26,7 @@ namespace SourceGit.Native public static string GitExecutable { get; set; } = string.Empty; public static string ShellOrTerminal { get; set; } = string.Empty; public static List ExternalTools { get; set; } = []; + public static string CustomPathEnv { get; set; } = string.Empty; static OS() { From bb6ceb03b9c9deb70c98cbc41837030db62acafb Mon Sep 17 00:00:00 2001 From: "Dmitrij D. Czarkoff" Date: Mon, 21 Oct 2024 07:38:30 +0000 Subject: [PATCH 02/42] fix: Display all parents even if there are more then 2 (#583) --- src/Commands/QueryCommits.cs | 10 +--------- src/Commands/QueryCommitsWithFullMessage.cs | 10 +--------- 2 files changed, 2 insertions(+), 18 deletions(-) diff --git a/src/Commands/QueryCommits.cs b/src/Commands/QueryCommits.cs index 76894412..5875301e 100644 --- a/src/Commands/QueryCommits.cs +++ b/src/Commands/QueryCommits.cs @@ -112,15 +112,7 @@ namespace SourceGit.Commands if (data.Length < 8) return; - var idx = data.IndexOf(' ', StringComparison.Ordinal); - if (idx == -1) - { - _current.Parents.Add(data); - return; - } - - _current.Parents.Add(data.Substring(0, idx)); - _current.Parents.Add(data.Substring(idx + 1)); + _current.Parents.AddRange(data.Split(separator: ' ', options: StringSplitOptions.RemoveEmptyEntries)); } private void MarkFirstMerged() diff --git a/src/Commands/QueryCommitsWithFullMessage.cs b/src/Commands/QueryCommitsWithFullMessage.cs index 36e22b42..116cb3cd 100644 --- a/src/Commands/QueryCommitsWithFullMessage.cs +++ b/src/Commands/QueryCommitsWithFullMessage.cs @@ -73,15 +73,7 @@ namespace SourceGit.Commands if (data.Length < 8) return; - var idx = data.IndexOf(' ', StringComparison.Ordinal); - if (idx == -1) - { - _current.Commit.Parents.Add(data); - return; - } - - _current.Commit.Parents.Add(data.Substring(0, idx)); - _current.Commit.Parents.Add(data.Substring(idx + 1)); + _current.Commit.Parents.AddRange(data.Split(separator: ' ', options: StringSplitOptions.RemoveEmptyEntries)); } private List _commits = new List(); From 3804b0a828a75d35fa1199ad36f779a1cb612aea Mon Sep 17 00:00:00 2001 From: Antony David Date: Mon, 21 Oct 2024 09:41:31 +0200 Subject: [PATCH 03/42] fix(histories): handle commits with breaking changes (#584) --- src/Views/Histories.axaml.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Views/Histories.axaml.cs b/src/Views/Histories.axaml.cs index 1309206d..f8174c0c 100644 --- a/src/Views/Histories.axaml.cs +++ b/src/Views/Histories.axaml.cs @@ -308,7 +308,7 @@ namespace SourceGit.Views [GeneratedRegex(@"^\[[\w\s]+\]")] private static partial Regex REG_KEYWORD_FORMAT1(); - [GeneratedRegex(@"^\w+([\<\(][\w\s_\-\*,]+[\>\)])?\s?:\s")] + [GeneratedRegex(@"^\w+([\<\(][\w\s_\-\*,]+[\>\)])?\!?\s?:\s")] private static partial Regex REG_KEYWORD_FORMAT2(); private List _matches = null; From 00a2ec5abeeafbcda7563aa5fef939092a90cec4 Mon Sep 17 00:00:00 2001 From: leo Date: Mon, 21 Oct 2024 15:47:54 +0800 Subject: [PATCH 04/42] enhance: conventional commit message builder supports breaking changes prefix (#584) --- src/ViewModels/ConventionalCommitMessageBuilder.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/ViewModels/ConventionalCommitMessageBuilder.cs b/src/ViewModels/ConventionalCommitMessageBuilder.cs index ab48bc30..731c48ae 100644 --- a/src/ViewModels/ConventionalCommitMessageBuilder.cs +++ b/src/ViewModels/ConventionalCommitMessageBuilder.cs @@ -68,12 +68,13 @@ namespace SourceGit.ViewModels { builder.Append("("); builder.Append(_scope); - builder.Append("): "); + builder.Append(")"); } - else - { + + if (string.IsNullOrEmpty(_breakingChanges)) builder.Append(": "); - } + else + builder.Append("!: "); builder.Append(_description); builder.Append("\n\n"); From 3b1a54dffddc3a72f3a67935ff80e57292f38298 Mon Sep 17 00:00:00 2001 From: leo Date: Mon, 21 Oct 2024 16:20:34 +0800 Subject: [PATCH 05/42] refactor: use `git update-ref $LOCAL_BRANCH $REMOTE_BRANCH` instead of `git fetch $REMOTE $LOCAL_BRANCH $REMOTE_BRANCH` to fast-forward local branch without checkout it first. --- src/Commands/Fetch.cs | 10 --------- src/Commands/UpdateRef.cs | 23 ++++++++++++++++++++ src/ViewModels/FastForwardWithoutCheckout.cs | 2 +- 3 files changed, 24 insertions(+), 11 deletions(-) create mode 100644 src/Commands/UpdateRef.cs diff --git a/src/Commands/Fetch.cs b/src/Commands/Fetch.cs index 94b7fde9..17f08609 100644 --- a/src/Commands/Fetch.cs +++ b/src/Commands/Fetch.cs @@ -24,16 +24,6 @@ namespace SourceGit.Commands Args += remote; } - public Fetch(string repo, string remote, string localBranch, string remoteBranch, Action outputHandler) - { - _outputHandler = outputHandler; - WorkingDirectory = repo; - Context = repo; - TraitErrorAsOutput = true; - SSHKey = new Config(repo).Get($"remote.{remote}.sshkey"); - Args = $"fetch --progress --verbose {remote} {remoteBranch}:{localBranch}"; - } - protected override void OnReadline(string line) { _outputHandler?.Invoke(line); diff --git a/src/Commands/UpdateRef.cs b/src/Commands/UpdateRef.cs new file mode 100644 index 00000000..ba1b3d2f --- /dev/null +++ b/src/Commands/UpdateRef.cs @@ -0,0 +1,23 @@ +using System; + +namespace SourceGit.Commands +{ + public class UpdateRef : Command + { + public UpdateRef(string repo, string refName, string toRevision, Action outputHandler) + { + _outputHandler = outputHandler; + + WorkingDirectory = repo; + Context = repo; + Args = $"update-ref {refName} {toRevision}"; + } + + protected override void OnReadline(string line) + { + _outputHandler?.Invoke(line); + } + + private Action _outputHandler; + } +} diff --git a/src/ViewModels/FastForwardWithoutCheckout.cs b/src/ViewModels/FastForwardWithoutCheckout.cs index 3861046d..df4b4d73 100644 --- a/src/ViewModels/FastForwardWithoutCheckout.cs +++ b/src/ViewModels/FastForwardWithoutCheckout.cs @@ -31,7 +31,7 @@ namespace SourceGit.ViewModels return Task.Run(() => { - new Commands.Fetch(_repo.FullPath, To.Remote, Local.Name, To.Name, SetProgressDescription).Exec(); + new Commands.UpdateRef(_repo.FullPath, Local.FullName, To.FullName, SetProgressDescription).Exec(); CallUIThread(() => _repo.SetWatcherEnabled(true)); return true; }); From a5e783da086b09246d1cde8728025039525ce1a5 Mon Sep 17 00:00:00 2001 From: leo Date: Mon, 21 Oct 2024 16:39:57 +0800 Subject: [PATCH 06/42] enhance: disable `Fast-Forward` for worktree which is not current branch --- src/ViewModels/Repository.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ViewModels/Repository.cs b/src/ViewModels/Repository.cs index dcc40154..8fc56a38 100644 --- a/src/ViewModels/Repository.cs +++ b/src/ViewModels/Repository.cs @@ -1355,8 +1355,9 @@ namespace SourceGit.ViewModels }; menu.Items.Add(checkout); + var worktree = _worktrees.Find(x => x.Branch == branch.FullName); var upstream = _branches.Find(x => x.FullName == branch.Upstream); - if (upstream != null) + if (upstream != null && worktree == null) { var fastForward = new MenuItem(); fastForward.Header = new Views.NameHighlightedTextBlock("BranchCM.FastForward", upstream.FriendlyName); From 3296f90feb0b8819a56d17907757ec1d9c4450f0 Mon Sep 17 00:00:00 2001 From: leo Date: Mon, 21 Oct 2024 16:58:15 +0800 Subject: [PATCH 07/42] enhance: only show two chars when they are all ascii letters or digits (#585) --- src/Views/Avatar.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Views/Avatar.cs b/src/Views/Avatar.cs index 71ed204d..c959fa43 100644 --- a/src/Views/Avatar.cs +++ b/src/Views/Avatar.cs @@ -128,10 +128,9 @@ namespace SourceGit.Views foreach (var part in parts) chars.Add(part[0]); - if (chars.Count >= 2) + if (chars.Count >= 2 && char.IsAsciiLetterOrDigit(chars[0]) && char.IsAsciiLetterOrDigit(chars[^1])) return string.Format("{0}{1}", chars[0], chars[^1]); - if (chars.Count == 1) - return string.Format("{0}", chars[0]); + return name.Substring(0, 1); } From bb45a5af8ea68b2e3981e0a67fa9b7ce4356d0ca Mon Sep 17 00:00:00 2001 From: leo Date: Mon, 21 Oct 2024 17:07:56 +0800 Subject: [PATCH 08/42] enhance: use `\S` instead of `\w` to supports emoji character --- src/Views/Histories.axaml.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Views/Histories.axaml.cs b/src/Views/Histories.axaml.cs index f8174c0c..137fd298 100644 --- a/src/Views/Histories.axaml.cs +++ b/src/Views/Histories.axaml.cs @@ -308,7 +308,7 @@ namespace SourceGit.Views [GeneratedRegex(@"^\[[\w\s]+\]")] private static partial Regex REG_KEYWORD_FORMAT1(); - [GeneratedRegex(@"^\w+([\<\(][\w\s_\-\*,]+[\>\)])?\!?\s?:\s")] + [GeneratedRegex(@"^\S+([\<\(][\w\s_\-\*,]+[\>\)])?\!?\s?:\s")] private static partial Regex REG_KEYWORD_FORMAT2(); private List _matches = null; From 31e7bef01dc4fecfe5a699fef6624e2d6203a5ab Mon Sep 17 00:00:00 2001 From: leo Date: Mon, 21 Oct 2024 20:28:39 +0800 Subject: [PATCH 09/42] docs: typo in readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b0434ebe..02881ce5 100644 --- a/README.md +++ b/README.md @@ -81,7 +81,7 @@ For **macOS** users: * Make sure your mac trusts all software from anywhere. For more information, search `spctl --master-disable`. * Make sure [git-credential-manager](https://github.com/git-ecosystem/git-credential-manager/releases) is installed on your mac. * You may need to run `sudo xattr -cr /Applications/SourceGit.app` to make sure the software works. -* You man need to run `echo $PATH > ~/Library/Application\ Support/SourceGit/PATH` to introduce `PATH` env to SourceGit. +* You can run `echo $PATH > ~/Library/Application\ Support/SourceGit/PATH` to generate a custom PATH env file to introduce `PATH` env to SourceGit. For **Linux** users: From 6dac26d52555597b854bb53529b4296ff9e12c96 Mon Sep 17 00:00:00 2001 From: leo Date: Tue, 22 Oct 2024 09:29:49 +0800 Subject: [PATCH 10/42] refactor: since there is a hotkey to stage and commit, remove the unsafe auto-stage configure --- src/Models/RepositorySettings.cs | 6 ------ src/Resources/Locales/de_DE.axaml | 1 - src/Resources/Locales/en_US.axaml | 1 - src/Resources/Locales/fr_FR.axaml | 1 - src/Resources/Locales/pt_BR.axaml | 1 - src/Resources/Locales/ru_RU.axaml | 1 - src/Resources/Locales/zh_CN.axaml | 1 - src/Resources/Locales/zh_TW.axaml | 1 - src/ViewModels/WorkingCopy.cs | 10 ++-------- src/Views/WorkingCopy.axaml | 17 +++++------------ 10 files changed, 7 insertions(+), 33 deletions(-) diff --git a/src/Models/RepositorySettings.cs b/src/Models/RepositorySettings.cs index f2fd1bc6..c48e3c0c 100644 --- a/src/Models/RepositorySettings.cs +++ b/src/Models/RepositorySettings.cs @@ -70,12 +70,6 @@ namespace SourceGit.Models set; } = true; - public bool AutoStageBeforeCommit - { - get; - set; - } = false; - public AvaloniaList Filters { get; diff --git a/src/Resources/Locales/de_DE.axaml b/src/Resources/Locales/de_DE.axaml index 7cc9fd63..f5a6c91c 100644 --- a/src/Resources/Locales/de_DE.axaml +++ b/src/Resources/Locales/de_DE.axaml @@ -622,7 +622,6 @@ Ignoriere Dateien im selben Ordner Ignoriere nur diese Datei Amend - Auto-Stage Du kannst diese Datei jetzt stagen. COMMIT COMMIT & PUSH diff --git a/src/Resources/Locales/en_US.axaml b/src/Resources/Locales/en_US.axaml index bfb0ace4..2a475acd 100644 --- a/src/Resources/Locales/en_US.axaml +++ b/src/Resources/Locales/en_US.axaml @@ -631,7 +631,6 @@ Ignore files in the same folder Ignore this file only Amend - Auto-Stage You can stage this file now. COMMIT COMMIT & PUSH diff --git a/src/Resources/Locales/fr_FR.axaml b/src/Resources/Locales/fr_FR.axaml index 8e56248d..631750dd 100644 --- a/src/Resources/Locales/fr_FR.axaml +++ b/src/Resources/Locales/fr_FR.axaml @@ -582,7 +582,6 @@ Ignorer les fichiers dans le même dossier N'ignorer que ce fichier Amender - Auto-Index Vous pouvez indexer ce fichier. COMMIT COMMIT & PUSH diff --git a/src/Resources/Locales/pt_BR.axaml b/src/Resources/Locales/pt_BR.axaml index 8a970730..362e81f1 100644 --- a/src/Resources/Locales/pt_BR.axaml +++ b/src/Resources/Locales/pt_BR.axaml @@ -575,7 +575,6 @@ Ignorar arquivos na mesma pasta Ignorar apenas este arquivo Corrigir - Auto-Stage Você pode stagear este arquivo agora. COMMIT COMMIT & PUSH diff --git a/src/Resources/Locales/ru_RU.axaml b/src/Resources/Locales/ru_RU.axaml index 23ec125f..e331ac31 100644 --- a/src/Resources/Locales/ru_RU.axaml +++ b/src/Resources/Locales/ru_RU.axaml @@ -634,7 +634,6 @@ Игнорировать файлы в том же каталоге Игнорировать только эти файлы Изменить - Автоподготовка Теперь вы можете подготовитть этот файл. ЗАФИКСИРОВАТЬ ЗАФИКСИРОВАТЬ и ОТПРАВИТЬ diff --git a/src/Resources/Locales/zh_CN.axaml b/src/Resources/Locales/zh_CN.axaml index 919e4093..e8346fa3 100644 --- a/src/Resources/Locales/zh_CN.axaml +++ b/src/Resources/Locales/zh_CN.axaml @@ -629,7 +629,6 @@ 忽略同目录下所有文件 忽略本文件 修补(--amend) - 自动暂存 现在您已可将其加入暂存区中 提交 提交并推送 diff --git a/src/Resources/Locales/zh_TW.axaml b/src/Resources/Locales/zh_TW.axaml index bccf4aab..fb6489cf 100644 --- a/src/Resources/Locales/zh_TW.axaml +++ b/src/Resources/Locales/zh_TW.axaml @@ -634,7 +634,6 @@ 忽略同路徑下所有檔案 忽略本檔案 修補 (--amend) - 自動暫存 現在您已可將其加入暫存區中 提 交 提交並推送 diff --git a/src/ViewModels/WorkingCopy.cs b/src/ViewModels/WorkingCopy.cs index 70b4f11f..209da812 100644 --- a/src/ViewModels/WorkingCopy.cs +++ b/src/ViewModels/WorkingCopy.cs @@ -79,12 +79,6 @@ namespace SourceGit.ViewModels private set => SetProperty(ref _isCommitting, value); } - public bool AutoStageBeforeCommit - { - get => _repo.Settings.AutoStageBeforeCommit; - set => _repo.Settings.AutoStageBeforeCommit = value; - } - public bool UseAmend { get => _useAmend; @@ -416,7 +410,7 @@ namespace SourceGit.ViewModels public void Commit() { - DoCommit(AutoStageBeforeCommit, false); + DoCommit(false, false); } public void CommitWithAutoStage() @@ -426,7 +420,7 @@ namespace SourceGit.ViewModels public void CommitWithPush() { - DoCommit(AutoStageBeforeCommit, true); + DoCommit(false, true); } public ContextMenu CreateContextMenuForUnstagedChanges() diff --git a/src/Views/WorkingCopy.axaml b/src/Views/WorkingCopy.axaml index 1b289e9e..3333cda1 100644 --- a/src/Views/WorkingCopy.axaml +++ b/src/Views/WorkingCopy.axaml @@ -185,7 +185,7 @@ - +