code_review: PR #793

* do NOT modify the existing merge, and add a new constructor for `Commands.Merge` instead
* rewrite `ViewModels.MergeMultiple`
  - since `_histories.Commits.Find` may returns null, use `List<object>` instead of `List<Models.Commits>`
  - supports display merge target as both `Models.Commit` and `Models.Branch`
* rename translation key `Text.MergeMultiple.Commit` to `Text.MergeMultiple.Targets`, and add translations for zh_CN and zh_TW
* some UI/UX changes
This commit is contained in:
leo 2024-12-09 21:12:58 +08:00
parent 4eed9674b4
commit 94daa46db9
No known key found for this signature in database
10 changed files with 122 additions and 40 deletions

View file

@ -1,18 +1,15 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using SourceGit.Models;
namespace SourceGit.ViewModels
{
public class MergeMultiple : Popup
{
public List<string> Strategies = ["octopus", "ours"];
public List<Commit> Targets
public List<object> Targets
{
get;
private set;
}
} = [];
public bool AutoCommit
{
@ -20,18 +17,27 @@ namespace SourceGit.ViewModels
set;
}
public MergeStrategy Strategy
public Models.MergeStrategy Strategy
{
get;
set;
}
public MergeMultiple(Repository repo, List<Commit> targets)
public MergeMultiple(Repository repo, List<Models.Commit> commits)
{
_repo = repo;
Targets = targets;
Targets.AddRange(commits);
AutoCommit = true;
Strategy = MergeStrategy.ForMultiple.Find(s => s.Arg == null);
Strategy = Models.MergeStrategy.ForMultiple[0];
View = new Views.MergeMultiple() { DataContext = this };
}
public MergeMultiple(Repository repo, List<Models.Branch> branches)
{
_repo = repo;
Targets.AddRange(branches);
AutoCommit = true;
Strategy = Models.MergeStrategy.ForMultiple[0];
View = new Views.MergeMultiple() { DataContext = this };
}
@ -44,9 +50,9 @@ namespace SourceGit.ViewModels
{
var succ = new Commands.Merge(
_repo.FullPath,
string.Join(" ", Targets.ConvertAll(c => c.Decorators.Find(d => d.Type == DecoratorType.RemoteBranchHead || d.Type == DecoratorType.LocalBranchHead)?.Name ?? c.Decorators.Find(d => d.Type == DecoratorType.Tag)?.Name ?? c.SHA)),
AutoCommit ? string.Empty : "--no-commit",
Strategy?.Arg,
ConvertTargetToMergeSources(),
AutoCommit,
Strategy.Arg,
SetProgressDescription).Exec();
CallUIThread(() => _repo.SetWatcherEnabled(true));
@ -54,6 +60,34 @@ namespace SourceGit.ViewModels
});
}
private List<string> ConvertTargetToMergeSources()
{
var ret = new List<string>();
foreach (var t in Targets)
{
if (t is Models.Branch branch)
{
ret.Add(branch.FriendlyName);
}
else if (t is Models.Commit commit)
{
var d = commit.Decorators.Find(x =>
{
return x.Type == Models.DecoratorType.LocalBranchHead ||
x.Type == Models.DecoratorType.RemoteBranchHead ||
x.Type == Models.DecoratorType.Tag;
});
if (d != null)
ret.Add(d.Name);
else
ret.Add(commit.SHA);
}
}
return ret;
}
private readonly Repository _repo = null;
}
}