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 <longshuang@msn.cn>
This commit is contained in:
leo 2025-02-19 10:35:34 +08:00
parent 5d2cd8b2fa
commit 59638eb731
No known key found for this signature in database
5 changed files with 25 additions and 13 deletions

View file

@ -104,6 +104,18 @@ namespace SourceGit.Models
set; set;
} = false; } = false;
public bool PushToRemoteWhenCreateTag
{
get;
set;
} = true;
public bool PushToRemoteWhenDeleteTag
{
get;
set;
} = false;
public DealWithLocalChanges DealWithLocalChangesOnCreateBranch public DealWithLocalChanges DealWithLocalChangesOnCreateBranch
{ {
get; get;

View file

@ -39,11 +39,11 @@ namespace SourceGit.ViewModels
set; set;
} = false; } = false;
public bool PushToAllRemotes public bool PushToRemotes
{ {
get; get => _repo.Settings.PushToRemoteWhenCreateTag;
set; set => _repo.Settings.PushToRemoteWhenCreateTag = value;
} = true; }
public CreateTag(Repository repo, Models.Branch branch) public CreateTag(Repository repo, Models.Branch branch)
{ {
@ -82,6 +82,7 @@ namespace SourceGit.ViewModels
_repo.SetWatcherEnabled(false); _repo.SetWatcherEnabled(false);
ProgressDescription = "Create tag..."; ProgressDescription = "Create tag...";
var remotes = PushToRemotes ? _repo.Remotes : null;
return Task.Run(() => return Task.Run(() =>
{ {
bool succ; bool succ;
@ -90,9 +91,9 @@ namespace SourceGit.ViewModels
else else
succ = Commands.Tag.Add(_repo.FullPath, _tagName, _basedOn); 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} ..."); SetProgressDescription($"Pushing tag to remote {remote.Name} ...");
new Commands.Push(_repo.FullPath, remote.Name, _tagName, false).Exec(); new Commands.Push(_repo.FullPath, remote.Name, _tagName, false).Exec();

View file

@ -10,17 +10,16 @@ namespace SourceGit.ViewModels
private set; private set;
} }
public bool ShouldPushToRemote public bool PushToRemotes
{ {
get; get => _repo.Settings.PushToRemoteWhenDeleteTag;
set; set => _repo.Settings.PushToRemoteWhenDeleteTag = value;
} }
public DeleteTag(Repository repo, Models.Tag tag) public DeleteTag(Repository repo, Models.Tag tag)
{ {
_repo = repo; _repo = repo;
Target = tag; Target = tag;
ShouldPushToRemote = true;
View = new Views.DeleteTag() { DataContext = this }; View = new Views.DeleteTag() { DataContext = this };
} }
@ -29,9 +28,9 @@ namespace SourceGit.ViewModels
_repo.SetWatcherEnabled(false); _repo.SetWatcherEnabled(false);
ProgressDescription = $"Deleting tag '{Target.Name}' ..."; ProgressDescription = $"Deleting tag '{Target.Name}' ...";
var remotes = PushToRemotes ? _repo.Remotes : null;
return Task.Run(() => return Task.Run(() =>
{ {
var remotes = ShouldPushToRemote ? _repo.Remotes : null;
var succ = Commands.Tag.Delete(_repo.FullPath, Target.Name, remotes); var succ = Commands.Tag.Delete(_repo.FullPath, Target.Name, remotes);
CallUIThread(() => CallUIThread(() =>
{ {

View file

@ -84,7 +84,7 @@
<CheckBox Grid.Row="5" Grid.Column="1" <CheckBox Grid.Row="5" Grid.Column="1"
Content="{DynamicResource Text.CreateTag.PushToAllRemotes}" Content="{DynamicResource Text.CreateTag.PushToAllRemotes}"
IsChecked="{Binding PushToAllRemotes, Mode=TwoWay}"/> IsChecked="{Binding PushToRemotes, Mode=TwoWay}"/>
</Grid> </Grid>
</StackPanel> </StackPanel>
</UserControl> </UserControl>

View file

@ -23,7 +23,7 @@
<CheckBox Grid.Row="1" Grid.Column="1" <CheckBox Grid.Row="1" Grid.Column="1"
Content="{DynamicResource Text.DeleteTag.WithRemote}" Content="{DynamicResource Text.DeleteTag.WithRemote}"
IsChecked="{Binding ShouldPushToRemote, Mode=TwoWay}"/> IsChecked="{Binding PushToRemotes, Mode=TwoWay}"/>
</Grid> </Grid>
</StackPanel> </StackPanel>
</UserControl> </UserControl>