mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-06-21 10:25:00 +00:00
feat: specific author when commit
This commit is contained in:
parent
056b90a5ae
commit
aea331a2ce
13 changed files with 152 additions and 17 deletions
|
@ -4,14 +4,21 @@ namespace SourceGit.Commands
|
|||
{
|
||||
public class Commit : Command
|
||||
{
|
||||
public Commit(string repo, string message, bool signOff, bool amend, bool resetAuthor)
|
||||
public Commit(string repo, string message, bool signOff, bool amend, bool resetAuthor = false, string userName = null, string userEmail = null)
|
||||
{
|
||||
_tmpFile = Path.GetTempFileName();
|
||||
File.WriteAllText(_tmpFile, message);
|
||||
|
||||
WorkingDirectory = repo;
|
||||
Context = repo;
|
||||
Args = $"commit --allow-empty --file=\"{_tmpFile}\"";
|
||||
|
||||
if (!string.IsNullOrEmpty(userName))
|
||||
Args += $"-c user.name=\"{userName}\" ";
|
||||
if (!string.IsNullOrEmpty(userEmail))
|
||||
Args += $"-c user.email=\"{userEmail}\" ";
|
||||
|
||||
Args += $"commit --allow-empty --file=\"{_tmpFile}\"";
|
||||
|
||||
if (signOff)
|
||||
Args += " --signoff";
|
||||
if (amend)
|
||||
|
|
|
@ -103,6 +103,10 @@
|
|||
<x:String x:Key="Text.Clone.RemoteURL" xml:space="preserve">Repository URL:</x:String>
|
||||
<x:String x:Key="Text.Close" xml:space="preserve">CLOSE</x:String>
|
||||
<x:String x:Key="Text.CodeEditor" xml:space="preserve">Editor</x:String>
|
||||
<x:String x:Key="Text.CommitAuthorTextBox.AuthorName" xml:space="preserve">Author Name:</x:String>
|
||||
<x:String x:Key="Text.CommitAuthorTextBox.AuthorName.Placeholder" xml:space="preserve">Enter author's name</x:String>
|
||||
<x:String x:Key="Text.CommitAuthorTextBox.AuthorEmail" xml:space="preserve">Author Email:</x:String>
|
||||
<x:String x:Key="Text.CommitAuthorTextBox.AuthorEmail.Placeholder" xml:space="preserve">Enter author's email</x:String>
|
||||
<x:String x:Key="Text.CommitCM.Checkout" xml:space="preserve">Checkout Commit</x:String>
|
||||
<x:String x:Key="Text.CommitCM.CherryPick" xml:space="preserve">Cherry-Pick Commit</x:String>
|
||||
<x:String x:Key="Text.CommitCM.CherryPickMultiple" xml:space="preserve">Cherry-Pick ...</x:String>
|
||||
|
@ -779,6 +783,7 @@
|
|||
<x:String x:Key="Text.WorkingCopy.Conflicts.UseMine" xml:space="preserve">USE MINE</x:String>
|
||||
<x:String x:Key="Text.WorkingCopy.Conflicts.UseTheirs" xml:space="preserve">USE THEIRS</x:String>
|
||||
<x:String x:Key="Text.WorkingCopy.IncludeUntracked" xml:space="preserve">INCLUDE UNTRACKED FILES</x:String>
|
||||
<x:String x:Key="Text.WorkingCopy.ModifyAuthor" xml:space="preserve">Modify Author</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>
|
||||
|
|
|
@ -107,6 +107,10 @@
|
|||
<x:String x:Key="Text.Clone.RemoteURL" xml:space="preserve">远程仓库 :</x:String>
|
||||
<x:String x:Key="Text.Close" xml:space="preserve">关闭</x:String>
|
||||
<x:String x:Key="Text.CodeEditor" xml:space="preserve">提交信息编辑器</x:String>
|
||||
<x:String x:Key="Text.CommitAuthorTextBox.AuthorName" xml:space="preserve">作者用户名:</x:String>
|
||||
<x:String x:Key="Text.CommitAuthorTextBox.AuthorName.Placeholder" xml:space="preserve">输入作者用户名</x:String>
|
||||
<x:String x:Key="Text.CommitAuthorTextBox.AuthorEmail" xml:space="preserve">作者邮箱:</x:String>
|
||||
<x:String x:Key="Text.CommitAuthorTextBox.AuthorEmail.Placeholder" xml:space="preserve">输入作者邮箱</x:String>
|
||||
<x:String x:Key="Text.CommitCM.Checkout" xml:space="preserve">检出此提交</x:String>
|
||||
<x:String x:Key="Text.CommitCM.CherryPick" xml:space="preserve">挑选(cherry-pick)此提交</x:String>
|
||||
<x:String x:Key="Text.CommitCM.CherryPickMultiple" xml:space="preserve">挑选(cherry-pick)...</x:String>
|
||||
|
@ -783,6 +787,7 @@
|
|||
<x:String x:Key="Text.WorkingCopy.Conflicts.UseMine" xml:space="preserve">使用 MINE</x:String>
|
||||
<x:String x:Key="Text.WorkingCopy.Conflicts.UseTheirs" xml:space="preserve">使用 THEIRS</x:String>
|
||||
<x:String x:Key="Text.WorkingCopy.IncludeUntracked" xml:space="preserve">显示未跟踪文件</x:String>
|
||||
<x:String x:Key="Text.WorkingCopy.ModifyAuthor" 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>
|
||||
|
|
|
@ -107,6 +107,10 @@
|
|||
<x:String x:Key="Text.Clone.RemoteURL" xml:space="preserve">遠端存放庫:</x:String>
|
||||
<x:String x:Key="Text.Close" xml:space="preserve">關閉</x:String>
|
||||
<x:String x:Key="Text.CodeEditor" xml:space="preserve">提交訊息編輯器</x:String>
|
||||
<x:String x:Key="Text.CommitAuthorTextBox.AuthorName" xml:space="preserve">作者名稱:</x:String>
|
||||
<x:String x:Key="Text.CommitAuthorTextBox.AuthorName.Placeholder" xml:space="preserve">輸入作者名稱</x:String>
|
||||
<x:String x:Key="Text.CommitAuthorTextBox.AuthorEmail" xml:space="preserve">作者電子郵件:</x:String>
|
||||
<x:String x:Key="Text.CommitAuthorTextBox.AuthorEmail.Placeholder" xml:space="preserve">輸入作者電子郵件</x:String>
|
||||
<x:String x:Key="Text.CommitCM.Checkout" xml:space="preserve">簽出 (checkout) 此提交</x:String>
|
||||
<x:String x:Key="Text.CommitCM.CherryPick" xml:space="preserve">揀選 (cherry-pick) 此提交</x:String>
|
||||
<x:String x:Key="Text.CommitCM.CherryPickMultiple" xml:space="preserve">揀選 (cherry-pick)...</x:String>
|
||||
|
@ -783,6 +787,7 @@
|
|||
<x:String x:Key="Text.WorkingCopy.Conflicts.UseMine" xml:space="preserve">使用我方版本 (ours)</x:String>
|
||||
<x:String x:Key="Text.WorkingCopy.Conflicts.UseTheirs" xml:space="preserve">使用對方版本 (theirs)</x:String>
|
||||
<x:String x:Key="Text.WorkingCopy.IncludeUntracked" xml:space="preserve">顯示未追蹤檔案</x:String>
|
||||
<x:String x:Key="Text.WorkingCopy.ModifyAuthor" 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>
|
||||
|
|
|
@ -41,7 +41,7 @@ namespace SourceGit.ViewModels
|
|||
return Task.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();
|
||||
var succ = new Commands.Commit(_repo.FullPath, _message, signOff, true).Use(log).Run();
|
||||
log.Complete();
|
||||
CallUIThread(() => _repo.SetWatcherEnabled(true));
|
||||
return succ;
|
||||
|
|
|
@ -53,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, signOff, true, true).Use(log).Run();
|
||||
succ = new Commands.Commit(_repo.FullPath, _message, signOff, true).Use(log).Run();
|
||||
|
||||
if (succ && autoStashed)
|
||||
new Commands.Stash(_repo.FullPath).Use(log).Pop("stash@{0}");
|
||||
|
|
|
@ -68,6 +68,18 @@ namespace SourceGit.ViewModels
|
|||
set => _repo.Settings.EnableSignOffForCommit = value;
|
||||
}
|
||||
|
||||
public string UserName
|
||||
{
|
||||
get => _userName;
|
||||
set => SetProperty(ref _userName, value);
|
||||
}
|
||||
|
||||
public string UserEmail
|
||||
{
|
||||
get => _userEmail;
|
||||
set => SetProperty(ref _userEmail, value);
|
||||
}
|
||||
|
||||
public bool UseAmend
|
||||
{
|
||||
get => _useAmend;
|
||||
|
@ -242,6 +254,8 @@ namespace SourceGit.ViewModels
|
|||
|
||||
_detailContext = null;
|
||||
_commitMessage = string.Empty;
|
||||
_userName = null;
|
||||
_userEmail = null;
|
||||
}
|
||||
|
||||
public void SetData(List<Models.Change> changes)
|
||||
|
@ -1733,7 +1747,7 @@ namespace SourceGit.ViewModels
|
|||
succ = new Commands.Add(_repo.FullPath, _repo.IncludeUntracked).Use(log).Exec();
|
||||
|
||||
if (succ)
|
||||
succ = new Commands.Commit(_repo.FullPath, _commitMessage, signOff, _useAmend, _resetAuthor).Use(log).Run();
|
||||
succ = new Commands.Commit(_repo.FullPath, _commitMessage, _repo.Settings.EnableSignOffForCommit, _useAmend, _resetAuthor, _userName, _userEmail).Use(log).Run();
|
||||
|
||||
log.Complete();
|
||||
|
||||
|
@ -1743,6 +1757,8 @@ namespace SourceGit.ViewModels
|
|||
{
|
||||
CommitMessage = string.Empty;
|
||||
UseAmend = false;
|
||||
UserName = string.Empty;
|
||||
UserEmail = string.Empty;
|
||||
|
||||
if (autoPush && _repo.Remotes.Count > 0)
|
||||
{
|
||||
|
@ -1795,6 +1811,8 @@ namespace SourceGit.ViewModels
|
|||
private bool _useAmend = false;
|
||||
private bool _resetAuthor = false;
|
||||
private bool _hasRemotes = false;
|
||||
private string _userName = string.Empty;
|
||||
private string _userEmail = string.Empty;
|
||||
private List<Models.Change> _cached = [];
|
||||
private List<Models.Change> _unstaged = [];
|
||||
private List<Models.Change> _visibleUnstaged = [];
|
||||
|
|
39
src/Views/CommitAuthorTextBox.axaml
Normal file
39
src/Views/CommitAuthorTextBox.axaml
Normal file
|
@ -0,0 +1,39 @@
|
|||
<UserControl xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:v="using:SourceGit.Views"
|
||||
mc:Ignorable="d" d:DesignWidth="400" d:DesignHeight="68"
|
||||
x:Class="SourceGit.Views.CommitAuthorTextBox">
|
||||
<Grid RowDefinitions="32,32" ColumnDefinitions="Auto,*" Margin="16,4,16,8">
|
||||
<!-- Author Name Row -->
|
||||
<TextBlock Grid.Row="0" Grid.Column="0"
|
||||
Text="{DynamicResource Text.CommitAuthorTextBox.AuthorName}"
|
||||
HorizontalAlignment="Right" VerticalAlignment="Center"
|
||||
Margin="0,0,8,0"/>
|
||||
<TextBox Grid.Row="0" Grid.Column="1"
|
||||
Height="28"
|
||||
CornerRadius="3"
|
||||
Text="{Binding $parent[v:CommitAuthorTextBox].UserName, Mode=TwoWay}"
|
||||
Watermark="{DynamicResource Text.CommitAuthorTextBox.AuthorName.Placeholder}"
|
||||
AcceptsReturn="False"
|
||||
TextWrapping="NoWrap"
|
||||
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
|
||||
ScrollViewer.VerticalScrollBarVisibility="Disabled"/>
|
||||
|
||||
<!-- Author Email Row -->
|
||||
<TextBlock Grid.Row="1" Grid.Column="0"
|
||||
Text="{DynamicResource Text.CommitAuthorTextBox.AuthorEmail}"
|
||||
HorizontalAlignment="Right" VerticalAlignment="Center"
|
||||
Margin="0,0,8,0"/>
|
||||
<TextBox Grid.Row="1" Grid.Column="1"
|
||||
Height="28"
|
||||
CornerRadius="3"
|
||||
Text="{Binding $parent[v:CommitAuthorTextBox].UserEmail, Mode=TwoWay}"
|
||||
Watermark="{DynamicResource Text.CommitAuthorTextBox.AuthorEmail.Placeholder}"
|
||||
AcceptsReturn="False"
|
||||
TextWrapping="NoWrap"
|
||||
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
|
||||
ScrollViewer.VerticalScrollBarVisibility="Disabled"/>
|
||||
</Grid>
|
||||
</UserControl>
|
40
src/Views/CommitAuthorTextBox.axaml.cs
Normal file
40
src/Views/CommitAuthorTextBox.axaml.cs
Normal file
|
@ -0,0 +1,40 @@
|
|||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Data;
|
||||
|
||||
namespace SourceGit.Views
|
||||
{
|
||||
public partial class CommitAuthorTextBox : UserControl
|
||||
{
|
||||
|
||||
public static readonly StyledProperty<string> UserNameProperty =
|
||||
AvaloniaProperty.Register<CommitAuthorTextBox, string>(
|
||||
nameof(UserName),
|
||||
string.Empty,
|
||||
defaultBindingMode: BindingMode.TwoWay);
|
||||
|
||||
public static readonly StyledProperty<string> UserEmailProperty =
|
||||
AvaloniaProperty.Register<CommitAuthorTextBox, string>(
|
||||
nameof(UserEmail),
|
||||
string.Empty,
|
||||
defaultBindingMode: BindingMode.TwoWay);
|
||||
|
||||
public string UserName
|
||||
{
|
||||
get => GetValue(UserNameProperty);
|
||||
set => SetValue(UserNameProperty, value);
|
||||
}
|
||||
|
||||
public string UserEmail
|
||||
{
|
||||
get => GetValue(UserEmailProperty);
|
||||
set => SetValue(UserEmailProperty, value);
|
||||
}
|
||||
|
||||
public CommitAuthorTextBox()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -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,Auto">
|
||||
<Grid Grid.Row="3" Margin="0,6,0,0" ColumnDefinitions="Auto,Auto,Auto,Auto,*,Auto,Auto,Auto">
|
||||
<CheckBox Grid.Column="0"
|
||||
Height="24"
|
||||
Margin="1,0,0,0"
|
||||
|
@ -267,12 +267,28 @@
|
|||
ToolTip.Placement="Top"
|
||||
ToolTip.VerticalOffset="0"/>
|
||||
|
||||
<v:LoadingIcon Grid.Column="3"
|
||||
<Button Grid.Column="3"
|
||||
Classes="icon_button"
|
||||
Width="24" Height="24"
|
||||
Margin="12,0,0,0"
|
||||
ToolTip.Tip="{DynamicResource Text.WorkingCopy.ModifyAuthor}">
|
||||
<Button.Flyout>
|
||||
<Flyout Placement="TopEdgeAlignedLeft">
|
||||
<Panel Width="400" Height="68">
|
||||
<v:CommitAuthorTextBox UserName="{Binding UserName, Mode=TwoWay}"
|
||||
UserEmail="{Binding UserEmail, Mode=TwoWay}"/>
|
||||
</Panel>
|
||||
</Flyout>
|
||||
</Button.Flyout>
|
||||
<Path Width="14" Height="14" Data="{StaticResource Icons.User}"/>
|
||||
</Button>
|
||||
|
||||
<v:LoadingIcon Grid.Column="4"
|
||||
Width="18" Height="18"
|
||||
HorizontalAlignment="Right"
|
||||
IsVisible="{Binding IsCommitting}"/>
|
||||
|
||||
<SplitButton Grid.Column="4"
|
||||
<SplitButton Grid.Column="5"
|
||||
Content="{DynamicResource Text.Repository.Continue}"
|
||||
Height="28"
|
||||
Margin="8,0,0,0"
|
||||
|
@ -294,7 +310,7 @@
|
|||
</SplitButton.Flyout>
|
||||
</SplitButton>
|
||||
|
||||
<Button Grid.Column="4"
|
||||
<Button Grid.Column="5"
|
||||
Classes="flat primary"
|
||||
Content="{DynamicResource Text.WorkingCopy.Commit}"
|
||||
Height="28"
|
||||
|
@ -327,7 +343,7 @@
|
|||
</Button>
|
||||
|
||||
<!-- Invisible button just to add another hotkey `Ctrl+Shift+Enter` to commit with auto-stage -->
|
||||
<Button Grid.Column="5"
|
||||
<Button Grid.Column="6"
|
||||
Width="0" Height="0"
|
||||
Background="Transparent"
|
||||
Command="{Binding CommitWithAutoStage}"
|
||||
|
@ -340,7 +356,7 @@
|
|||
</Button.IsEnabled>
|
||||
</Button>
|
||||
|
||||
<Button Grid.Column="6"
|
||||
<Button Grid.Column="7"
|
||||
Classes="flat"
|
||||
Content="{DynamicResource Text.WorkingCopy.CommitAndPush}"
|
||||
Height="28"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue