Skip to content

Commit 06fd49b

Browse files
committed
feature: support --signoff for git commit command (#591)
Signed-off-by: leo <[email protected]>
1 parent b9d7f90 commit 06fd49b

File tree

10 files changed

+48
-9
lines changed

10 files changed

+48
-9
lines changed

src/Commands/Commit.cs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,37 @@ namespace SourceGit.Commands
44
{
55
public class Commit : Command
66
{
7-
public Commit(string repo, string message, bool amend)
7+
public Commit(string repo, string message, bool amend, bool signOff)
88
{
9-
var file = Path.GetTempFileName();
10-
File.WriteAllText(file, message);
9+
_tmpFile = Path.GetTempFileName();
10+
File.WriteAllText(_tmpFile, message);
1111

1212
WorkingDirectory = repo;
1313
Context = repo;
1414
TraitErrorAsOutput = true;
15-
Args = $"commit --allow-empty --file=\"{file}\"";
15+
Args = $"commit --allow-empty --file=\"{_tmpFile}\"";
1616
if (amend)
1717
Args += " --amend --no-edit";
18+
if (signOff)
19+
Args += " --signoff";
1820
}
21+
22+
public bool Run()
23+
{
24+
var succ = Exec();
25+
26+
try
27+
{
28+
File.Delete(_tmpFile);
29+
}
30+
catch
31+
{
32+
// Ignore
33+
}
34+
35+
return succ;
36+
}
37+
38+
private string _tmpFile = string.Empty;
1939
}
2040
}

src/Models/RepositorySettings.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,12 @@ public int AutoFetchInterval
106106
set;
107107
} = 10;
108108

109+
public bool EnableSignOffForCommit
110+
{
111+
get;
112+
set;
113+
} = false;
114+
109115
public void PushCommitMessage(string message)
110116
{
111117
var existIdx = CommitMessages.IndexOf(message);

src/Resources/Locales/en_US.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@
143143
<x:String x:Key="Text.Configure.Git.AutoFetch" xml:space="preserve">Fetch remotes automatically</x:String>
144144
<x:String x:Key="Text.Configure.Git.AutoFetchIntervalSuffix" xml:space="preserve">Minute(s)</x:String>
145145
<x:String x:Key="Text.Configure.Git.DefaultRemote" xml:space="preserve">Default Remote</x:String>
146+
<x:String x:Key="Text.Configure.Git.EnableSignOff" xml:space="preserve">Enable --signoff for commit</x:String>
146147
<x:String x:Key="Text.Configure.IssueTracker" xml:space="preserve">ISSUE TRACKER</x:String>
147148
<x:String x:Key="Text.Configure.IssueTracker.AddSampleGithub" xml:space="preserve">Add Sample Github Rule</x:String>
148149
<x:String x:Key="Text.Configure.IssueTracker.AddSampleJira" xml:space="preserve">Add Sample Jira Rule</x:String>

src/Resources/Locales/zh_CN.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@
146146
<x:String x:Key="Text.Configure.Git.AutoFetch" xml:space="preserve">启用定时自动拉取远程更新</x:String>
147147
<x:String x:Key="Text.Configure.Git.AutoFetchIntervalSuffix" xml:space="preserve">分钟</x:String>
148148
<x:String x:Key="Text.Configure.Git.DefaultRemote" xml:space="preserve">默认远程</x:String>
149+
<x:String x:Key="Text.Configure.Git.EnableSignOff" xml:space="preserve">提交信息追加署名 (--signoff)</x:String>
149150
<x:String x:Key="Text.Configure.IssueTracker" xml:space="preserve">ISSUE追踪</x:String>
150151
<x:String x:Key="Text.Configure.IssueTracker.AddSampleGithub" xml:space="preserve">新增匹配Github Issue规则</x:String>
151152
<x:String x:Key="Text.Configure.IssueTracker.AddSampleJira" xml:space="preserve">新增匹配Jira规则</x:String>

src/Resources/Locales/zh_TW.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@
146146
<x:String x:Key="Text.Configure.Git.AutoFetch" xml:space="preserve">啟用定時自動提取 (fetch) 遠端更新</x:String>
147147
<x:String x:Key="Text.Configure.Git.AutoFetchIntervalSuffix" xml:space="preserve">分鐘</x:String>
148148
<x:String x:Key="Text.Configure.Git.DefaultRemote" xml:space="preserve">預設遠端存放庫</x:String>
149+
<x:String x:Key="Text.Configure.Git.EnableSignOff" xml:space="preserve">提交資訊追加署名 (--signoff)</x:String>
149150
<x:String x:Key="Text.Configure.IssueTracker" xml:space="preserve">Issue 追蹤</x:String>
150151
<x:String x:Key="Text.Configure.IssueTracker.AddSampleGithub" xml:space="preserve">新增符合 GitHub Issue 規則</x:String>
151152
<x:String x:Key="Text.Configure.IssueTracker.AddSampleJira" xml:space="preserve">新增符合 Jira 規則</x:String>

src/ViewModels/RepositoryConfigure.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ public string HttpProxy
6060
set => SetProperty(ref _httpProxy, value);
6161
}
6262

