diff --git a/src/Commands/Commit.cs b/src/Commands/Commit.cs index 17410bc9..6e7a862c 100644 --- a/src/Commands/Commit.cs +++ b/src/Commands/Commit.cs @@ -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) diff --git a/src/Commands/QueryStagedChangesWithAmend.cs b/src/Commands/QueryStagedChangesWithAmend.cs index b20c20dc..78980401 100644 --- a/src/Commands/QueryStagedChangesWithAmend.cs +++ b/src/Commands/QueryStagedChangesWithAmend.cs @@ -24,7 +24,7 @@ namespace SourceGit.Commands var rs = ReadToEnd(); if (!rs.IsSuccess) return []; - + var changes = new List(); var lines = rs.StdOut.Split(['\r', '\n'], StringSplitOptions.RemoveEmptyEntries); foreach (var line in lines) diff --git a/src/Models/Change.cs b/src/Models/Change.cs index 7d772d3e..788144a5 100644 --- a/src/Models/Change.cs +++ b/src/Models/Change.cs @@ -64,7 +64,7 @@ namespace SourceGit.Models if (Path[0] == '"') Path = Path.Substring(1, Path.Length - 2); - + if (!string.IsNullOrEmpty(OriginalPath) && OriginalPath[0] == '"') OriginalPath = OriginalPath.Substring(1, OriginalPath.Length - 2); } diff --git a/src/Resources/Locales/en_US.axaml b/src/Resources/Locales/en_US.axaml index 07ebc675..7c723404 100644 --- a/src/Resources/Locales/en_US.axaml +++ b/src/Resources/Locales/en_US.axaml @@ -103,6 +103,10 @@ Repository URL: CLOSE Editor + Author Name: + Enter author's name + Author Email: + Enter author's email Checkout Commit Cherry-Pick Commit Cherry-Pick ... @@ -779,6 +783,7 @@ USE MINE USE THEIRS INCLUDE UNTRACKED FILES + Modify Author NO RECENT INPUT MESSAGES NO COMMIT TEMPLATES Reset Author diff --git a/src/Resources/Locales/zh_CN.axaml b/src/Resources/Locales/zh_CN.axaml index 2703f5a2..b9e5aaa0 100644 --- a/src/Resources/Locales/zh_CN.axaml +++ b/src/Resources/Locales/zh_CN.axaml @@ -107,6 +107,10 @@ 远程仓库 : 关闭 提交信息编辑器 + 作者用户名: + 输入作者用户名 + 作者邮箱: + 输入作者邮箱 检出此提交 挑选(cherry-pick)此提交 挑选(cherry-pick)... @@ -783,6 +787,7 @@ 使用 MINE 使用 THEIRS 显示未跟踪文件 + 修改作者 没有提交信息记录 没有可应用的提交信息模板 重置提交者 diff --git a/src/Resources/Locales/zh_TW.axaml b/src/Resources/Locales/zh_TW.axaml index f810ea15..560982bd 100644 --- a/src/Resources/Locales/zh_TW.axaml +++ b/src/Resources/Locales/zh_TW.axaml @@ -107,6 +107,10 @@ 遠端存放庫: 關閉 提交訊息編輯器 + 作者名稱: + 輸入作者名稱 + 作者電子郵件: + 輸入作者電子郵件 簽出 (checkout) 此提交 揀選 (cherry-pick) 此提交 揀選 (cherry-pick)... @@ -783,6 +787,7 @@ 使用我方版本 (ours) 使用對方版本 (theirs) 顯示未追蹤檔案 + 修改作者 沒有提交訊息記錄 沒有可套用的提交訊息範本 重設作者 diff --git a/src/ViewModels/Repository.cs b/src/ViewModels/Repository.cs index b02cf36a..4dc8b251 100644 --- a/src/ViewModels/Repository.cs +++ b/src/ViewModels/Repository.cs @@ -639,7 +639,7 @@ namespace SourceGit.ViewModels Task.Run(RefreshWorktrees); Task.Run(RefreshWorkingCopyChanges); Task.Run(RefreshStashes); - + Task.Run(() => { var config = new Commands.Config(_fullpath).ListAll(); diff --git a/src/ViewModels/Reword.cs b/src/ViewModels/Reword.cs index 72dd9e58..e9e2415e 100644 --- a/src/ViewModels/Reword.cs +++ b/src/ViewModels/Reword.cs @@ -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; diff --git a/src/ViewModels/Squash.cs b/src/ViewModels/Squash.cs index 0d680d20..d270d34f 100644 --- a/src/ViewModels/Squash.cs +++ b/src/ViewModels/Squash.cs @@ -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}"); diff --git a/src/ViewModels/WorkingCopy.cs b/src/ViewModels/WorkingCopy.cs index 64c7b31d..ce33f282 100644 --- a/src/ViewModels/WorkingCopy.cs +++ b/src/ViewModels/WorkingCopy.cs @@ -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 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) { @@ -1770,7 +1786,7 @@ namespace SourceGit.ViewModels { if (old.Count != cur.Count) return true; - + var oldMap = new Dictionary(); foreach (var c in old) oldMap.Add(c.Path, c); @@ -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 _cached = []; private List _unstaged = []; private List _visibleUnstaged = []; diff --git a/src/Views/CommitAuthorTextBox.axaml b/src/Views/CommitAuthorTextBox.axaml new file mode 100644 index 00000000..48fd743f --- /dev/null +++ b/src/Views/CommitAuthorTextBox.axaml @@ -0,0 +1,39 @@ + + + + + + + + + + + diff --git a/src/Views/CommitAuthorTextBox.axaml.cs b/src/Views/CommitAuthorTextBox.axaml.cs new file mode 100644 index 00000000..b8cace08 --- /dev/null +++ b/src/Views/CommitAuthorTextBox.axaml.cs @@ -0,0 +1,40 @@ +using Avalonia; +using Avalonia.Controls; +using Avalonia.Data; + +namespace SourceGit.Views +{ + public partial class CommitAuthorTextBox : UserControl + { + + public static readonly StyledProperty UserNameProperty = + AvaloniaProperty.Register( + nameof(UserName), + string.Empty, + defaultBindingMode: BindingMode.TwoWay); + + public static readonly StyledProperty UserEmailProperty = + AvaloniaProperty.Register( + 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(); + } + + } +} diff --git a/src/Views/WorkingCopy.axaml b/src/Views/WorkingCopy.axaml index 8c600956..8df0d372 100644 --- a/src/Views/WorkingCopy.axaml +++ b/src/Views/WorkingCopy.axaml @@ -168,7 +168,7 @@ ViewMode="{Binding Source={x:Static vm:Preferences.Instance}, Path=StagedChangeViewMode, Mode=TwoWay}"/> - + - + - + + + + + + + + + + + - - -