From 59638eb73159d60cb103a7bb58a5cee4511e95db Mon Sep 17 00:00:00 2001 From: leo Date: Wed, 19 Feb 2025 10:35:34 +0800 Subject: [PATCH] enhance: tag push behavior while creating and deleting (#999) - Remember the state of `Push to all remotes after created` checkbox while creating tag - Remember the state of `Delete from remote repositories` checkbox while deleting tag - Change default state of `Delete from remote repositories` to `false` Signed-off-by: leo --- src/Models/RepositorySettings.cs | 12 ++++++++++++ src/ViewModels/CreateTag.cs | 13 +++++++------ src/ViewModels/DeleteTag.cs | 9 ++++----- src/Views/CreateTag.axaml | 2 +- src/Views/DeleteTag.axaml | 2 +- 5 files changed, 25 insertions(+), 13 deletions(-) diff --git a/src/Models/RepositorySettings.cs b/src/Models/RepositorySettings.cs index 556c99ea..44742fb8 100644 --- a/src/Models/RepositorySettings.cs +++ b/src/Models/RepositorySettings.cs @@ -104,6 +104,18 @@ namespace SourceGit.Models set; } = false; + public bool PushToRemoteWhenCreateTag + { + get; + set; + } = true; + + public bool PushToRemoteWhenDeleteTag + { + get; + set; + } = false; + public DealWithLocalChanges DealWithLocalChangesOnCreateBranch { get; diff --git a/src/ViewModels/CreateTag.cs b/src/ViewModels/CreateTag.cs index af9dcf99..a6d7255b 100644 --- a/src/ViewModels/CreateTag.cs +++ b/src/ViewModels/CreateTag.cs @@ -39,11 +39,11 @@ namespace SourceGit.ViewModels set; } = false; - public bool PushToAllRemotes + public bool PushToRemotes { - get; - set; - } = true; + get => _repo.Settings.PushToRemoteWhenCreateTag; + set => _repo.Settings.PushToRemoteWhenCreateTag = value; + } public CreateTag(Repository repo, Models.Branch branch) { @@ -82,6 +82,7 @@ namespace SourceGit.ViewModels _repo.SetWatcherEnabled(false); ProgressDescription = "Create tag..."; + var remotes = PushToRemotes ? _repo.Remotes : null; return Task.Run(() => { bool succ; @@ -90,9 +91,9 @@ namespace SourceGit.ViewModels else succ = Commands.Tag.Add(_repo.FullPath, _tagName, _basedOn); - if (succ && PushToAllRemotes) + if (succ && remotes != null) { - foreach (var remote in _repo.Remotes) + foreach (var remote in remotes) { SetProgressDescription($"Pushing tag to remote {remote.Name} ..."); new Commands.Push(_repo.FullPath, remote.Name, _tagName, false).Exec(); diff --git a/src/ViewModels/DeleteTag.cs b/src/ViewModels/DeleteTag.cs index 7b53e798..341eb4a2 100644 --- a/src/ViewModels/DeleteTag.cs +++ b/src/ViewModels/DeleteTag.cs @@ -10,17 +10,16 @@ namespace SourceGit.ViewModels private set; } - public bool ShouldPushToRemote + public bool PushToRemotes { - get; - set; + get => _repo.Settings.PushToRemoteWhenDeleteTag; + set => _repo.Settings.PushToRemoteWhenDeleteTag = value; } public DeleteTag(Repository repo, Models.Tag tag) { _repo = repo; Target = tag; - ShouldPushToRemote = true; View = new Views.DeleteTag() { DataContext = this }; } @@ -29,9 +28,9 @@ namespace SourceGit.ViewModels _repo.SetWatcherEnabled(false); ProgressDescription = $"Deleting tag '{Target.Name}' ..."; + var remotes = PushToRemotes ? _repo.Remotes : null; return Task.Run(() => { - var remotes = ShouldPushToRemote ? _repo.Remotes : null; var succ = Commands.Tag.Delete(_repo.FullPath, Target.Name, remotes); CallUIThread(() => { diff --git a/src/Views/CreateTag.axaml b/src/Views/CreateTag.axaml index 20b6798a..55b6052f 100644 --- a/src/Views/CreateTag.axaml +++ b/src/Views/CreateTag.axaml @@ -84,7 +84,7 @@ + IsChecked="{Binding PushToRemotes, Mode=TwoWay}"/> diff --git a/src/Views/DeleteTag.axaml b/src/Views/DeleteTag.axaml index 702a7f2a..23c19d35 100644 --- a/src/Views/DeleteTag.axaml +++ b/src/Views/DeleteTag.axaml @@ -23,7 +23,7 @@ + IsChecked="{Binding PushToRemotes, Mode=TwoWay}"/>