mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-23 21:24:59 +00:00
feature: add a context menu item to compare selected branch/revision with current worktree
This commit is contained in:
parent
211e4b24c1
commit
52ef0db427
6 changed files with 119 additions and 30 deletions
|
@ -318,10 +318,10 @@ namespace SourceGit.ViewModels
|
|||
|
||||
if (current.Head != commit.SHA)
|
||||
{
|
||||
var compare = new MenuItem();
|
||||
compare.Header = App.Text("CommitCM.CompareWithHead");
|
||||
compare.Icon = App.CreateMenuIcon("Icons.Compare");
|
||||
compare.Click += (o, e) =>
|
||||
var compareWithHead = new MenuItem();
|
||||
compareWithHead.Header = App.Text("CommitCM.CompareWithHead");
|
||||
compareWithHead.Icon = App.CreateMenuIcon("Icons.Compare");
|
||||
compareWithHead.Click += (o, e) =>
|
||||
{
|
||||
var head = _commits.Find(x => x.SHA == current.Head);
|
||||
if (head == null)
|
||||
|
@ -338,8 +338,21 @@ namespace SourceGit.ViewModels
|
|||
|
||||
e.Handled = true;
|
||||
};
|
||||
menu.Items.Add(compareWithHead);
|
||||
|
||||
if (_repo.WorkingCopyChangesCount > 0)
|
||||
{
|
||||
var compareWithWorktree = new MenuItem();
|
||||
compareWithWorktree.Header = App.Text("CommitCM.CompareWithWorktree");
|
||||
compareWithWorktree.Icon = App.CreateMenuIcon("Icons.Compare");
|
||||
compareWithWorktree.Click += (o, e) =>
|
||||
{
|
||||
DetailContext = new RevisionCompare(_repo.FullPath, commit, null);
|
||||
e.Handled = true;
|
||||
};
|
||||
menu.Items.Add(compareWithWorktree);
|
||||
}
|
||||
|
||||
menu.Items.Add(compare);
|
||||
menu.Items.Add(new MenuItem() { Header = "-" });
|
||||
}
|
||||
|
||||
|
|
|
@ -947,6 +947,25 @@ namespace SourceGit.ViewModels
|
|||
e.Handled = true;
|
||||
};
|
||||
|
||||
if (WorkingCopyChangesCount > 0)
|
||||
{
|
||||
var compareWithWorktree = new MenuItem();
|
||||
compareWithWorktree.Header = App.Text("BranchCM.CompareWithWorktree");
|
||||
compareWithWorktree.Icon = App.CreateMenuIcon("Icons.Compare");
|
||||
compareWithWorktree.Click += (o, e) =>
|
||||
{
|
||||
SearchResultSelectedCommit = null;
|
||||
|
||||
if (_histories != null)
|
||||
{
|
||||
var target = new Commands.QuerySingleCommit(FullPath, branch.Head).Result();
|
||||
_histories.AutoSelectedCommit = null;
|
||||
_histories.DetailContext = new RevisionCompare(FullPath, target, null);
|
||||
}
|
||||
};
|
||||
menu.Items.Add(compareWithWorktree);
|
||||
}
|
||||
|
||||
menu.Items.Add(new MenuItem() { Header = "-" });
|
||||
menu.Items.Add(compare);
|
||||
}
|
||||
|
@ -1238,8 +1257,27 @@ namespace SourceGit.ViewModels
|
|||
|
||||
e.Handled = true;
|
||||
};
|
||||
|
||||
menu.Items.Add(compare);
|
||||
|
||||
if (WorkingCopyChangesCount > 0)
|
||||
{
|
||||
var compareWithWorktree = new MenuItem();
|
||||
compareWithWorktree.Header = App.Text("BranchCM.CompareWithWorktree");
|
||||
compareWithWorktree.Icon = App.CreateMenuIcon("Icons.Compare");
|
||||
compareWithWorktree.Click += (o, e) =>
|
||||
{
|
||||
SearchResultSelectedCommit = null;
|
||||
|
||||
if (_histories != null)
|
||||
{
|
||||
var target = new Commands.QuerySingleCommit(FullPath, branch.Head).Result();
|
||||
_histories.AutoSelectedCommit = null;
|
||||
_histories.DetailContext = new RevisionCompare(FullPath, target, null);
|
||||
}
|
||||
};
|
||||
menu.Items.Add(compareWithWorktree);
|
||||
}
|
||||
|
||||
menu.Items.Add(new MenuItem() { Header = "-" });
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,6 +10,11 @@ using CommunityToolkit.Mvvm.ComponentModel;
|
|||
|
||||
namespace SourceGit.ViewModels
|
||||
{
|
||||
public class CompareTargetWorktree
|
||||
{
|
||||
public string SHA => string.Empty;
|
||||
}
|
||||
|
||||
public class RevisionCompare : ObservableObject
|
||||
{
|
||||
public Models.Commit StartPoint
|
||||
|
@ -18,7 +23,7 @@ namespace SourceGit.ViewModels
|
|||
private set;
|
||||
}
|
||||
|
||||
public Models.Commit EndPoint
|
||||
public object EndPoint
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
|
@ -51,7 +56,7 @@ namespace SourceGit.ViewModels
|
|||
else
|
||||
{
|
||||
SelectedNode = FileTreeNode.SelectByPath(_changeTree, value.Path);
|
||||
DiffContext = new DiffContext(_repo, new Models.DiffOption(StartPoint.SHA, EndPoint.SHA, value), _diffContext);
|
||||
DiffContext = new DiffContext(_repo, new Models.DiffOption(StartPoint.SHA, _endPoint, value), _diffContext);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -98,11 +103,21 @@ namespace SourceGit.ViewModels
|
|||
{
|
||||
_repo = repo;
|
||||
StartPoint = startPoint;
|
||||
EndPoint = endPoint;
|
||||
|
||||
if (endPoint == null)
|
||||
{
|
||||
EndPoint = new CompareTargetWorktree();
|
||||
_endPoint = string.Empty;
|
||||
}
|
||||
else
|
||||
{
|
||||
EndPoint = endPoint;
|
||||
_endPoint = endPoint.SHA;
|
||||
}
|
||||
|
||||
Task.Run(() =>
|
||||
{
|
||||
_changes = new Commands.CompareRevisions(_repo, startPoint.SHA, endPoint.SHA).Result();
|
||||
_changes = new Commands.CompareRevisions(_repo, startPoint.SHA, _endPoint).Result();
|
||||
|
||||
var visible = _changes;
|
||||
if (!string.IsNullOrWhiteSpace(_searchFilter))
|
||||
|
@ -162,7 +177,7 @@ namespace SourceGit.ViewModels
|
|||
diffWithMerger.Icon = App.CreateMenuIcon("Icons.Diff");
|
||||
diffWithMerger.Click += (_, ev) =>
|
||||
{
|
||||
var opt = new Models.DiffOption(StartPoint.SHA, EndPoint.SHA, change);
|
||||
var opt = new Models.DiffOption(StartPoint.SHA, _endPoint, change);
|
||||
var type = Preference.Instance.ExternalMergeToolType;
|
||||
var exec = Preference.Instance.ExternalMergeToolPath;
|
||||
|
||||
|
@ -234,6 +249,7 @@ namespace SourceGit.ViewModels
|
|||
}
|
||||
|
||||
private string _repo = string.Empty;
|
||||
private string _endPoint = string.Empty;
|
||||
private List<Models.Change> _changes = null;
|
||||
private List<Models.Change> _visibleChanges = null;
|
||||
private List<FileTreeNode> _changeTree = null;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue