From 0728cc9bf6d3d33c326b6d5f353f352122c7f513 Mon Sep 17 00:00:00 2001 From: Cezary Piatek Date: Tue, 17 Sep 2024 21:50:56 +0200 Subject: [PATCH 1/4] Improve git operations --- .../ConfigRepositoryUpdater.cs | 41 ++++++++++++++++--- .../OutdatedRepositoryModel.cs | 14 +++++-- .../ViewModels/MainWindowViewModel.cs | 17 ++++++-- .../Views/NotificationSection.axaml | 7 ++-- 4 files changed, 62 insertions(+), 17 deletions(-) diff --git a/src/ScriptRunner/ScriptRunner.GUI/BackgroundTasks/ConfigRepositoryUpdater.cs b/src/ScriptRunner/ScriptRunner.GUI/BackgroundTasks/ConfigRepositoryUpdater.cs index 52ae922..8fe55a4 100644 --- a/src/ScriptRunner/ScriptRunner.GUI/BackgroundTasks/ConfigRepositoryUpdater.cs +++ b/src/ScriptRunner/ScriptRunner.GUI/BackgroundTasks/ConfigRepositoryUpdater.cs @@ -3,6 +3,7 @@ using System.IO; using System.Linq; using System.Text; +using System.Text.RegularExpressions; using System.Threading.Tasks; using CliWrap; using ScriptRunner.GUI.Settings; @@ -11,7 +12,7 @@ namespace ScriptRunner.GUI.BackgroundTasks; public interface IRepositoryClient { - Task IsOutdated(string repoPath); + Task<(bool,string)> IsOutdated(string repoPath); Task PullRepository(string path); } @@ -29,16 +30,40 @@ public CliRepositoryClient(CliCommandExecutor cliCommandExecutor) _cliCommandExecutor = cliCommandExecutor; } - public async Task IsOutdated(string repoPath) + public async Task<(bool,string)> IsOutdated(string repoPath) { _ = await ExecuteCommand(repoPath, "git", "fetch --prune origin --verbose"); + if(await GetHeadBranchName(repoPath) is {} mainBranch) + { + var (_, statusForBranch) = await ExecuteCommand(repoPath, "git", $"log {mainBranch}..origin/{mainBranch} --oneline"); + var outdated = string.IsNullOrWhiteSpace(statusForBranch) == false; + return (outdated, mainBranch); + } + var (success, result) = await ExecuteCommand(repoPath, "git", "status -uno"); - return success && result.Contains("up to date", StringComparison.InvariantCultureIgnoreCase) == false; + var isOutdated = success && result.Contains("up to date", StringComparison.InvariantCultureIgnoreCase) == false; + return (isOutdated, "current"); } + static async Task GetHeadBranchName(string repoPath) + { + var (_, originDetectOutput) = await ExecuteCommand(repoPath, "git", "remote show origin"); + + // Use regular expression to match the 'HEAD branch' line + var match = Regex.Match(originDetectOutput, @"HEAD branch:\s*(\S+)"); + if (match.Success) + { + return match.Groups[1].Value; // Return the branch name captured by the group + } + + return null; + } + public async Task PullRepository(string path) { - var result = await _cliCommandExecutor.Invoke(new CliCommand("git", "pull --rebase=true origin --prune --verbose", path)); + _ = await ExecuteCommand(path, "git", "fetch --prune origin --verbose"); + var mainBranch = await GetHeadBranchName(path) ?? ""; + var result = await _cliCommandExecutor.Invoke(new CliCommand("git", $"rebase origin/{mainBranch} {mainBranch} --verbose", path)); return result.StandardError.Contains("error", StringComparison.InvariantCultureIgnoreCase) == false; } @@ -90,11 +115,15 @@ public async Task> CheckAllRepositories() continue; } - var isOutdated = await repositoryClient.IsOutdated(entry.Path); + var (isOutdated, branchName) = await repositoryClient.IsOutdated(entry.Path); if (isOutdated) { - outOfDateRepos.Add(new OutdatedRepositoryModel(entry.Path)); + outOfDateRepos.Add(new OutdatedRepositoryModel() + { + Path = entry.Path, + BranchName = branchName + }); } } diff --git a/src/ScriptRunner/ScriptRunner.GUI/BackgroundTasks/OutdatedRepositoryModel.cs b/src/ScriptRunner/ScriptRunner.GUI/BackgroundTasks/OutdatedRepositoryModel.cs index 40e3d90..59d3999 100644 --- a/src/ScriptRunner/ScriptRunner.GUI/BackgroundTasks/OutdatedRepositoryModel.cs +++ b/src/ScriptRunner/ScriptRunner.GUI/BackgroundTasks/OutdatedRepositoryModel.cs @@ -1,11 +1,17 @@ -namespace ScriptRunner.GUI.BackgroundTasks; +using ReactiveUI; -public class OutdatedRepositoryModel +namespace ScriptRunner.GUI.BackgroundTasks; + +public class OutdatedRepositoryModel:ReactiveObject { public string Path { get; set; } + public string BranchName { get; set; } + + private bool _isPulling; - public OutdatedRepositoryModel(string path) + public bool IsPulling { - Path = path; + get => _isPulling; + set => this.RaiseAndSetIfChanged(ref _isPulling, value); } } \ No newline at end of file diff --git a/src/ScriptRunner/ScriptRunner.GUI/ViewModels/MainWindowViewModel.cs b/src/ScriptRunner/ScriptRunner.GUI/ViewModels/MainWindowViewModel.cs index 68bbba0..0b86efc 100644 --- a/src/ScriptRunner/ScriptRunner.GUI/ViewModels/MainWindowViewModel.cs +++ b/src/ScriptRunner/ScriptRunner.GUI/ViewModels/MainWindowViewModel.cs @@ -573,13 +573,22 @@ public async void PullRepoChanges(object arg) { if (arg is OutdatedRepositoryModel record) { + record.IsPulling = true; var result = false; - await Task.Run(async () => result = await _configRepositoryUpdater.RefreshRepository(record.Path)); - if (result) + try { - OutOfDateConfigRepositories.Remove(record); - RefreshSettings(); + await Task.Run(async () => result = await _configRepositoryUpdater.RefreshRepository(record.Path)); } + finally + { + if (result) + { + OutOfDateConfigRepositories.Remove(record); + RefreshSettings(); + } + record.IsPulling = false; + } + } } diff --git a/src/ScriptRunner/ScriptRunner.GUI/Views/NotificationSection.axaml b/src/ScriptRunner/ScriptRunner.GUI/Views/NotificationSection.axaml index 81e824d..29e9139 100644 --- a/src/ScriptRunner/ScriptRunner.GUI/Views/NotificationSection.axaml +++ b/src/ScriptRunner/ScriptRunner.GUI/Views/NotificationSection.axaml @@ -30,9 +30,10 @@ - - - From cf972eaf854d77b656e8bfd0d5e44ea7292457aa Mon Sep 17 00:00:00 2001 From: Cezary Piatek Date: Tue, 17 Sep 2024 22:11:42 +0200 Subject: [PATCH 2/4] Add loading indicator for Pull operation --- src/ScriptRunner/ScriptRunner.GUI/App.axaml | 8 ++++++++ src/ScriptRunner/ScriptRunner.GUI/ScriptRunner.GUI.csproj | 1 + .../ScriptRunner.GUI/Views/NotificationSection.axaml | 2 ++ 3 files changed, 11 insertions(+) diff --git a/src/ScriptRunner/ScriptRunner.GUI/App.axaml b/src/ScriptRunner/ScriptRunner.GUI/App.axaml index 692465c..0213660 100644 --- a/src/ScriptRunner/ScriptRunner.GUI/App.axaml +++ b/src/ScriptRunner/ScriptRunner.GUI/App.axaml @@ -12,4 +12,12 @@ + + + + + + + + diff --git a/src/ScriptRunner/ScriptRunner.GUI/ScriptRunner.GUI.csproj b/src/ScriptRunner/ScriptRunner.GUI/ScriptRunner.GUI.csproj index f392d2c..286a1c4 100644 --- a/src/ScriptRunner/ScriptRunner.GUI/ScriptRunner.GUI.csproj +++ b/src/ScriptRunner/ScriptRunner.GUI/ScriptRunner.GUI.csproj @@ -45,6 +45,7 @@ + diff --git a/src/ScriptRunner/ScriptRunner.GUI/Views/NotificationSection.axaml b/src/ScriptRunner/ScriptRunner.GUI/Views/NotificationSection.axaml index 29e9139..34bdd3d 100644 --- a/src/ScriptRunner/ScriptRunner.GUI/Views/NotificationSection.axaml +++ b/src/ScriptRunner/ScriptRunner.GUI/Views/NotificationSection.axaml @@ -6,6 +6,7 @@ xmlns:views="clr-namespace:ScriptRunner.GUI.Views" xmlns:viewModels="clr-namespace:ScriptRunner.GUI.ViewModels" xmlns:converters="clr-namespace:ScriptRunner.GUI.Converters" + xmlns:avalonia="clr-namespace:LoadingIndicators.Avalonia;assembly=LoadingIndicators.Avalonia" mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" x:DataType="viewModels:MainWindowViewModel" x:Class="ScriptRunner.GUI.Views.NotificationSection"> @@ -36,6 +37,7 @@ + From 1af6de8c22057158286ff79bbffce0dab2d013e2 Mon Sep 17 00:00:00 2001 From: Cezary Piatek Date: Tue, 17 Sep 2024 22:24:54 +0200 Subject: [PATCH 3/4] Fix main window transparency --- src/ScriptRunner/ScriptRunner.GUI/Views/MainWindow.axaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ScriptRunner/ScriptRunner.GUI/Views/MainWindow.axaml b/src/ScriptRunner/ScriptRunner.GUI/Views/MainWindow.axaml index 19346b4..b00f869 100644 --- a/src/ScriptRunner/ScriptRunner.GUI/Views/MainWindow.axaml +++ b/src/ScriptRunner/ScriptRunner.GUI/Views/MainWindow.axaml @@ -40,7 +40,7 @@ BackgroundSource="Digger" TintColor="Black" TintOpacity="1" - MaterialOpacity="0.65" /> + MaterialOpacity="0.85" /> From dac6f129f9ebd15e13e197a51d7ee1fa794aa931 Mon Sep 17 00:00:00 2001 From: Cezary Piatek Date: Tue, 17 Sep 2024 22:32:32 +0200 Subject: [PATCH 4/4] Improve history layout --- .../Views/ActionDetailsSection.axaml | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/ScriptRunner/ScriptRunner.GUI/Views/ActionDetailsSection.axaml b/src/ScriptRunner/ScriptRunner.GUI/Views/ActionDetailsSection.axaml index eebc5d7..6e78516 100644 --- a/src/ScriptRunner/ScriptRunner.GUI/Views/ActionDetailsSection.axaml +++ b/src/ScriptRunner/ScriptRunner.GUI/Views/ActionDetailsSection.axaml @@ -122,11 +122,18 @@ + + - - - - + + + + + + + + +