feature: supports to set default remote to push local branches without any tracking remotes (#534)

This commit is contained in:
leo 2024-10-02 15:13:27 +08:00
parent 6d1dfad8a1
commit d746e352a7
No known key found for this signature in database
7 changed files with 66 additions and 10 deletions

View file

@ -137,9 +137,15 @@ namespace SourceGit.ViewModels
}
}
// Set default remote to the first if haven't been set.
// Set default remote to the first if it has not been set.
if (_selectedRemote == null)
_selectedRemote = repo.Remotes[0];
{
var remote = null as Models.Remote;
if (!string.IsNullOrEmpty(_repo.Settings.DefaultRemote))
remote = repo.Remotes.Find(x => x.Name == _repo.Settings.DefaultRemote);
_selectedRemote = remote ?? repo.Remotes[0];
}
// Auto select preferred remote branch.
AutoSelectBranchByRemote();

View file

@ -18,6 +18,24 @@ namespace SourceGit.ViewModels
set;
}
public List<string> Remotes
{
get;
}
public string DefaultRemote
{
get => _repo.Settings.DefaultRemote;
set
{
if (_repo.Settings.DefaultRemote != value)
{
_repo.Settings.DefaultRemote = value;
OnPropertyChanged();
}
}
}
public bool GPGCommitSigningEnabled
{
get;
@ -88,6 +106,10 @@ namespace SourceGit.ViewModels
{
_repo = repo;
Remotes = new List<string>();
foreach (var remote in _repo.Remotes)
Remotes.Add(remote.Name);
_cached = new Commands.Config(repo.FullPath).ListAll();
if (_cached.TryGetValue("user.name", out var name))
UserName = name;