Skip to content

Commit 5021131

Browse files
committed
feature: supports --no-verify option while committing (#1762)
Signed-off-by: leo <[email protected]>
1 parent a9565f1 commit 5021131

File tree

9 files changed

+65
-16
lines changed

9 files changed

+65
-16
lines changed

src/Commands/Commit.cs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,39 @@
11
using System.IO;
2+
using System.Text;
23
using System.Threading.Tasks;
34

45
namespace SourceGit.Commands
56
{
67
public class Commit : Command
78
{
8-
public Commit(string repo, string message, bool signOff, bool amend, bool resetAuthor)
9+
public Commit(string repo, string message, bool signOff, bool noVerify, bool amend, bool resetAuthor)
910
{
1011
_tmpFile = Path.GetTempFileName();
1112
_message = message;
1213

1314
WorkingDirectory = repo;
1415
Context = repo;
15-
Args = $"commit --allow-empty --file={_tmpFile.Quoted()}";
16+
17+
var builder = new StringBuilder();
18+
builder.Append("commit --allow-empty --file=");
19+
builder.Append(_tmpFile.Quoted());
20+
builder.Append(' ');
21+
1622
if (signOff)
17-
Args += " --signoff";
23+
builder.Append("--signoff ");
24+
25+
if (noVerify)
26+
builder.Append("--no-verify ");
27+
1828
if (amend)
19-
Args += resetAuthor ? " --amend --reset-author --no-edit" : " --amend --no-edit";
29+
{
30+
builder.Append("--amend ");
31+
if (resetAuthor)
32+
builder.Append("--reset-author ");
33+
builder.Append("--no-edit");
34+
}
35+
36+
Args = builder.ToString();
2037
}
2138

2239
public async Task<bool> RunAsync()

src/Models/RepositorySettings.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,12 @@ public bool EnableSignOffForCommit
158158
set;
159159
} = false;
160160

161+
public bool NoVerifyOnCommit
162+
{
163+
get;
164+
set;
165+
} = false;
166+
161167
public bool IncludeUntrackedWhenStash
162168
{
163169
get;

src/Resources/Locales/en_US.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,7 @@
860860
<x:String x:Key="Text.WorkingCopy.IncludeUntracked" xml:space="preserve">INCLUDE UNTRACKED FILES</x:String>
861861
<x:String x:Key="Text.WorkingCopy.NoCommitHistories" xml:space="preserve">NO RECENT INPUT MESSAGES</x:String>
862862
<x:String x:Key="Text.WorkingCopy.NoCommitTemplates" xml:space="preserve">NO COMMIT TEMPLATES</x:String>
863+
<x:String x:Key="Text.WorkingCopy.NoVerify" xml:space="preserve">No-Verify</x:String>
863864
<x:String x:Key="Text.WorkingCopy.ResetAuthor" xml:space="preserve">Reset Author</x:String>
864865
<x:String x:Key="Text.WorkingCopy.SignOff" xml:space="preserve">SignOff</x:String>
865866
<x:String x:Key="Text.WorkingCopy.Staged" xml:space="preserve">STAGED</x:String>

src/Resources/Locales/zh_CN.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -864,6 +864,7 @@
864864
<x:String x:Key="Text.WorkingCopy.IncludeUntracked" xml:space="preserve">显示未跟踪文件</x:String>
865865
<x:String x:Key="Text.WorkingCopy.NoCommitHistories" xml:space="preserve">没有提交信息记录</x:String>
866866
<x:String x:Key="Text.WorkingCopy.NoCommitTemplates" xml:space="preserve">没有可应用的提交信息模板</x:String>
867+
<x:String x:Key="Text.WorkingCopy.NoVerify" xml:space="preserve">跳过GIT钩子</x:String>
867868
<x:String x:Key="Text.WorkingCopy.ResetAuthor" xml:space="preserve">重置提交者</x:String>
868869
<x:String x:Key="Text.WorkingCopy.SignOff" xml:space="preserve">署名</x:String>
869870
<x:String x:Key="Text.WorkingCopy.Staged" xml:space="preserve">已暂存</x:String>

src/Resources/Locales/zh_TW.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -864,6 +864,7 @@
864864
<x:String x:Key="Text.WorkingCopy.IncludeUntracked" xml:space="preserve">顯示未追蹤檔案</x:String>
865865
<x:String x:Key="Text.WorkingCopy.NoCommitHistories" xml:space="preserve">沒有提交訊息記錄</x:String>
866866
<x:String x:Key="Text.WorkingCopy.NoCommitTemplates" xml:space="preserve">沒有可套用的提交訊息範本</x:String>
867+
<x:String x:Key="Text.WorkingCopy.NoVerify" xml:space="preserve">繞過 HOOKS 檢查</x:String>
867868
<x:String x:Key="Text.WorkingCopy.ResetAuthor" xml:space="preserve">重設作者</x:String>
868869
<x:String x:Key="Text.WorkingCopy.SignOff" xml:space="preserve">署名</x:String>
869870
<x:String x:Key="Text.WorkingCopy.Staged" xml:space="preserve">已暫存</x:String>

src/ViewModels/Reword.cs

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

4040
var changes = await new Commands.QueryLocalChanges(_repo.FullPath, false).GetResultAsync();
4141
var signOff = _repo.Settings.EnableSignOffForCommit;
42+
var noVerify = _repo.Settings.NoVerifyOnCommit;
4243
var needAutoStash = false;
4344
var succ = false;
4445

@@ -64,7 +65,7 @@ public override async Task<bool> Sure()
6465
}
6566
}
6667

67-
succ = await new Commands.Commit(_repo.FullPath, _message, signOff, true, false)
68+
succ = await new Commands.Commit(_repo.FullPath, _message, signOff, noVerify, true, false)
6869
.Use(log)
6970
.RunAsync();
7071

src/ViewModels/Squash.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public override async Task<bool> Sure()
3434

3535
var changes = await new Commands.QueryLocalChanges(_repo.FullPath, false).GetResultAsync();
3636
var signOff = _repo.Settings.EnableSignOffForCommit;
37+
var noVerify = _repo.Settings.NoVerifyOnCommit;
3738
var needAutoStash = false;
3839
var succ = false;
3940

@@ -64,7 +65,7 @@ public override async Task<bool> Sure()
6465
.ExecAsync();
6566

6667
if (succ)
67-
succ = await new Commands.Commit(_repo.FullPath, _message, signOff, true, false)
68+
succ = await new Commands.Commit(_repo.FullPath, _message, signOff, noVerify, true, false)
6869
.Use(log)
6970
.RunAsync();
7071

src/ViewModels/WorkingCopy.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ public bool EnableSignOff
7171
set => _repo.Settings.EnableSignOffForCommit = value;
7272
}
7373

