From 0fe73fac09d500dcd1d28123a2436645c6d983b8 Mon Sep 17 00:00:00 2001 From: Michael Seibt Date: Sun, 30 Jan 2022 23:20:53 +0100 Subject: [PATCH 1/4] Add git stash --staged --- GitCommands/Git/GitVersion.cs | 4 +++- GitUI/CommandsDialogs/FormBrowse.Designer.cs | 11 +++++++++ GitUI/CommandsDialogs/FormBrowse.cs | 8 +++++++ GitUI/CommandsDialogs/FormCommit.Designer.cs | 25 ++++++++++++++++---- GitUI/CommandsDialogs/FormCommit.cs | 11 +++++++++ GitUI/GitUICommands.cs | 13 ++++++++++ GitUI/Translation/English.xlf | 12 ++++++++++ 7 files changed, 79 insertions(+), 5 deletions(-) diff --git a/GitCommands/Git/GitVersion.cs b/GitCommands/Git/GitVersion.cs index 6b45c3af193..9f224cf0228 100644 --- a/GitCommands/Git/GitVersion.cs +++ b/GitCommands/Git/GitVersion.cs @@ -10,12 +10,13 @@ public class GitVersion : IComparable { private static readonly GitVersion v2_19_0 = new("2.19.0"); private static readonly GitVersion v2_20_0 = new("2.20.0"); + private static readonly GitVersion v2_35_0 = new("2.35.0"); /// /// The recommonded Git version (normally latest official before a GE release). /// This and later versions are green in the settings check. /// - public static readonly GitVersion LastRecommendedVersion = new("2.33.0"); + public static readonly GitVersion LastRecommendedVersion = new("2.35.0"); /// /// The oldest version with reasonable reliable support in GE. @@ -119,6 +120,7 @@ int Get(IReadOnlyList values, int index) public bool SupportRebaseMerges => this >= v2_19_0; public bool SupportGuiMergeTool => this >= v2_20_0; public bool SupportRangeDiffTool => this >= v2_19_0; + public bool SupportStashStaged => this >= v2_35_0; public bool IsUnknown => _a == 0 && _b == 0 && _c == 0 && _d == 0; diff --git a/GitUI/CommandsDialogs/FormBrowse.Designer.cs b/GitUI/CommandsDialogs/FormBrowse.Designer.cs index 62f10e5ec06..e541c090308 100644 --- a/GitUI/CommandsDialogs/FormBrowse.Designer.cs +++ b/GitUI/CommandsDialogs/FormBrowse.Designer.cs @@ -39,6 +39,7 @@ private void InitializeComponent() this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator(); this.toolStripSplitStash = new System.Windows.Forms.ToolStripSplitButton(); this.stashChangesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.stashStagedToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.stashPopToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripSeparator9 = new System.Windows.Forms.ToolStripSeparator(); this.manageStashesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); @@ -389,6 +390,7 @@ private void InitializeComponent() // this.toolStripSplitStash.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.stashChangesToolStripMenuItem, + this.stashStagedToolStripMenuItem, this.stashPopToolStripMenuItem, this.toolStripSeparator9, this.manageStashesToolStripMenuItem, @@ -409,6 +411,14 @@ private void InitializeComponent() this.stashChangesToolStripMenuItem.ToolTipText = "Stash changes"; this.stashChangesToolStripMenuItem.Click += new System.EventHandler(this.StashChangesToolStripMenuItemClick); // + // stashStagedToolStripMenuItem + // + this.stashStagedToolStripMenuItem.Name = "stashStagedToolStripMenuItem"; + this.stashStagedToolStripMenuItem.Size = new System.Drawing.Size(167, 22); + this.stashStagedToolStripMenuItem.Text = "S&tash staged"; + this.stashStagedToolStripMenuItem.ToolTipText = "Stash staged changes"; + this.stashStagedToolStripMenuItem.Click += new System.EventHandler(this.StashStagedToolStripMenuItemClick); + // // stashPopToolStripMenuItem // this.stashPopToolStripMenuItem.Name = "stashPopToolStripMenuItem"; @@ -1792,6 +1802,7 @@ private void InitializeComponent() private ToolStripPushButton toolStripButtonPush; private ToolStripSplitButton toolStripSplitStash; private ToolStripMenuItem stashChangesToolStripMenuItem; + private ToolStripMenuItem stashStagedToolStripMenuItem; private ToolStripMenuItem stashPopToolStripMenuItem; private ToolStripSeparator toolStripSeparator9; private ToolStripMenuItem manageStashesToolStripMenuItem; diff --git a/GitUI/CommandsDialogs/FormBrowse.cs b/GitUI/CommandsDialogs/FormBrowse.cs index d92d03e063d..85c5418ee10 100644 --- a/GitUI/CommandsDialogs/FormBrowse.cs +++ b/GitUI/CommandsDialogs/FormBrowse.cs @@ -266,6 +266,8 @@ public FormBrowse(GitUICommands commands, BrowseArguments args) MainSplitContainer.Visible = false; MainSplitContainer.SplitterDistance = DpiUtil.Scale(260); + stashStagedToolStripMenuItem.Visible = GitVersion.Current.SupportStashStaged; + ThreadHelper.JoinableTaskFactory.RunAsync(async () => { await TaskScheduler.Default; @@ -1592,6 +1594,12 @@ private void StashChangesToolStripMenuItemClick(object sender, EventArgs e) UpdateStashCount(); } + private void StashStagedToolStripMenuItemClick(object sender, EventArgs e) + { + UICommands.StashStaged(this); + UpdateStashCount(); + } + private void StashPopToolStripMenuItemClick(object sender, EventArgs e) { UICommands.StashPop(this); diff --git a/GitUI/CommandsDialogs/FormCommit.Designer.cs b/GitUI/CommandsDialogs/FormCommit.Designer.cs index 38e5dbca71a..b0e2b6273c8 100644 --- a/GitUI/CommandsDialogs/FormCommit.Designer.cs +++ b/GitUI/CommandsDialogs/FormCommit.Designer.cs @@ -123,6 +123,7 @@ private void InitializeComponent() this.CommitAndPush = new System.Windows.Forms.Button(); this.Amend = new System.Windows.Forms.CheckBox(); this.ResetAuthor = new System.Windows.Forms.CheckBox(); + this.StashStaged = new System.Windows.Forms.Button(); this.Reset = new System.Windows.Forms.Button(); this.ResetUnStaged = new System.Windows.Forms.Button(); this.toolbarCommit = new GitUI.ToolStripEx(); @@ -1115,6 +1116,7 @@ private void InitializeComponent() var resetAuthorPanel = new Panel{ AutoSize = false, Size = this.ResetAuthor.Size, Margin = new Padding(0) }; resetAuthorPanel.Controls.Add(this.ResetAuthor); this.flowCommitButtons.Controls.Add(resetAuthorPanel); + this.flowCommitButtons.Controls.Add(this.StashStaged); this.flowCommitButtons.Controls.Add(this.Reset); this.flowCommitButtons.Controls.Add(this.ResetUnStaged); this.flowCommitButtons.Dock = System.Windows.Forms.DockStyle.Fill; @@ -1178,11 +1180,25 @@ private void InitializeComponent() this.ResetAuthor.UseVisualStyleBackColor = true; this.ResetAuthor.Visible = false; // + // StashStaged + // + this.StashStaged.Image = global::GitUI.Properties.Images.Stash; + this.StashStaged.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft; + this.StashStaged.Location = new System.Drawing.Point(0, 110); + this.StashStaged.Margin = new System.Windows.Forms.Padding(0, 3, 0, 3); + this.StashStaged.Name = "StashStaged"; + this.StashStaged.Size = new System.Drawing.Size(171, 26); + this.StashStaged.TabIndex = 14; + this.StashStaged.TabStop = false; + this.StashStaged.Text = "S&tash staged changes"; + this.StashStaged.UseVisualStyleBackColor = true; + this.StashStaged.Click += new System.EventHandler(this.StashStagedClick); + // // Reset // this.Reset.Image = global::GitUI.Properties.Images.ResetWorkingDirChanges; this.Reset.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft; - this.Reset.Location = new System.Drawing.Point(0, 110); + this.Reset.Location = new System.Drawing.Point(0, 142); this.Reset.Margin = new System.Windows.Forms.Padding(0, 3, 0, 3); this.Reset.Name = "Reset"; this.Reset.Size = new System.Drawing.Size(171, 26); @@ -1196,7 +1212,7 @@ private void InitializeComponent() // this.ResetUnStaged.Image = global::GitUI.Properties.Images.ResetWorkingDirChanges; this.ResetUnStaged.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft; - this.ResetUnStaged.Location = new System.Drawing.Point(0, 142); + this.ResetUnStaged.Location = new System.Drawing.Point(0, 174); this.ResetUnStaged.Margin = new System.Windows.Forms.Padding(0, 3, 0, 3); this.ResetUnStaged.Name = "ResetUnStaged"; this.ResetUnStaged.Size = new System.Drawing.Size(171, 26); @@ -1679,10 +1695,11 @@ private void InitializeComponent() private FlowLayoutPanel flowCommitButtons; private Button Commit; private Button CommitAndPush; - private Button Reset; + private CheckBox StageInSuperproject; private CheckBox Amend; private CheckBox ResetAuthor; - private CheckBox StageInSuperproject; + private Button StashStaged; + private Button Reset; private Button ResetUnStaged; private ToolStripMenuItem resetUnstagedChangesToolStripMenuItem; private ToolStripMenuItem noVerifyToolStripMenuItem; diff --git a/GitUI/CommandsDialogs/FormCommit.cs b/GitUI/CommandsDialogs/FormCommit.cs index 90dd5f33bed..6a79378d53d 100644 --- a/GitUI/CommandsDialogs/FormCommit.cs +++ b/GitUI/CommandsDialogs/FormCommit.cs @@ -307,6 +307,11 @@ public FormCommit(GitUICommands commands, CommitKind commitKind = CommitKind.Nor selectionFilter.Size = DpiUtil.Scale(selectionFilter.Size); toolStripStatusBranchIcon.Width = DpiUtil.Scale(toolStripStatusBranchIcon.Width); + if (!GitVersion.Current.SupportStashStaged) + { + flowCommitButtons.Controls.Remove(StashStaged); + } + SetVisibilityOfSelectionFilter(AppSettings.CommitDialogSelectionFilter); Reset.Visible = AppSettings.ShowResetAllChanges; ResetUnStaged.Visible = AppSettings.ShowResetWorkTreeChanges; @@ -2699,6 +2704,12 @@ private void HandleResetButton(bool onlyUnstaged) Initialize(); } + private void StashStagedClick(object sender, EventArgs e) + { + BypassFormActivatedEventHandler(() => UICommands.StashStaged(owner: this)); + Initialize(); + } + private void BypassFormActivatedEventHandler(Action action) { try diff --git a/GitUI/GitUICommands.cs b/GitUI/GitUICommands.cs index 87bec4fd272..1bbd663ca40 100644 --- a/GitUI/GitUICommands.cs +++ b/GitUI/GitUICommands.cs @@ -202,6 +202,19 @@ bool Action() return DoActionOnRepo(owner, Action); } + public bool StashStaged(IWin32Window? owner) + { + bool Action() + { + FormProcess.ShowDialog(owner, arguments: "stash --staged", Module.WorkingDir, input: null, useDialogSettings: true); + + // git-stash may have changed commits also if aborted, the grid must be refreshed + return true; + } + + return DoActionOnRepo(owner, Action); + } + public bool StashPop(IWin32Window? owner) { bool Action() diff --git a/GitUI/Translation/English.xlf b/GitUI/Translation/English.xlf index c9d559d3fb6..31fb0838e75 100644 --- a/GitUI/Translation/English.xlf +++ b/GitUI/Translation/English.xlf @@ -3127,6 +3127,14 @@ Do you want to continue? Apply and drop single stash + + S&tash staged + + + + Stash staged changes + + Ma&nage stashes... @@ -3840,6 +3848,10 @@ gitex.cmd / gitex (located in the same folder as GitExtensions.exe): Stage &in Superproject + + S&tash staged changes + + Add selection to commit message From cc345a5b0f5f9657f80e9924438e0a1e4edeb176 Mon Sep 17 00:00:00 2001 From: Michael Seibt Date: Tue, 1 Feb 2022 22:21:18 +0100 Subject: [PATCH 2/4] fixup! Review comments --- GitUI/CommandsDialogs/FormBrowse.cs | 2 +- GitUI/CommandsDialogs/FormCommit.Designer.cs | 6 +++--- GitUI/CommandsDialogs/FormCommit.cs | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/GitUI/CommandsDialogs/FormBrowse.cs b/GitUI/CommandsDialogs/FormBrowse.cs index 85c5418ee10..6ead16c2109 100644 --- a/GitUI/CommandsDialogs/FormBrowse.cs +++ b/GitUI/CommandsDialogs/FormBrowse.cs @@ -266,7 +266,7 @@ public FormBrowse(GitUICommands commands, BrowseArguments args) MainSplitContainer.Visible = false; MainSplitContainer.SplitterDistance = DpiUtil.Scale(260); - stashStagedToolStripMenuItem.Visible = GitVersion.Current.SupportStashStaged; + stashStagedToolStripMenuItem.Visible = Module.GitVersion.SupportStashStaged; ThreadHelper.JoinableTaskFactory.RunAsync(async () => { diff --git a/GitUI/CommandsDialogs/FormCommit.Designer.cs b/GitUI/CommandsDialogs/FormCommit.Designer.cs index b0e2b6273c8..cbdb7c1a95a 100644 --- a/GitUI/CommandsDialogs/FormCommit.Designer.cs +++ b/GitUI/CommandsDialogs/FormCommit.Designer.cs @@ -1695,11 +1695,11 @@ private void InitializeComponent() private FlowLayoutPanel flowCommitButtons; private Button Commit; private Button CommitAndPush; - private CheckBox StageInSuperproject; - private CheckBox Amend; - private CheckBox ResetAuthor; private Button StashStaged; private Button Reset; + private CheckBox Amend; + private CheckBox ResetAuthor; + private CheckBox StageInSuperproject; private Button ResetUnStaged; private ToolStripMenuItem resetUnstagedChangesToolStripMenuItem; private ToolStripMenuItem noVerifyToolStripMenuItem; diff --git a/GitUI/CommandsDialogs/FormCommit.cs b/GitUI/CommandsDialogs/FormCommit.cs index 6a79378d53d..050730d074a 100644 --- a/GitUI/CommandsDialogs/FormCommit.cs +++ b/GitUI/CommandsDialogs/FormCommit.cs @@ -307,7 +307,7 @@ public FormCommit(GitUICommands commands, CommitKind commitKind = CommitKind.Nor selectionFilter.Size = DpiUtil.Scale(selectionFilter.Size); toolStripStatusBranchIcon.Width = DpiUtil.Scale(toolStripStatusBranchIcon.Width); - if (!GitVersion.Current.SupportStashStaged) + if (!Module.GitVersion.SupportStashStaged) { flowCommitButtons.Controls.Remove(StashStaged); } From 769633d68330006bdd18b6e8341531cd1b7bc5ed Mon Sep 17 00:00:00 2001 From: Gerhard Olsson Date: Tue, 1 Feb 2022 23:10:58 +0100 Subject: [PATCH 3/4] squash! Add git stash --staged Check for WSL Git version was always using Windows version --- GitCommands/Git/GitModule.cs | 2 +- GitCommands/Git/GitVersion.cs | 10 ++++++++-- GitUI/CommandsDialogs/FormBrowse.cs | 3 +-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/GitCommands/Git/GitModule.cs b/GitCommands/Git/GitModule.cs index e274d63f2a6..763be9de9a1 100644 --- a/GitCommands/Git/GitModule.cs +++ b/GitCommands/Git/GitModule.cs @@ -158,7 +158,7 @@ static bool HasGitModulesFile(string path) /// /// GitVersion for the default GitExecutable. /// - public GitVersion GitVersion => GitVersion.CurrentVersion(_wslDistro); + public GitVersion GitVersion => GitVersion.CurrentVersion(GitExecutable, _wslDistro); /// public IExecutable GitExecutable => _gitExecutable; diff --git a/GitCommands/Git/GitVersion.cs b/GitCommands/Git/GitVersion.cs index 9f224cf0228..8fcbc72321d 100644 --- a/GitCommands/Git/GitVersion.cs +++ b/GitCommands/Git/GitVersion.cs @@ -3,6 +3,7 @@ using System.Linq; using System.Windows.Forms; using GitExtUtils; +using GitUIPluginInterfaces; namespace GitCommands { @@ -41,11 +42,16 @@ public class GitVersion : IComparable /// /// The unique identification of the Git executable /// The GitVersion - public static GitVersion CurrentVersion(string gitIdentifiable = "") + public static GitVersion CurrentVersion(IExecutable gitExec = null, string gitIdentifiable = "") { if (!_current.ContainsKey(gitIdentifiable) || _current[gitIdentifiable] is null || _current[gitIdentifiable].IsUnknown) { - string output = new Executable(AppSettings.GitCommand).GetOutput("--version"); + if (gitExec is null) + { + gitExec = new Executable(AppSettings.GitCommand); + } + + string output = gitExec.GetOutput("--version"); _current[gitIdentifiable] = new GitVersion(output); if (_current[gitIdentifiable] < LastVersionWithoutKnownLimitations) { diff --git a/GitUI/CommandsDialogs/FormBrowse.cs b/GitUI/CommandsDialogs/FormBrowse.cs index 6ead16c2109..7632fa98679 100644 --- a/GitUI/CommandsDialogs/FormBrowse.cs +++ b/GitUI/CommandsDialogs/FormBrowse.cs @@ -266,8 +266,6 @@ public FormBrowse(GitUICommands commands, BrowseArguments args) MainSplitContainer.Visible = false; MainSplitContainer.SplitterDistance = DpiUtil.Scale(260); - stashStagedToolStripMenuItem.Visible = Module.GitVersion.SupportStashStaged; - ThreadHelper.JoinableTaskFactory.RunAsync(async () => { await TaskScheduler.Default; @@ -871,6 +869,7 @@ private void InternalInitialize() } stashChangesToolStripMenuItem.Enabled = !bareRepository; + stashStagedToolStripMenuItem.Visible = Module.GitVersion.SupportStashStaged; gitGUIToolStripMenuItem.Enabled = !bareRepository; SetShortcutKeyDisplayStringsFromHotkeySettings(); From 346bdbd57c8adb94e7d9797bb0180c07ffdffa29 Mon Sep 17 00:00:00 2001 From: Michael Seibt Date: Tue, 1 Feb 2022 23:19:11 +0100 Subject: [PATCH 4/4] fixup! Shorten --- GitCommands/Git/GitVersion.cs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/GitCommands/Git/GitVersion.cs b/GitCommands/Git/GitVersion.cs index 8fcbc72321d..4fea29e4cee 100644 --- a/GitCommands/Git/GitVersion.cs +++ b/GitCommands/Git/GitVersion.cs @@ -46,11 +46,7 @@ public static GitVersion CurrentVersion(IExecutable gitExec = null, string gitId { if (!_current.ContainsKey(gitIdentifiable) || _current[gitIdentifiable] is null || _current[gitIdentifiable].IsUnknown) { - if (gitExec is null) - { - gitExec = new Executable(AppSettings.GitCommand); - } - + gitExec ??= new Executable(AppSettings.GitCommand); string output = gitExec.GetOutput("--version"); _current[gitIdentifiable] = new GitVersion(output); if (_current[gitIdentifiable] < LastVersionWithoutKnownLimitations)