mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-31 09:04:59 +00:00
feature: allow to reset author when --amend
is enabled for committing
This commit is contained in:
parent
d3bc85418e
commit
0641a22230
8 changed files with 38 additions and 12 deletions
|
@ -4,7 +4,7 @@ namespace SourceGit.Commands
|
|||
{
|
||||
public class Commit : Command
|
||||
{
|
||||
public Commit(string repo, string message, bool amend, bool signOff)
|
||||
public Commit(string repo, string message, bool signOff, bool amend, bool resetAuthor)
|
||||
{
|
||||
_tmpFile = Path.GetTempFileName();
|
||||
File.WriteAllText(_tmpFile, message);
|
||||
|
@ -12,10 +12,10 @@ namespace SourceGit.Commands
|
|||
WorkingDirectory = repo;
|
||||
Context = repo;
|
||||
Args = $"commit --allow-empty --file=\"{_tmpFile}\"";
|
||||
if (amend)
|
||||
Args += " --amend --no-edit";
|
||||
if (signOff)
|
||||
Args += " --signoff";
|
||||
if (amend)
|
||||
Args += resetAuthor ? " --amend --reset-author --no-edit" : " --amend --no-edit";
|
||||
}
|
||||
|
||||
public bool Run()
|
||||
|
|
|
@ -781,6 +781,7 @@
|
|||
<x:String x:Key="Text.WorkingCopy.IncludeUntracked" xml:space="preserve">INCLUDE UNTRACKED FILES</x:String>
|
||||
<x:String x:Key="Text.WorkingCopy.NoCommitHistories" xml:space="preserve">NO RECENT INPUT MESSAGES</x:String>
|
||||
<x:String x:Key="Text.WorkingCopy.NoCommitTemplates" xml:space="preserve">NO COMMIT TEMPLATES</x:String>
|
||||
<x:String x:Key="Text.WorkingCopy.ResetAuthor" xml:space="preserve">Reset Author</x:String>
|
||||
<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>
|
||||
<x:String x:Key="Text.WorkingCopy.SignOff" xml:space="preserve">SignOff</x:String>
|
||||
<x:String x:Key="Text.WorkingCopy.Staged" xml:space="preserve">STAGED</x:String>
|
||||
|
|
|
@ -785,6 +785,7 @@
|
|||
<x:String x:Key="Text.WorkingCopy.IncludeUntracked" xml:space="preserve">显示未跟踪文件</x:String>
|
||||
<x:String x:Key="Text.WorkingCopy.NoCommitHistories" xml:space="preserve">没有提交信息记录</x:String>
|
||||
<x:String x:Key="Text.WorkingCopy.NoCommitTemplates" xml:space="preserve">没有可应用的提交信息模板</x:String>
|
||||
<x:String x:Key="Text.WorkingCopy.ResetAuthor" xml:space="preserve">重置提交者</x:String>
|
||||
<x:String x:Key="Text.WorkingCopy.ResolveTip" xml:space="preserve">请选中冲突文件,打开右键菜单,选择合适的解决方式</x:String>
|
||||
<x:String x:Key="Text.WorkingCopy.SignOff" xml:space="preserve">署名</x:String>
|
||||
<x:String x:Key="Text.WorkingCopy.Staged" xml:space="preserve">已暂存</x:String>
|
||||
|
|
|
@ -785,6 +785,7 @@
|
|||
<x:String x:Key="Text.WorkingCopy.IncludeUntracked" xml:space="preserve">顯示未追蹤檔案</x:String>
|
||||
<x:String x:Key="Text.WorkingCopy.NoCommitHistories" xml:space="preserve">沒有提交訊息記錄</x:String>
|
||||
<x:String x:Key="Text.WorkingCopy.NoCommitTemplates" xml:space="preserve">沒有可套用的提交訊息範本</x:String>
|
||||
<x:String x:Key="Text.WorkingCopy.ResetAuthor" xml:space="preserve">重設作者</x:String>
|
||||
<x:String x:Key="Text.WorkingCopy.ResolveTip" xml:space="preserve">請選擇發生衝突的檔案,開啟右鍵選單,選擇合適的解決方式</x:String>
|
||||
<x:String x:Key="Text.WorkingCopy.SignOff" xml:space="preserve">署名</x:String>
|
||||
<x:String x:Key="Text.WorkingCopy.Staged" xml:space="preserve">已暫存</x:String>
|
||||
|
|
|
@ -37,9 +37,11 @@ namespace SourceGit.ViewModels
|
|||
var log = _repo.CreateLog("Reword HEAD");
|
||||
Use(log);
|
||||
|
||||
var signOff = _repo.Settings.EnableSignOffForCommit;
|
||||
return Task.Run(() =>
|
||||
{
|
||||
var succ = new Commands.Commit(_repo.FullPath, _message, true, _repo.Settings.EnableSignOffForCommit).Use(log).Run();
|
||||
// For reword (only changes the commit message), disable `--reset-author`
|
||||
var succ = new Commands.Commit(_repo.FullPath, _message, signOff, true, false).Use(log).Run();
|
||||
log.Complete();
|
||||
CallUIThread(() => _repo.SetWatcherEnabled(true));
|
||||
return succ;
|
||||
|
|
|
@ -34,6 +34,7 @@ namespace SourceGit.ViewModels
|
|||
|
||||
return Task.Run(() =>
|
||||
{
|
||||
var signOff = _repo.Settings.EnableSignOffForCommit;
|
||||
var autoStashed = false;
|
||||
var succ = false;
|
||||
|
||||
|
@ -52,7 +53,7 @@ namespace SourceGit.ViewModels
|
|||
|
||||
succ = new Commands.Reset(_repo.FullPath, Target.SHA, "--soft").Use(log).Exec();
|
||||
if (succ)
|
||||
succ = new Commands.Commit(_repo.FullPath, _message, true, _repo.Settings.EnableSignOffForCommit).Use(log).Run();
|
||||
succ = new Commands.Commit(_repo.FullPath, _message, signOff, true, true).Use(log).Run();
|
||||
|
||||
if (succ && autoStashed)
|
||||
new Commands.Stash(_repo.FullPath).Use(log).Pop("stash@{0}");
|
||||
|
|
|
@ -91,6 +91,7 @@ namespace SourceGit.ViewModels
|
|||
else
|
||||
{
|
||||
CommitMessage = string.Empty;
|
||||
ResetAuthor = false;
|
||||
}
|
||||
|
||||
Staged = GetStagedChanges();
|
||||
|
@ -100,6 +101,12 @@ namespace SourceGit.ViewModels
|
|||
}
|
||||
}
|
||||
|
||||
public bool ResetAuthor
|
||||
{
|
||||
get => _resetAuthor;
|
||||
set => SetProperty(ref _resetAuthor, value);
|
||||
}
|
||||
|
||||
public string Filter
|
||||
{
|
||||
get => _filter;
|
||||
|
@ -1717,6 +1724,7 @@ namespace SourceGit.ViewModels
|
|||
_repo.Settings.PushCommitMessage(_commitMessage);
|
||||
_repo.SetWatcherEnabled(false);
|
||||
|
||||
var signOff = _repo.Settings.EnableSignOffForCommit;
|
||||
var log = _repo.CreateLog("Commit");
|
||||
Task.Run(() =>
|
||||
{
|
||||
|
@ -1725,7 +1733,7 @@ namespace SourceGit.ViewModels
|
|||
succ = new Commands.Add(_repo.FullPath, _repo.IncludeUntracked).Use(log).Exec();
|
||||
|
||||
if (succ)
|
||||
succ = new Commands.Commit(_repo.FullPath, _commitMessage, _useAmend, _repo.Settings.EnableSignOffForCommit).Use(log).Run();
|
||||
succ = new Commands.Commit(_repo.FullPath, _commitMessage, signOff, _useAmend, _resetAuthor).Use(log).Run();
|
||||
|
||||
log.Complete();
|
||||
|
||||
|
@ -1785,6 +1793,7 @@ namespace SourceGit.ViewModels
|
|||
private bool _isUnstaging = false;
|
||||
private bool _isCommitting = false;
|
||||
private bool _useAmend = false;
|
||||
private bool _resetAuthor = false;
|
||||
private bool _hasRemotes = false;
|
||||
private List<Models.Change> _cached = [];
|
||||
private List<Models.Change> _unstaged = [];
|
||||
|
|
|
@ -235,7 +235,7 @@
|
|||
<v:CommitMessageTextBox Grid.Row="2" ShowAdvancedOptions="True" Text="{Binding CommitMessage, Mode=TwoWay}"/>
|
||||
|
||||
<!-- Commit Options -->
|
||||
<Grid Grid.Row="3" Margin="0,6,0,0" ColumnDefinitions="Auto,Auto,*,Auto,Auto,Auto">
|
||||
<Grid Grid.Row="3" Margin="0,6,0,0" ColumnDefinitions="Auto,Auto,Auto,*,Auto,Auto,Auto">
|
||||
<CheckBox Grid.Column="0"
|
||||
Height="24"
|
||||
Margin="1,0,0,0"
|
||||
|
@ -256,12 +256,23 @@
|
|||
ToolTip.Placement="Top"
|
||||
ToolTip.VerticalOffset="0"/>
|
||||
|
||||
<v:LoadingIcon Grid.Column="2"
|
||||
<CheckBox Grid.Column="2"
|
||||
Height="24"
|
||||
Margin="12,0,0,0"
|
||||
HorizontalAlignment="Left"
|
||||
IsChecked="{Binding ResetAuthor, Mode=TwoWay}"
|
||||
IsVisible="{Binding UseAmend}"
|
||||
Content="{DynamicResource Text.WorkingCopy.ResetAuthor}"
|
||||
ToolTip.Tip="--reset-author"
|
||||
ToolTip.Placement="Top"
|
||||
ToolTip.VerticalOffset="0"/>
|
||||
|
||||
<v:LoadingIcon Grid.Column="3"
|
||||
Width="18" Height="18"
|
||||
HorizontalAlignment="Right"
|
||||
IsVisible="{Binding IsCommitting}"/>
|
||||
|
||||
<SplitButton Grid.Column="3"
|
||||
<SplitButton Grid.Column="4"
|
||||
Content="{DynamicResource Text.Repository.Continue}"
|
||||
Height="28"
|
||||
Margin="8,0,0,0"
|
||||
|
@ -283,7 +294,7 @@
|
|||
</SplitButton.Flyout>
|
||||
</SplitButton>
|
||||
|
||||
<Button Grid.Column="3"
|
||||
<Button Grid.Column="4"
|
||||
Classes="flat primary"
|
||||
Content="{DynamicResource Text.WorkingCopy.Commit}"
|
||||
Height="28"
|
||||
|
@ -316,7 +327,7 @@
|
|||
</Button>
|
||||
|
||||
<!-- Invisible button just to add another hotkey `Ctrl+Shift+Enter` to commit with auto-stage -->
|
||||
<Button Grid.Column="4"
|
||||
<Button Grid.Column="5"
|
||||
Width="0" Height="0"
|
||||
Background="Transparent"
|
||||
Command="{Binding CommitWithAutoStage}"
|
||||
|
@ -329,7 +340,7 @@
|
|||
</Button.IsEnabled>
|
||||
</Button>
|
||||
|
||||
<Button Grid.Column="5"
|
||||
<Button Grid.Column="6"
|
||||
Classes="flat"
|
||||
Content="{DynamicResource Text.WorkingCopy.CommitAndPush}"
|
||||
Height="28"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue