From cf83d0789e0a49f80e32f831c7e2394d69e58e63 Mon Sep 17 00:00:00 2001 From: Gadfly Date: Thu, 6 Feb 2025 20:23:42 +0800 Subject: [PATCH] fix: when upstream is null show CommitAndPush and stop auto push (#955) --- src/ViewModels/LauncherPage.cs | 6 ++++-- src/ViewModels/Popup.cs | 5 +++++ src/ViewModels/Push.cs | 5 +++++ src/ViewModels/Repository.cs | 3 --- src/ViewModels/WorkingCopy.cs | 7 ------- src/Views/WorkingCopy.axaml | 1 - 6 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/ViewModels/LauncherPage.cs b/src/ViewModels/LauncherPage.cs index 498c18657..78aa92785 100644 --- a/src/ViewModels/LauncherPage.cs +++ b/src/ViewModels/LauncherPage.cs @@ -59,15 +59,17 @@ public bool CanCreatePopup() public void StartPopup(Popup popup) { Popup = popup; - ProcessPopup(); + ProcessPopup(true); } - public async void ProcessPopup() + public async void ProcessPopup(bool autoCheck = false) { if (_popup != null) { if (!_popup.Check()) return; + if (autoCheck && !_popup.AutoCheck()) + return; _popup.InProgress = true; var task = _popup.Sure(); diff --git a/src/ViewModels/Popup.cs b/src/ViewModels/Popup.cs index ff74df510..f8991ff4c 100644 --- a/src/ViewModels/Popup.cs +++ b/src/ViewModels/Popup.cs @@ -37,6 +37,11 @@ public bool Check() return !HasErrors; } + public virtual bool AutoCheck() + { + return true; + } + public virtual Task Sure() { return null; diff --git a/src/ViewModels/Push.cs b/src/ViewModels/Push.cs index 004ae7b64..5f37bfaf4 100644 --- a/src/ViewModels/Push.cs +++ b/src/ViewModels/Push.cs @@ -152,6 +152,11 @@ public Push(Repository repo, Models.Branch localBranch) View = new Views.Push() { DataContext = this }; } + public override bool AutoCheck() + { + return !string.IsNullOrEmpty(_selectedRemoteBranch?.Head); + } + public override Task Sure() { _repo.SetWatcherEnabled(false); diff --git a/src/ViewModels/Repository.cs b/src/ViewModels/Repository.cs index 926fd6b66..c91f5e733 100644 --- a/src/ViewModels/Repository.cs +++ b/src/ViewModels/Repository.cs @@ -937,9 +937,6 @@ public void RefreshBranches() CurrentBranch = branches.Find(x => x.IsCurrent); LocalBranchTrees = builder.Locals; RemoteBranchTrees = builder.Remotes; - - if (_workingCopy != null) - _workingCopy.CanCommitWithPush = _currentBranch != null && !string.IsNullOrEmpty(_currentBranch.Upstream); }); } diff --git a/src/ViewModels/WorkingCopy.cs b/src/ViewModels/WorkingCopy.cs index 616f244a4..255d6b6ba 100644 --- a/src/ViewModels/WorkingCopy.cs +++ b/src/ViewModels/WorkingCopy.cs @@ -26,12 +26,6 @@ public bool IncludeUntracked } } - public bool CanCommitWithPush - { - get => _canCommitWithPush; - set => SetProperty(ref _canCommitWithPush, value); - } - public bool HasUnsolvedConflicts { get => _hasUnsolvedConflicts; @@ -1625,7 +1619,6 @@ private bool IsChanged(List old, List cur) private bool _isUnstaging = false; private bool _isCommitting = false; private bool _useAmend = false; - private bool _canCommitWithPush = false; private List _cached = []; private List _unstaged = []; private List _staged = []; diff --git a/src/Views/WorkingCopy.axaml b/src/Views/WorkingCopy.axaml index 7f493b6ae..e0d0503db 100644 --- a/src/Views/WorkingCopy.axaml +++ b/src/Views/WorkingCopy.axaml @@ -375,7 +375,6 @@ -