Skip to content

Commit b556feb

Browse files
committed
enhance: tag creation & pushing (#141)
* supports creating lightweight tags * supports GPG signed tags * add option to push selected tag to all remotes
1 parent 0dea7ed commit b556feb

File tree

11 files changed

+122
-42
lines changed

11 files changed

+122
-42
lines changed

src/Commands/Tag.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,22 @@ namespace SourceGit.Commands
55
{
66
public static class Tag
77
{
8-
public static bool Add(string repo, string name, string basedOn, string message)
8+
public static bool Add(string repo, string name, string basedOn)
99
{
1010
var cmd = new Command();
1111
cmd.WorkingDirectory = repo;
1212
cmd.Context = repo;
13-
cmd.Args = $"tag -a {name} {basedOn} ";
13+
cmd.Args = $"tag {name} {basedOn}";
14+
return cmd.Exec();
15+
}
16+
17+
public static bool Add(string repo, string name, string basedOn, string message, bool sign)
18+
{
19+
var param = sign ? "-s -a" : "-a";
20+
var cmd = new Command();
21+
cmd.WorkingDirectory = repo;
22+
cmd.Context = repo;
23+
cmd.Args = $"tag {param} {name} {basedOn} ";
1424

1525
if (!string.IsNullOrEmpty(message))
1626
{

src/Resources/Locales/en_US.axaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,14 @@
114114
<x:String x:Key="Text.CreateBranch.Title" xml:space="preserve">Create Local Branch</x:String>
115115
<x:String x:Key="Text.CreateTag" xml:space="preserve">Create Tag</x:String>
116116
<x:String x:Key="Text.CreateTag.BasedOn" xml:space="preserve">New Tag At :</x:String>
117+
<x:String x:Key="Text.CreateTag.GPGSign" xml:space="preserve">Enable GPG signing</x:String>
117118
<x:String x:Key="Text.CreateTag.Message" xml:space="preserve">Tag Message :</x:String>
118119
<x:String x:Key="Text.CreateTag.Message.Placeholder" xml:space="preserve">Optional.</x:String>
119120
<x:String x:Key="Text.CreateTag.Name" xml:space="preserve">Tag Name :</x:String>
120121
<x:String x:Key="Text.CreateTag.Name.Placeholder" xml:space="preserve">Recommended format :v1.0.0-alpha</x:String>
122+
<x:String x:Key="Text.CreateTag.Type" xml:space="preserve">Kind :</x:String>
123+
<x:String x:Key="Text.CreateTag.Type.Annotated" xml:space="preserve">annotated</x:String>
124+
<x:String x:Key="Text.CreateTag.Type.Lightweight" xml:space="preserve">lightweight</x:String>
121125
<x:String x:Key="Text.Cut" xml:space="preserve">Cut</x:String>
122126
<x:String x:Key="Text.DeleteBranch" xml:space="preserve">Delete Branch</x:String>
123127
<x:String x:Key="Text.DeleteBranch.Branch" xml:space="preserve">Branch :</x:String>
@@ -312,6 +316,7 @@
312316
<x:String x:Key="Text.Push.To" xml:space="preserve">Remote Branch :</x:String>
313317
<x:String x:Key="Text.Push.WithAllTags" xml:space="preserve">Push all tags</x:String>
314318
<x:String x:Key="Text.PushTag" xml:space="preserve">Push Tag To Remote</x:String>
319+
<x:String x:Key="Text.PushTag.PushAllRemotes" xml:space="preserve">Push to all remotes</x:String>
315320
<x:String x:Key="Text.PushTag.Remote" xml:space="preserve">Remote :</x:String>
316321
<x:String x:Key="Text.PushTag.Tag" xml:space="preserve">Tag :</x:String>
317322
<x:String x:Key="Text.Quit" xml:space="preserve">Quit</x:String>

src/Resources/Locales/zh_CN.axaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,14 @@
114114
<x:String x:Key="Text.CreateBranch.Title" xml:space="preserve">创建本地分支</x:String>
115115
<x:String x:Key="Text.CreateTag" xml:space="preserve">新建标签</x:String>
116116
<x:String x:Key="Text.CreateTag.BasedOn" xml:space="preserve">标签位于 :</x:String>
117+
<x:String x:Key="Text.CreateTag.GPGSign" xml:space="preserve">使用GPG签名</x:String>
117118
<x:String x:Key="Text.CreateTag.Message" xml:space="preserve">标签描述 :</x:String>
118119
<x:String x:Key="Text.CreateTag.Message.Placeholder" xml:space="preserve">选填。</x:String>
119120
<x:String x:Key="Text.CreateTag.Name" xml:space="preserve">标签名 :</x:String>
120121
<x:String x:Key="Text.CreateTag.Name.Placeholder" xml:space="preserve">推荐格式 :v1.0.0-alpha</x:String>
122+
<x:String x:Key="Text.CreateTag.Type" xml:space="preserve">类型 :</x:String>
123+
<x:String x:Key="Text.CreateTag.Type.Annotated" xml:space="preserve">附注标签</x:String>
124+
<x:String x:Key="Text.CreateTag.Type.Lightweight" xml:space="preserve">轻量标签</x:String>
121125
<x:String x:Key="Text.Cut" xml:space="preserve">剪切</x:String>
122126
<x:String x:Key="Text.DeleteBranch" xml:space="preserve">删除分支确认</x:String>
123127
<x:String x:Key="Text.DeleteBranch.Branch" xml:space="preserve">分支名 :</x:String>
@@ -312,6 +316,7 @@
312316
<x:String x:Key="Text.Push.To" xml:space="preserve">远程分支 :</x:String>
313317
<x:String x:Key="Text.Push.WithAllTags" xml:space="preserve">同时推送标签</x:String>
314318
<x:String x:Key="Text.PushTag" xml:space="preserve">推送标签到远程仓库</x:String>
319+
<x:String x:Key="Text.PushTag.PushAllRemotes" xml:space="preserve">推送到所有远程仓库</x:String>
315320
<x:String x:Key="Text.PushTag.Remote" xml:space="preserve">远程仓库 :</x:String>
316321
<x:String x:Key="Text.PushTag.Tag" xml:space="preserve">标签 :</x:String>
317322
<x:String x:Key="Text.Quit" xml:space="preserve">退出</x:String>

src/ViewModels/CreateTag.cs

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1-
using System;
2-
using System.ComponentModel.DataAnnotations;
3-
using System.Text.RegularExpressions;
1+
using System.ComponentModel.DataAnnotations;
42
using System.Threading.Tasks;
53

64
namespace SourceGit.ViewModels
75
{
86
public class CreateTag : Popup
97
{
8+
public object BasedOn
9+
{
10+
get;
11+
private set;
12+
}
13+
1014
[Required(ErrorMessage = "Tag name is required!")]
1115
[RegularExpression(@"^[\w\-\.]+$", ErrorMessage = "Bad tag name format!")]
1216
[CustomValidation(typeof(CreateTag), nameof(ValidateTagName))]
@@ -22,12 +26,18 @@ public string Message
2226
set;
2327
}
2428

25-
public object BasedOn
29+
public bool Annotated
2630
{
27-
get;
28-
private set;
31+
get => _annotated;
32+
set => SetProperty(ref _annotated, value);
2933
}
3034

35+
public bool SignTag
36+
{
37+
get;
38+
set;
39+
} = false;
40+
3141
public CreateTag(Repository repo, Models.Branch branch)
3242
{
3343
_repo = repo;
@@ -65,14 +75,19 @@ public override Task<bool> Sure()
6575

6676
return Task.Run(() =>
6777
{
68-
Commands.Tag.Add(_repo.FullPath, TagName, _basedOn, Message);
78+
if (_annotated)
79+
Commands.Tag.Add(_repo.FullPath, _tagName, _basedOn, Message, SignTag);
80+
else
81+
Commands.Tag.Add(_repo.FullPath, _tagName, _basedOn);
82+
6983
CallUIThread(() => _repo.SetWatcherEnabled(true));
7084
return true;
7185
});
7286
}
7387

7488
private readonly Repository _repo = null;
7589
private string _tagName = string.Empty;
90+
private bool _annotated = true;
7691
private readonly string _basedOn = string.Empty;
7792
}
7893
}

src/ViewModels/PushTag.cs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ public Models.Remote SelectedRemote
2222
set;
2323
}
2424

25+
public bool PushAllRemotes
26+
{
27+
get => _pushAllRemotes;
28+
set => SetProperty(ref _pushAllRemotes, value);
29+
}
30+
2531
public PushTag(Repository repo, Models.Tag target)
2632
{
2733
_repo = repo;
@@ -37,12 +43,27 @@ public override Task<bool> Sure()
3743

3844
return Task.Run(() =>
3945
{
40-
var succ = new Commands.Push(_repo.FullPath, SelectedRemote.Name, Target.Name, false).Exec();
46+
bool succ = true;
47+
if (_pushAllRemotes)
48+
{
49+
foreach (var remote in _repo.Remotes)
50+
{
51+
succ = new Commands.Push(_repo.FullPath, remote.Name, Target.Name, false).Exec();
52+
if (!succ)
53+
break;
54+
}
55+
}
56+
else
57+
{
58+
succ = new Commands.Push(_repo.FullPath, SelectedRemote.Name, Target.Name, false).Exec();
59+
}
60+
4161
CallUIThread(() => _repo.SetWatcherEnabled(true));
4262
return succ;
4363
});
4464
}
4565

4666
private readonly Repository _repo = null;
67+
private bool _pushAllRemotes = false;
4768
}
4869
}

src/Views/ContextMenuExtension.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System;
2-
using System.ComponentModel;
1+
using System.ComponentModel;
32

43
using Avalonia.Controls;
54

src/Views/CreateTag.axaml

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<TextBlock FontSize="18"
1414
Classes="bold"
1515
Text="{DynamicResource Text.CreateTag}"/>
16-
<Grid Margin="0,16,8,0" RowDefinitions="32,32,64" ColumnDefinitions="150,*">
16+
<Grid Margin="0,16,8,0" RowDefinitions="32,32,32,Auto,Auto" ColumnDefinitions="150,*">
1717
<TextBlock Grid.Column="0"
1818
HorizontalAlignment="Right" VerticalAlignment="Center"
1919
Margin="0,0,8,0"
@@ -49,16 +49,37 @@
4949
v:AutoFocusBehaviour.IsEnabled="True"/>
5050

5151
<TextBlock Grid.Row="2" Grid.Column="0"
52+
HorizontalAlignment="Right" VerticalAlignment="Center"
53+
Margin="0,0,8,0"
54+
Text="{DynamicResource Text.CreateTag.Type}"/>
55+
<StackPanel Grid.Row="2" Grid.Column="1" Orientation="Horizontal">
56+
<RadioButton Content="{DynamicResource Text.CreateTag.Type.Annotated}"
57+
GroupName="TagKind"
58+
IsChecked="{Binding Annotated, Mode=TwoWay}"/>
59+
<RadioButton Content="{DynamicResource Text.CreateTag.Type.Lightweight}"
60+
GroupName="TagKind"
61+
Margin="8,0,0,0"/>
62+
</StackPanel>
63+
64+
<TextBlock Grid.Row="3" Grid.Column="0"
5265
HorizontalAlignment="Right" VerticalAlignment="Top"
5366
Margin="0,6,8,0"
54-
Text="{DynamicResource Text.CreateTag.Message}"/>
55-
<TextBox Grid.Row="2" Grid.Column="1"
56-
Height="56"
67+
Text="{DynamicResource Text.CreateTag.Message}"
68+
IsVisible="{Binding Annotated}"/>
69+
<TextBox Grid.Row="3" Grid.Column="1"
70+
Height="64"
5771
AcceptsReturn="True" AcceptsTab="False"
5872
VerticalAlignment="Center" VerticalContentAlignment="Top"
5973
CornerRadius="2"
6074
Watermark="{DynamicResource Text.CreateTag.Message.Placeholder}"
61-
Text="{Binding Message, Mode=TwoWay}"/>
75+
Text="{Binding Message, Mode=TwoWay}"
76+
IsVisible="{Binding Annotated}"/>
77+
78+
<CheckBox Grid.Row="4" Grid.Column="1"
79+
Height="32"
80+
Content="{DynamicResource Text.CreateTag.GPGSign}"
81+
IsChecked="{Binding SignTag, Mode=TwoWay}"
82+
IsVisible="{Binding Annotated}"/>
6283
</Grid>
6384
</StackPanel>
6485
</UserControl>

src/Views/Preference.axaml

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -396,17 +396,10 @@
396396

397397
<Grid Margin="8" RowDefinitions="32,32,32" ColumnDefinitions="Auto,*">
398398
<TextBlock Grid.Row="0" Grid.Column="0"
399-
Text="{DynamicResource Text.Preference.GPG.Enabled}"
400-
HorizontalAlignment="Right"
401-
Margin="0,0,16,0"/>
402-
<CheckBox Grid.Row="0" Grid.Column="1"
403-
IsChecked="{Binding #me.EnableGPGSigning, Mode=TwoWay}"/>
404-
405-
<TextBlock Grid.Row="1" Grid.Column="0"
406399
Text="{DynamicResource Text.Preference.GPG.Path}"
407400
HorizontalAlignment="Right"
408401
Margin="0,0,16,0"/>
409-
<TextBox Grid.Row="1" Grid.Column="1"
402+
<TextBox Grid.Row="0" Grid.Column="1"
410403
Height="28"
411404
CornerRadius="3"
412405
Text="{Binding #me.GPGExecutableFile, Mode=TwoWay}">
@@ -417,15 +410,19 @@
417410
</TextBox.InnerRightContent>
418411
</TextBox>
419412

420-
<TextBlock Grid.Row="2" Grid.Column="0"
413+
<TextBlock Grid.Row="1" Grid.Column="0"
421414
Text="{DynamicResource Text.Preference.GPG.UserKey}"
422415
HorizontalAlignment="Right"
423416
Margin="0,0,16,0"/>
424-
<TextBox Grid.Row="2" Grid.Column="1"
417+
<TextBox Grid.Row="1" Grid.Column="1"
425418
Height="28"
426419
CornerRadius="3"
427420
Text="{Binding #me.GPGUserKey, Mode=TwoWay}"
428421
Watermark="{DynamicResource Text.Preference.GPG.UserKey.Placeholder}"/>
422+
423+
<CheckBox Grid.Row="2" Grid.Column="1"
424+
Content="{DynamicResource Text.Preference.GPG.Enabled}"
425+
IsChecked="{Binding #me.EnableGPGSigning, Mode=TwoWay}"/>
429426
</Grid>
430427
</TabItem>
431428

src/Views/Preference.axaml.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,17 @@ private async void SelectDefaultCloneDir(object sender, RoutedEventArgs e)
207207

208208
private async void SelectGPGExecutable(object sender, RoutedEventArgs e)
209209
{
210-
var pattern = OperatingSystem.IsWindows() ? "gpg.exe" : "gpg";
210+
var patterns = new List<string>();
211+
if (OperatingSystem.IsWindows())
212+
patterns.Add("gpg.exe");
213+
else if (OperatingSystem.IsLinux())
214+
patterns.AddRange(new string[] { "gpg", "gpg2" });
215+
else
216+
patterns.Add("gpg");
217+
211218
var options = new FilePickerOpenOptions()
212219
{
213-
FileTypeFilter = [new FilePickerFileType("GPG Executable") { Patterns = [pattern] }],
220+
FileTypeFilter = [new FilePickerFileType("GPG Executable") { Patterns = patterns }],
214221
AllowMultiple = false,
215222
};
216223

src/Views/PushTag.axaml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<TextBlock FontSize="18"
1313
Classes="bold"
1414
Text="{DynamicResource Text.PushTag}"/>
15-
<Grid Margin="0,16,0,0" RowDefinitions="32,32" ColumnDefinitions="150,*">
15+
<Grid Margin="0,16,0,0" RowDefinitions="32,32,32" ColumnDefinitions="150,*">
1616
<TextBlock Grid.Column="0"
1717
HorizontalAlignment="Right" VerticalAlignment="Center"
1818
Margin="0,0,8,0"
@@ -31,7 +31,8 @@
3131
Height="28" Padding="8,0"
3232
VerticalAlignment="Center" HorizontalAlignment="Stretch"
3333
ItemsSource="{Binding Remotes}"
34-
SelectedItem="{Binding SelectedRemote, Mode=TwoWay}">
34+
SelectedItem="{Binding SelectedRemote, Mode=TwoWay}"
35+
IsEnabled="{Binding !PushAllRemotes}">
3536
<ComboBox.ItemTemplate>
3637
<DataTemplate x:DataType="{x:Type m:Remote}">
3738
<StackPanel Orientation="Horizontal" Height="20" VerticalAlignment="Center">
@@ -41,6 +42,10 @@
4142
</DataTemplate>
4243
</ComboBox.ItemTemplate>
4344
</ComboBox>
45+
46+
<CheckBox Grid.Row="2" Grid.Column="1"
47+
Content="{DynamicResource Text.PushTag.PushAllRemotes}"
48+
IsChecked="{Binding PushAllRemotes, Mode=TwoWay}"/>
4449
</Grid>
4550
</StackPanel>
4651
</UserControl>

0 commit comments

Comments
 (0)