enhance: disable unused context menus for bare repository (#899)

This commit is contained in:
leo 2025-01-14 17:53:26 +08:00
parent a9327274c6
commit 766b60d05e
No known key found for this signature in database
4 changed files with 397 additions and 362 deletions

View file

@ -420,6 +420,8 @@ namespace SourceGit.ViewModels
menu.Items.Add(patch);
menu.Items.Add(new MenuItem { Header = "-" });
if (!_repo.IsBare)
{
var resetToThisRevision = new MenuItem();
resetToThisRevision.Header = App.Text("ChangeCM.CheckoutThisRevision");
resetToThisRevision.Icon = App.CreateMenuIcon("Icons.File.Checkout");
@ -448,6 +450,7 @@ namespace SourceGit.ViewModels
if (File.Exists(Path.Combine(fullPath)))
TryToAddContextMenuItemsForGitLFS(menu, change.Path);
}
var copyPath = new MenuItem();
copyPath.Header = App.Text("CopyPath");

View file

@ -253,6 +253,8 @@ namespace SourceGit.ViewModels
var multipleMenu = new ContextMenu();
if (!_repo.IsBare)
{
if (canCherryPick)
{
var cherryPickMultiple = new MenuItem();
@ -283,6 +285,7 @@ namespace SourceGit.ViewModels
if (canCherryPick || canMerge)
multipleMenu.Items.Add(new MenuItem() { Header = "-" });
}
var saveToPatchMultiple = new MenuItem();
saveToPatchMultiple.Icon = App.CreateMenuIcon("Icons.Diff");
@ -394,6 +397,8 @@ namespace SourceGit.ViewModels
menu.Items.Add(new MenuItem() { Header = "-" });
}
if (!_repo.IsBare)
{
if (current.Head != commit.SHA)
{
var reset = new MenuItem();
@ -584,6 +589,7 @@ namespace SourceGit.ViewModels
menu.Items.Add(interactiveRebase);
menu.Items.Add(new MenuItem() { Header = "-" });
}
}
if (current.Head != commit.SHA)
{
@ -914,6 +920,8 @@ namespace SourceGit.ViewModels
submenu.Items.Add(rename);
submenu.Items.Add(new MenuItem() { Header = "-" });
if (!_repo.IsBare)
{
var detect = Commands.GitFlow.DetectType(_repo.FullPath, _repo.Branches, current.Name);
if (detect.IsGitFlowBranch)
{
@ -929,6 +937,7 @@ namespace SourceGit.ViewModels
submenu.Items.Add(finish);
submenu.Items.Add(new MenuItem() { Header = "-" });
}
}
var copy = new MenuItem();
copy.Header = App.Text("BranchCM.CopyName");
@ -951,6 +960,8 @@ namespace SourceGit.ViewModels
FillBranchVisibilityMenu(submenu, branch);
if (!_repo.IsBare)
{
var checkout = new MenuItem();
checkout.Header = new Views.NameHighlightedTextBlock("BranchCM.Checkout", branch.Name);
checkout.Icon = App.CreateMenuIcon("Icons.Check");
@ -972,6 +983,7 @@ namespace SourceGit.ViewModels
e.Handled = true;
};
submenu.Items.Add(merge);
}
var rename = new MenuItem();
rename.Header = new Views.NameHighlightedTextBlock("BranchCM.Rename", branch.Name);
@ -996,6 +1008,8 @@ namespace SourceGit.ViewModels
submenu.Items.Add(delete);
submenu.Items.Add(new MenuItem() { Header = "-" });
if (!_repo.IsBare)
{
var detect = Commands.GitFlow.DetectType(_repo.FullPath, _repo.Branches, branch.Name);
if (detect.IsGitFlowBranch)
{
@ -1011,6 +1025,7 @@ namespace SourceGit.ViewModels
submenu.Items.Add(finish);
submenu.Items.Add(new MenuItem() { Header = "-" });
}
}
var copy = new MenuItem();
copy.Header = App.Text("BranchCM.CopyName");
@ -1104,10 +1119,11 @@ namespace SourceGit.ViewModels
};
submenu.Items.Add(push);
if (!_repo.IsBare && !merged)
{
var merge = new MenuItem();
merge.Header = new Views.NameHighlightedTextBlock("TagCM.Merge", tag.Name, current.Name);
merge.Icon = App.CreateMenuIcon("Icons.Merge");
merge.IsEnabled = !merged;
merge.Click += (_, e) =>
{
if (_repo.CanCreatePopup())
@ -1115,6 +1131,7 @@ namespace SourceGit.ViewModels
e.Handled = true;
};
submenu.Items.Add(merge);
}
var delete = new MenuItem();
delete.Header = new Views.NameHighlightedTextBlock("TagCM.Delete", tag.Name);

