diff --git a/src/ScriptRunner/AppInstaller/Program.cs b/src/ScriptRunner/AppInstaller/Program.cs index 02664bb..7e983a8 100644 --- a/src/ScriptRunner/AppInstaller/Program.cs +++ b/src/ScriptRunner/AppInstaller/Program.cs @@ -42,7 +42,9 @@ private static Command CreateUpdateDotnetToolCommand() updateDotnetToolCommand.SetHandler((packageName, version) => { Console.WriteLine($"Updating dotnet tool {packageName}"); - var command = string.IsNullOrWhiteSpace(version) == false? $"tool update {packageName} --global --no-cache --ignore-failed-sources --version {version}": $"tool update {packageName} --global --no-cache --ignore-failed-sources"; + var command = string.IsNullOrWhiteSpace(version) == false + ? $"tool update {packageName} --global --no-cache --ignore-failed-sources --version {version} --add-source https://api.nuget.org/v3/index.json" + : $"tool update {packageName} --global --no-cache --ignore-failed-sources --add-source https://api.nuget.org/v3/index.json"; var process = Process.Start("dotnet", command); process.WaitForExit(); if (process.ExitCode != 0) diff --git a/src/ScriptRunner/ScriptRunner.GUI/BackgroundTasks/ConfigRepositoryUpdater.cs b/src/ScriptRunner/ScriptRunner.GUI/BackgroundTasks/ConfigRepositoryUpdater.cs index 8fe55a4..ccbbc77 100644 --- a/src/ScriptRunner/ScriptRunner.GUI/BackgroundTasks/ConfigRepositoryUpdater.cs +++ b/src/ScriptRunner/ScriptRunner.GUI/BackgroundTasks/ConfigRepositoryUpdater.cs @@ -35,9 +35,20 @@ public CliRepositoryClient(CliCommandExecutor cliCommandExecutor) _ = 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 isMainBranchOutdated = await IsBranchOutdated(repoPath, mainBranch, mainBranch); + if (isMainBranchOutdated) + { + if(await GetCurrentBranchName(repoPath) is {} currentBranch && string.IsNullOrWhiteSpace(currentBranch) == false && currentBranch != mainBranch) + { + var isCurrentBranchOutdated = await IsBranchOutdated(repoPath, currentBranch, mainBranch); + if (isCurrentBranchOutdated == false) + { + return (false, mainBranch); + } + } + + } + return (isMainBranchOutdated, mainBranch); } var (success, result) = await ExecuteCommand(repoPath, "git", "status -uno"); @@ -45,6 +56,13 @@ public CliRepositoryClient(CliCommandExecutor cliCommandExecutor) return (isOutdated, "current"); } + private static async Task IsBranchOutdated(string repoPath, string sourceBranch, string targetBranch) + { + var (_, statusForBranch) = await ExecuteCommand(repoPath, "git", $"log {sourceBranch}..origin/{targetBranch} --oneline"); + var outdated = string.IsNullOrWhiteSpace(statusForBranch) == false; + return outdated; + } + static async Task GetHeadBranchName(string repoPath) { var (_, originDetectOutput) = await ExecuteCommand(repoPath, "git", "remote show origin"); @@ -58,6 +76,11 @@ public CliRepositoryClient(CliCommandExecutor cliCommandExecutor) return null; } + static async Task GetCurrentBranchName(string repoPath) + { + var (_, originDetectOutput) = await ExecuteCommand(repoPath, "git", "rev-parse --abbrev-ref HEAD"); + return originDetectOutput; + } public async Task PullRepository(string path) { diff --git a/src/ScriptRunner/ScriptRunner.GUI/ViewModels/MainWindowViewModel.cs b/src/ScriptRunner/ScriptRunner.GUI/ViewModels/MainWindowViewModel.cs index 0b86efc..212e9b5 100644 --- a/src/ScriptRunner/ScriptRunner.GUI/ViewModels/MainWindowViewModel.cs +++ b/src/ScriptRunner/ScriptRunner.GUI/ViewModels/MainWindowViewModel.cs @@ -305,28 +305,13 @@ public MainWindowViewModel(ParamsPanelFactory paramsPanelFactory, VaultProvider _appUpdateScheduler = new RealTimeScheduler(TimeSpan.FromDays(1), TimeSpan.FromHours(1), async () => { - var isNewerVersion = await appUpdater.CheckIsNewerVersionAvailable(); - if (isNewerVersion) - { - Dispatcher.UIThread.Post(() => - { - ShowNewVersionAvailable = true; - }); - } + await RefreshInfoAbouAppUpdates(); }); _appUpdateScheduler.Run(); - _outdatedRepoCheckingScheduler = new RealTimeScheduler(TimeSpan.FromHours( - 4), TimeSpan.FromHours(1), async () => + _outdatedRepoCheckingScheduler = new RealTimeScheduler(TimeSpan.FromHours(4), TimeSpan.FromHours(1), async () => { - var outOfDateRepos = await _configRepositoryUpdater.CheckAllRepositories(); - Dispatcher.UIThread.Post(() => - { - OutOfDateConfigRepositories.Clear(); - OutOfDateConfigRepositories.AddRange(outOfDateRepos); - }); - - + await RefreshInfoAboutRepositories(); }); _outdatedRepoCheckingScheduler.Run(); @@ -336,6 +321,28 @@ public MainWindowViewModel(ParamsPanelFactory paramsPanelFactory, VaultProvider BuildUi(); } + private async Task RefreshInfoAbouAppUpdates() + { + var isNewerVersion = await appUpdater.CheckIsNewerVersionAvailable(); + if (isNewerVersion) + { + Dispatcher.UIThread.Post(() => + { + ShowNewVersionAvailable = true; + }); + } + } + + private async Task RefreshInfoAboutRepositories() + { + var outOfDateRepos = await _configRepositoryUpdater.CheckAllRepositories(); + Dispatcher.UIThread.Post(() => + { + OutOfDateConfigRepositories.Clear(); + OutOfDateConfigRepositories.AddRange(outOfDateRepos); + }); + } + public void CheckForUpdates() { appUpdater.OpenLatestReleaseLog(); @@ -555,6 +562,12 @@ public void OpenSettingsWindow() } } + public void ForceRefresh() + { + _ = RefreshInfoAbouAppUpdates(); + _ = RefreshInfoAboutRepositories(); + BuildUi(); + } public void RefreshSettings() => BuildUi(); public void OpenVaultWindow() => TryToOpenDialog(); diff --git a/src/ScriptRunner/ScriptRunner.GUI/Views/SideMenu.axaml b/src/ScriptRunner/ScriptRunner.GUI/Views/SideMenu.axaml index 61b4f74..637f78b 100644 --- a/src/ScriptRunner/ScriptRunner.GUI/Views/SideMenu.axaml +++ b/src/ScriptRunner/ScriptRunner.GUI/Views/SideMenu.axaml @@ -25,7 +25,7 @@