Skip to content

Commit 0641a22

Browse files
committed
feature: allow to reset author when --amend is enabled for committing
1 parent d3bc854 commit 0641a22

File tree

8 files changed

+38
-12
lines changed

8 files changed

+38
-12
lines changed

src/Commands/Commit.cs

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

1212
WorkingDirectory = repo;
1313
Context = repo;
1414
Args = $"commit --allow-empty --file=\"{_tmpFile}\"";
15-
if (amend)
16-
Args += " --amend --no-edit";
1715
if (signOff)
1816
Args += " --signoff";
17+
if (amend)
18+
Args += resetAuthor ? " --amend --reset-author --no-edit" : " --amend --no-edit";
1919
}
2020

2121
public bool Run()

src/Resources/Locales/en_US.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,7 @@
781781
<x:String x:Key="Text.WorkingCopy.IncludeUntracked" xml:space="preserve">INCLUDE UNTRACKED FILES</x:String>
782782
<x:String x:Key="Text.WorkingCopy.NoCommitHistories" xml:space="preserve">NO RECENT INPUT MESSAGES</x:String>
783783
<x:String x:Key="Text.WorkingCopy.NoCommitTemplates" xml:space="preserve">NO COMMIT TEMPLATES</x:String>
784+
<x:String x:Key="Text.WorkingCopy.ResetAuthor" xml:space="preserve">Reset Author</x:String>
784785
<x:String x:Key="Text.WorkingCopy.ResolveTip" xml:space="preserve">Right-click the selected file(s), and make your choice to resolve conflicts.</x:String>
785786
<x:String x:Key="Text.WorkingCopy.SignOff" xml:space="preserve">SignOff</x:String>
786787
<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
@@ -785,6 +785,7 @@
785785
<x:String x:Key="Text.WorkingCopy.IncludeUntracked" xml:space="preserve">显示未跟踪文件</x:String>
786786
<x:String x:Key="Text.WorkingCopy.NoCommitHistories" xml:space="preserve">没有提交信息记录</x:String>
787787
<x:String x:Key="Text.WorkingCopy.NoCommitTemplates" xml:space="preserve">没有可应用的提交信息模板</x:String>
788+
<x:String x:Key="Text.WorkingCopy.ResetAuthor" xml:space="preserve">重置提交者</x:String>
788789
<x:String x:Key="Text.WorkingCopy.ResolveTip" xml:space="preserve">请选中冲突文件,打开右键菜单,选择合适的解决方式</x:String>
789790
<x:String x:Key="Text.WorkingCopy.SignOff" xml:space="preserve">署名</x:String>
790791
<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
@@ -785,6 +785,7 @@
785785
<x:String x:Key="Text.WorkingCopy.IncludeUntracked" xml:space="preserve">顯示未追蹤檔案</x:String>
786786
<x:String x:Key="Text.WorkingCopy.NoCommitHistories" xml:space="preserve">沒有提交訊息記錄</x:String>
787787
<x:String x:Key="Text.WorkingCopy.NoCommitTemplates" xml:space="preserve">沒有可套用的提交訊息範本</x:String>
788+
<x:String x:Key="Text.WorkingCopy.ResetAuthor" xml:space="preserve">重設作者</x:String>
788789
<x:String x:Key="Text.WorkingCopy.ResolveTip" xml:space="preserve">請選擇發生衝突的檔案,開啟右鍵選單,選擇合適的解決方式</x:String>
789790
<x:String x:Key="Text.WorkingCopy.SignOff" xml:space="preserve">署名</x:String>
790791
<x:String x:Key="Text.WorkingCopy.Staged" xml:space="preserve">已暫存</x:String>

src/ViewModels/Reword.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,11 @@ public override Task<bool> Sure()
3737
var log = _repo.CreateLog("Reword HEAD");
3838
Use(log);
3939

