feature: the default merge option supports reading branch.<name>.mergeoptions configuration (#540)

This commit is contained in:
leo 2024-10-06 22:21:18 +08:00
parent 7262437385
commit 029f56cb28
No known key found for this signature in database

View file

@ -1,4 +1,5 @@
using System.Threading.Tasks; using System;
using System.Threading.Tasks;
namespace SourceGit.ViewModels namespace SourceGit.ViewModels
{ {
@ -7,13 +8,11 @@ namespace SourceGit.ViewModels
public string Source public string Source
{ {
get; get;
private set;
} }
public string Into public string Into
{ {
get; get;
private set;
} }
public Models.MergeMode SelectedMode public Models.MergeMode SelectedMode
@ -27,7 +26,7 @@ namespace SourceGit.ViewModels
_repo = repo; _repo = repo;
Source = source; Source = source;
Into = into; Into = into;
SelectedMode = Models.MergeMode.Supported[0]; SelectedMode = AutoSelectMergeMode();
View = new Views.Merge() { DataContext = this }; View = new Views.Merge() { DataContext = this };
} }
@ -44,6 +43,21 @@ namespace SourceGit.ViewModels
}); });
} }
private Models.MergeMode AutoSelectMergeMode()
{
var config = new Commands.Config(_repo.FullPath).Get($"branch.{Into}.mergeoptions");
if (string.IsNullOrEmpty(config))
return Models.MergeMode.Supported[0];
if (config.Equals("--no-ff", StringComparison.Ordinal))
return Models.MergeMode.Supported[1];
if (config.Equals("--squash", StringComparison.Ordinal))
return Models.MergeMode.Supported[2];
if (config.Equals("--no-commit", StringComparison.Ordinal) || config.Equals("--no-ff --no-commit", StringComparison.Ordinal))
return Models.MergeMode.Supported[3];
return Models.MergeMode.Supported[0];
}
private readonly Repository _repo = null; private readonly Repository _repo = null;
} }
} }