63+
public bool EnableSignOffForCommit
64+
{
65+
get => _repo.Settings.EnableSignOffForCommit;
66+
set => _repo.Settings.EnableSignOffForCommit = value;
67+
}
68+
6369
public bool EnableAutoFetch
6470
{
6571
get => _repo.Settings.EnableAutoFetch;

src/ViewModels/Reword.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public override Task<bool> Sure()
3939

4040
return Task.Run(() =>
4141
{
42-
var succ = new Commands.Commit(_repo.FullPath, _message, true).Exec();
42+
var succ = new Commands.Commit(_repo.FullPath, _message, true, _repo.Settings.EnableSignOffForCommit).Run();
4343
CallUIThread(() => _repo.SetWatcherEnabled(true));
4444
return succ;
4545
});

src/ViewModels/Squash.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public override Task<bool> Sure()
3535
{
3636
var succ = new Commands.Reset(_repo.FullPath, Target.SHA, "--soft").Exec();
3737
if (succ)
38-
succ = new Commands.Commit(_repo.FullPath, _message, true).Exec();
38+
succ = new Commands.Commit(_repo.FullPath, _message, true, _repo.Settings.EnableSignOffForCommit).Run();
3939
CallUIThread(() => _repo.SetWatcherEnabled(true));
4040
return succ;
4141
});

src/ViewModels/WorkingCopy.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1311,7 +1311,7 @@ private void DoCommit(bool autoStage, bool autoPush, bool allowEmpty)
13111311
succ = new Commands.Add(_repo.FullPath, _repo.IncludeUntracked).Exec();
13121312

13131313
if (succ)
1314-
succ = new Commands.Commit(_repo.FullPath, _commitMessage, _useAmend).Exec();
1314+
succ = new Commands.Commit(_repo.FullPath, _commitMessage, _useAmend, _repo.Settings.EnableSignOffForCommit).Run();
13151315

13161316
Dispatcher.UIThread.Post(() =>
13171317
{

src/Views/RepositoryConfigure.axaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
<TextBlock Classes="tab_header" Text="{DynamicResource Text.Configure.Git}"/>
5252
</TabItem.Header>
5353

54-
<Grid Margin="16,4,16,8" RowDefinitions="32,32,32,32,32,32,32,32" ColumnDefinitions="Auto,*">
54+
<Grid Margin="16,4,16,8" RowDefinitions="32,32,32,32,32,32,32,32,32" ColumnDefinitions="Auto,*">
5555
<TextBlock Grid.Row="0" Grid.Column="0"
5656
HorizontalAlignment="Right" VerticalAlignment="Center"
5757
Margin="0,0,8,0"
@@ -123,10 +123,14 @@
123123
IsChecked="{Binding GPGCommitSigningEnabled, Mode=TwoWay}"/>
124124

125125
<CheckBox Grid.Row="6" Grid.Column="1"
126+
Content="{DynamicResource Text.Configure.Git.EnableSignOff}"
127+
IsChecked="{Binding EnableSignOffForCommit, Mode=TwoWay}"/>
128+
129+
<CheckBox Grid.Row="7" Grid.Column="1"
126130
Content="{DynamicResource Text.Preference.GPG.TagEnabled}"
127131
IsChecked="{Binding GPGTagSigningEnabled, Mode=TwoWay}"/>
128132

129-
<StackPanel Grid.Row="7" Grid.Column="1" Orientation="Horizontal">
133+
<StackPanel Grid.Row="8" Grid.Column="1" Orientation="Horizontal">
130134
<CheckBox x:Name="AutoFetchCheckBox"
131135
Content="{DynamicResource Text.Configure.Git.AutoFetch}"
132136
IsChecked="{Binding EnableAutoFetch, Mode=TwoWay}"/>

0 commit comments

Comments
 (0)