From 87ebe3741df33375ae380c28bfcd838d2f973d5b Mon Sep 17 00:00:00 2001 From: leo Date: Tue, 22 Apr 2025 18:45:14 +0800 Subject: [PATCH] fix: for init-commit, app will crash with `COMMIT & PUSH` due to local branch has not been updated (#1229) Signed-off-by: leo --- src/ViewModels/Push.cs | 3 +++ src/ViewModels/WorkingCopy.cs | 13 ++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/ViewModels/Push.cs b/src/ViewModels/Push.cs index 5bbb9858..917935b0 100644 --- a/src/ViewModels/Push.cs +++ b/src/ViewModels/Push.cs @@ -114,6 +114,9 @@ namespace SourceGit.ViewModels // Set default selected local branch. if (localBranch != null) { + if (LocalBranches.Count == 0) + LocalBranches.Add(localBranch); + _selectedLocalBranch = localBranch; HasSpecifiedLocalBranch = true; } diff --git a/src/ViewModels/WorkingCopy.cs b/src/ViewModels/WorkingCopy.cs index 29c8a13f..ef6f0996 100644 --- a/src/ViewModels/WorkingCopy.cs +++ b/src/ViewModels/WorkingCopy.cs @@ -1733,7 +1733,18 @@ namespace SourceGit.ViewModels UseAmend = false; if (autoPush && _repo.Remotes.Count > 0) - _repo.ShowAndStartPopup(new Push(_repo, null)); + { + if (_repo.CurrentBranch == null) + { + var currentBranchName = Commands.Branch.ShowCurrent(_repo.FullPath); + var tmp = new Models.Branch() { Name = currentBranchName }; + _repo.ShowAndStartPopup(new Push(_repo, tmp)); + } + else + { + _repo.ShowAndStartPopup(new Push(_repo, null)); + } + } } _repo.MarkBranchesDirtyManually();