74+
public bool NoVerifyOnCommit
75+
{
76+
get => _repo.Settings.NoVerifyOnCommit;
77+
set => _repo.Settings.NoVerifyOnCommit = value;
78+
}
79+
7480
public bool UseAmend
7581
{
7682
get => _useAmend;
@@ -667,14 +673,19 @@ public async Task CommitAsync(bool autoStage, bool autoPush, Models.CommitCheckP
667673
_repo.Settings.PushCommitMessage(_commitMessage);
668674
_repo.SetWatcherEnabled(false);
669675

670-
var signOff = _repo.Settings.EnableSignOffForCommit;
671676
var log = _repo.CreateLog("Commit");
672677
var succ = true;
673678
if (autoStage && _unstaged.Count > 0)
674-
succ = await new Commands.Add(_repo.FullPath, _repo.IncludeUntracked).Use(log).ExecAsync().ConfigureAwait(false);
679+
succ = await new Commands.Add(_repo.FullPath, _repo.IncludeUntracked)
680+
.Use(log)
681+
.ExecAsync()
682+
.ConfigureAwait(false);
675683

676684
if (succ)
677-
succ = await new Commands.Commit(_repo.FullPath, _commitMessage, signOff, _useAmend, _resetAuthor).Use(log).RunAsync().ConfigureAwait(false);
685+
succ = await new Commands.Commit(_repo.FullPath, _commitMessage, EnableSignOff, NoVerifyOnCommit, _useAmend, _resetAuthor)
686+
.Use(log)
687+
.RunAsync()
688+
.ConfigureAwait(false);
678689

679690
log.Complete();
680691

src/Views/WorkingCopy.axaml

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@
244244
<v:CommitMessageTextBox Grid.Row="2" ShowAdvancedOptions="True" Text="{Binding CommitMessage, Mode=TwoWay}"/>
245245

246246
<!-- Commit Options -->
247-
<Grid Grid.Row="3" Margin="0,6,0,0" ColumnDefinitions="Auto,Auto,Auto,*,Auto,Auto,Auto">
247+
<Grid Grid.Row="3" Margin="0,6,0,0" ColumnDefinitions="Auto,Auto,Auto,Auto,*,Auto,Auto,Auto">
248248
<CheckBox Grid.Column="0"
249249
Height="24"
250250
Margin="1,0,0,0"
@@ -256,6 +256,16 @@
256256
ToolTip.VerticalOffset="0"/>
257257

258258
<CheckBox Grid.Column="1"
259+
Height="24"
260+
Margin="12,0,0,0"
261+
HorizontalAlignment="Left"
262+
IsChecked="{Binding NoVerifyOnCommit, Mode=TwoWay}"
263+
Content="{DynamicResource Text.WorkingCopy.NoVerify}"
264+
ToolTip.Tip="--no-verify"
265+
ToolTip.Placement="Top"
266+
ToolTip.VerticalOffset="0"/>
267+
268+
<CheckBox Grid.Column="2"
259269
Height="24"
260270
Margin="12,0,0,0"
261271
HorizontalAlignment="Left"
@@ -265,7 +275,7 @@
265275
ToolTip.Placement="Top"
266276
ToolTip.VerticalOffset="0"/>
267277

268-
<CheckBox Grid.Column="2"
278+
<CheckBox Grid.Column="3"
269279
Height="24"
270280
Margin="12,0,0,0"
271281
HorizontalAlignment="Left"
@@ -276,12 +286,12 @@
276286
ToolTip.Placement="Top"
277287
ToolTip.VerticalOffset="0"/>
278288

279-
<v:LoadingIcon Grid.Column="3"
289+
<v:LoadingIcon Grid.Column="4"
280290
Width="18" Height="18"
281291
HorizontalAlignment="Right"
282292
IsVisible="{Binding IsCommitting}"/>
283293

284-
<SplitButton Grid.Column="4"
294+
<SplitButton Grid.Column="5"
285295
Content="{DynamicResource Text.Repository.Continue}"
286296
Height="28"
287297
Margin="8,0,0,0"
@@ -303,7 +313,7 @@
303313
</SplitButton.Flyout>
304314
</SplitButton>
305315

306-
<Button Grid.Column="4"
316+
<Button Grid.Column="5"
307317
Classes="flat primary"
308318
Content="{DynamicResource Text.WorkingCopy.Commit}"
309319
Height="28"
@@ -336,7 +346,7 @@
336346
</Button>
337347

338348
<!-- Invisible button just to add another hotkey `Ctrl+Shift+Enter` to commit with auto-stage -->
339-
<Button Grid.Column="5"
349+
<Button Grid.Column="6"
340350
Width="0" Height="0"
341351
Background="Transparent"
342352
Click="OnCommitWithAutoStage"
@@ -349,7 +359,7 @@
349359
</Button.IsEnabled>
350360
</Button>
351361

352-
<Button Grid.Column="6"
362+
<Button Grid.Column="7"
353363
Classes="flat"
354364
Content="{DynamicResource Text.WorkingCopy.CommitAndPush}"
355365
Height="28"

0 commit comments

Comments
 (0)