View file

@ -1433,6 +1433,8 @@ namespace SourceGit.ViewModels
};
if (branch.IsCurrent)
{
if (!IsBare)
{
var discard = new MenuItem();
discard.Header = App.Text("BranchCM.DiscardAll");
@ -1479,10 +1481,13 @@ namespace SourceGit.ViewModels
menu.Items.Add(fastForward);
menu.Items.Add(pull);
}
}
menu.Items.Add(push);
}
else
{
if (!IsBare)
{
var checkout = new MenuItem();
checkout.Header = new Views.NameHighlightedTextBlock("BranchCM.Checkout", branch.Name);
@ -1494,6 +1499,7 @@ namespace SourceGit.ViewModels
};
menu.Items.Add(checkout);
menu.Items.Add(new MenuItem() { Header = "-" });
}
var worktree = _worktrees.Find(x => x.Branch == branch.FullName);
var upstream = _branches.Find(x => x.FullName == branch.Upstream);
@ -1528,6 +1534,8 @@ namespace SourceGit.ViewModels
menu.Items.Add(push);
if (!IsBare)
{
var merge = new MenuItem();
merge.Header = new Views.NameHighlightedTextBlock("BranchCM.Merge", branch.Name, _currentBranch.Name);
merge.Icon = App.CreateMenuIcon("Icons.Merge");
@ -1550,6 +1558,7 @@ namespace SourceGit.ViewModels
menu.Items.Add(merge);
menu.Items.Add(rebase);
}
var compareWithHead = new MenuItem();
compareWithHead.Header = App.Text("BranchCM.CompareWithHead");
@ -1584,6 +1593,8 @@ namespace SourceGit.ViewModels
}
}
if (!IsBare)
{
var detect = Commands.GitFlow.DetectType(_fullpath, _branches, branch.Name);
if (detect.IsGitFlowBranch)
{
@ -1599,6 +1610,7 @@ namespace SourceGit.ViewModels
menu.Items.Add(new MenuItem() { Header = "-" });
menu.Items.Add(finish);
}
}
var rename = new MenuItem();
rename.Header = new Views.NameHighlightedTextBlock("BranchCM.Rename", branch.Name);
@ -1649,6 +1661,8 @@ namespace SourceGit.ViewModels
menu.Items.Add(createTag);
menu.Items.Add(new MenuItem() { Header = "-" });
if (!IsBare)
{
var remoteBranches = new List<Models.Branch>();
foreach (var b in _branches)
{
@ -1669,6 +1683,7 @@ namespace SourceGit.ViewModels
};
menu.Items.Add(tracking);
}
}
var archive = new MenuItem();
archive.Icon = App.CreateMenuIcon("Icons.Archive");

View file

@ -13,7 +13,7 @@
<Path Width="14" Height="14" Data="{StaticResource Icons.Explore}" Margin="0,2,0,0"/>
</Button>
<Button Classes="icon_button" Width="32" Click="OpenWithExternalTools" ToolTip.Tip="{DynamicResource Text.Repository.OpenWithExternalTools}">
<Button Classes="icon_button" Width="32" Click="OpenWithExternalTools" IsVisible="{Binding !IsBare}" ToolTip.Tip="{DynamicResource Text.Repository.OpenWithExternalTools}">
<Path Width="13" Height="13" Data="{StaticResource Icons.OpenWith}"/>
</Button>