40+
var signOff = _repo.Settings.EnableSignOffForCommit;
4041
return Task.Run(() =>
4142
{
42-
var succ = new Commands.Commit(_repo.FullPath, _message, true, _repo.Settings.EnableSignOffForCommit).Use(log).Run();
43+
// For reword (only changes the commit message), disable `--reset-author`
44+
var succ = new Commands.Commit(_repo.FullPath, _message, signOff, true, false).Use(log).Run();
4345
log.Complete();
4446
CallUIThread(() => _repo.SetWatcherEnabled(true));
4547
return succ;

src/ViewModels/Squash.cs

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

3535
return Task.Run(() =>
3636
{
37+
var signOff = _repo.Settings.EnableSignOffForCommit;
3738
var autoStashed = false;
3839
var succ = false;
3940

@@ -52,7 +53,7 @@ public override Task<bool> Sure()
5253

5354
succ = new Commands.Reset(_repo.FullPath, Target.SHA, "--soft").Use(log).Exec();
5455
if (succ)
55-
succ = new Commands.Commit(_repo.FullPath, _message, true, _repo.Settings.EnableSignOffForCommit).Use(log).Run();
56+
succ = new Commands.Commit(_repo.FullPath, _message, signOff, true, true).Use(log).Run();
5657

5758
if (succ && autoStashed)
5859
new Commands.Stash(_repo.FullPath).Use(log).Pop("stash@{0}");

src/ViewModels/WorkingCopy.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ public bool UseAmend
9191
else
9292
{
9393
CommitMessage = string.Empty;
94+
ResetAuthor = false;
9495
}
9596

9697
Staged = GetStagedChanges();
@@ -100,6 +101,12 @@ public bool UseAmend
100101
}
101102
}
102103

104+
public bool ResetAuthor
105+
{
106+
get => _resetAuthor;
107+
set => SetProperty(ref _resetAuthor, value);
108+
}
109+
103110
public string Filter
104111
{
105112
get => _filter;
@@ -1717,6 +1724,7 @@ private void DoCommit(bool autoStage, bool autoPush, bool allowEmpty = false, bo
17171724
_repo.Settings.PushCommitMessage(_commitMessage);
17181725
_repo.SetWatcherEnabled(false);
17191726

1727+
var signOff = _repo.Settings.EnableSignOffForCommit;
17201728
var log = _repo.CreateLog("Commit");
17211729
Task.Run(() =>
17221730
{
@@ -1725,7 +1733,7 @@ private void DoCommit(bool autoStage, bool autoPush, bool allowEmpty = false, bo
17251733
succ = new Commands.Add(_repo.FullPath, _repo.IncludeUntracked).Use(log).Exec();
17261734

17271735
if (succ)
1728-
succ = new Commands.Commit(_repo.FullPath, _commitMessage, _useAmend, _repo.Settings.EnableSignOffForCommit).Use(log).Run();
1736+
succ = new Commands.Commit(_repo.FullPath, _commitMessage, signOff, _useAmend, _resetAuthor).Use(log).Run();
17291737

17301738
log.Complete();
17311739

@@ -1785,6 +1793,7 @@ private bool IsChanged(List<Models.Change> old, List<Models.Change> cur)
17851793
private bool _isUnstaging = false;
17861794
private bool _isCommitting = false;
17871795
private bool _useAmend = false;
1796+
private bool _resetAuthor = false;
17881797
private bool _hasRemotes = false;
17891798
private List<Models.Change> _cached = [];
17901799
private List<Models.Change> _unstaged = [];

src/Views/WorkingCopy.axaml

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

237237
<!-- Commit Options -->
238-
<Grid Grid.Row="3" Margin="0,6,0,0" ColumnDefinitions="Auto,Auto,*,Auto,Auto,Auto">
238+
<Grid Grid.Row="3" Margin="0,6,0,0" ColumnDefinitions="Auto,Auto,Auto,*,Auto,Auto,Auto">
239239
<CheckBox Grid.Column="0"
240240
Height="24"
241241
Margin="1,0,0,0"
@@ -256,12 +256,23 @@
256256
ToolTip.Placement="Top"
257257
ToolTip.VerticalOffset="0"/>
258258

259-
<v:LoadingIcon Grid.Column="2"
259+
<CheckBox Grid.Column="2"
260+
Height="24"
261+
Margin="12,0,0,0"
262+
HorizontalAlignment="Left"
263+
IsChecked="{Binding ResetAuthor, Mode=TwoWay}"
264+
IsVisible="{Binding UseAmend}"
265+
Content="{DynamicResource Text.WorkingCopy.ResetAuthor}"
266+
ToolTip.Tip="--reset-author"
267+
ToolTip.Placement="Top"
268+
ToolTip.VerticalOffset="0"/>
269+
270+
<v:LoadingIcon Grid.Column="3"
260271
Width="18" Height="18"
261272
HorizontalAlignment="Right"
262273
IsVisible="{Binding IsCommitting}"/>
263274

264-
<SplitButton Grid.Column="3"
275+
<SplitButton Grid.Column="4"
265276
Content="{DynamicResource Text.Repository.Continue}"
266277
Height="28"
267278
Margin="8,0,0,0"
@@ -283,7 +294,7 @@
283294
</SplitButton.Flyout>
284295
</SplitButton>
285296

286-
<Button Grid.Column="3"
297+
<Button Grid.Column="4"
287298
Classes="flat primary"
288299
Content="{DynamicResource Text.WorkingCopy.Commit}"
289300
Height="28"
@@ -316,7 +327,7 @@
316327
</Button>
317328

318329
<!-- Invisible button just to add another hotkey `Ctrl+Shift+Enter` to commit with auto-stage -->
319-
<Button Grid.Column="4"
330+
<Button Grid.Column="5"
320331
Width="0" Height="0"
321332
Background="Transparent"
322333
Command="{Binding CommitWithAutoStage}"
@@ -329,7 +340,7 @@
329340
</Button.IsEnabled>
330341
</Button>
331342

332-
<Button Grid.Column="5"
343+
<Button Grid.Column="6"
333344
Classes="flat"
334345
Content="{DynamicResource Text.WorkingCopy.CommitAndPush}"
335346
Height="28"

0 commit comments

Comments
 (0)