From 4d5e543527f810167b2f403305da4179e5e1585d Mon Sep 17 00:00:00 2001 From: leo Date: Tue, 25 May 2021 17:38:42 +0800 Subject: [PATCH] fix: fix crash when push/pull/fetch with no remotes added into this repository --- src/Views/Widgets/Dashboard.xaml.cs | 17 +++++++++++++++++ src/Views/Widgets/Histories.xaml.cs | 3 ++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/Views/Widgets/Dashboard.xaml.cs b/src/Views/Widgets/Dashboard.xaml.cs index 31bf5238..42902ea1 100644 --- a/src/Views/Widgets/Dashboard.xaml.cs +++ b/src/Views/Widgets/Dashboard.xaml.cs @@ -271,16 +271,31 @@ namespace SourceGit.Views.Widgets { } private void OpenFetch(object sender, RoutedEventArgs e) { + if (repo.Remotes.Count == 0) { + Models.Exception.Raise("No remotes added to this repository!!!"); + return; + } + new Popups.Fetch(repo, null).Show(); e.Handled = true; } private void OpenPull(object sender, RoutedEventArgs e) { + if (repo.Remotes.Count == 0) { + Models.Exception.Raise("No remotes added to this repository!!!"); + return; + } + new Popups.Pull(repo, null).Show(); e.Handled = true; } private void OpenPush(object sender, RoutedEventArgs e) { + if (repo.Remotes.Count == 0) { + Models.Exception.Raise("No remotes added to this repository!!!"); + return; + } + new Popups.Push(repo, null).Show(); e.Handled = true; } @@ -450,6 +465,7 @@ namespace SourceGit.Views.Widgets { private void FillLocalBranchContextMenu(ContextMenu menu, Models.Branch branch) { var push = new MenuItem(); push.Header = App.Text("BranchCM.Push", branch.Name); + push.IsEnabled = repo.Remotes.Count > 0; push.Click += (o, e) => { new Popups.Push(repo, branch).Show(); e.Handled = true; @@ -768,6 +784,7 @@ namespace SourceGit.Views.Widgets { var pushTag = new MenuItem(); pushTag.Header = App.Text("TagCM.Push", tag.Name); + pushTag.IsEnabled = repo.Remotes.Count > 0; pushTag.Click += (o, ev) => { new Popups.PushTag(repo, tag.Name).Show(); ev.Handled = true; diff --git a/src/Views/Widgets/Histories.xaml.cs b/src/Views/Widgets/Histories.xaml.cs index f937d320..c73e735a 100644 --- a/src/Views/Widgets/Histories.xaml.cs +++ b/src/Views/Widgets/Histories.xaml.cs @@ -406,7 +406,7 @@ namespace SourceGit.Views.Widgets { var push = new MenuItem(); push.Header = App.Text("BranchCM.Push", current.Name); - push.IsEnabled = dirty; + push.IsEnabled = repo.Remotes.Count > 0 && dirty; push.Click += (o, e) => { new Popups.Push(repo, current).Show(); e.Handled = true; @@ -579,6 +579,7 @@ namespace SourceGit.Views.Widgets { var push = new MenuItem(); push.Header = App.Text("TagCM.Push", tag); + push.IsEnabled = repo.Remotes.Count > 0; push.Click += (o, e) => { new Popups.PushTag(repo, tag).Show(); e.Handled = true;