diff --git a/Directory.Build.props b/Directory.Build.props
index 134fb4b..87327e7 100644
--- a/Directory.Build.props
+++ b/Directory.Build.props
@@ -15,7 +15,8 @@
- net461
+ true
+ net5.0-windows7.0
1.0.0
diff --git a/GitExtensions.GerritPlugin.sln b/GitExtensions.GerritPlugin.sln
index 4276c62..04dd42f 100644
--- a/GitExtensions.GerritPlugin.sln
+++ b/GitExtensions.GerritPlugin.sln
@@ -1,51 +1,31 @@
-
-Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio Version 16
-VisualStudioVersion = 16.0.29709.97
-MinimumVisualStudioVersion = 15.0.26124.0
-Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GitExtensions.GerritPlugin", "src\GitExtensions.GerritPlugin\GitExtensions.GerritPlugin.csproj", "{58C09A62-E18E-4B76-AADB-D0B176C5424E}"
-EndProject
-Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GitExtensions.GerritPlugin.Tests", "UnitTests\GitExtensions.GerritPlugin.Tests\GitExtensions.GerritPlugin.Tests.csproj", "{847B0590-A76F-4B90-B797-10165DD6705F}"
-EndProject
-Global
- GlobalSection(SolutionConfigurationPlatforms) = preSolution
- Debug|Any CPU = Debug|Any CPU
- Debug|x64 = Debug|x64
- Debug|x86 = Debug|x86
- Release|Any CPU = Release|Any CPU
- Release|x64 = Release|x64
- Release|x86 = Release|x86
- EndGlobalSection
- GlobalSection(ProjectConfigurationPlatforms) = postSolution
- {58C09A62-E18E-4B76-AADB-D0B176C5424E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {58C09A62-E18E-4B76-AADB-D0B176C5424E}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {58C09A62-E18E-4B76-AADB-D0B176C5424E}.Debug|x64.ActiveCfg = Debug|Any CPU
- {58C09A62-E18E-4B76-AADB-D0B176C5424E}.Debug|x64.Build.0 = Debug|Any CPU
- {58C09A62-E18E-4B76-AADB-D0B176C5424E}.Debug|x86.ActiveCfg = Debug|Any CPU
- {58C09A62-E18E-4B76-AADB-D0B176C5424E}.Debug|x86.Build.0 = Debug|Any CPU
- {58C09A62-E18E-4B76-AADB-D0B176C5424E}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {58C09A62-E18E-4B76-AADB-D0B176C5424E}.Release|Any CPU.Build.0 = Release|Any CPU
- {58C09A62-E18E-4B76-AADB-D0B176C5424E}.Release|x64.ActiveCfg = Release|Any CPU
- {58C09A62-E18E-4B76-AADB-D0B176C5424E}.Release|x64.Build.0 = Release|Any CPU
- {58C09A62-E18E-4B76-AADB-D0B176C5424E}.Release|x86.ActiveCfg = Release|Any CPU
- {58C09A62-E18E-4B76-AADB-D0B176C5424E}.Release|x86.Build.0 = Release|Any CPU
- {847B0590-A76F-4B90-B797-10165DD6705F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {847B0590-A76F-4B90-B797-10165DD6705F}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {847B0590-A76F-4B90-B797-10165DD6705F}.Debug|x64.ActiveCfg = Debug|Any CPU
- {847B0590-A76F-4B90-B797-10165DD6705F}.Debug|x64.Build.0 = Debug|Any CPU
- {847B0590-A76F-4B90-B797-10165DD6705F}.Debug|x86.ActiveCfg = Debug|Any CPU
- {847B0590-A76F-4B90-B797-10165DD6705F}.Debug|x86.Build.0 = Debug|Any CPU
- {847B0590-A76F-4B90-B797-10165DD6705F}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {847B0590-A76F-4B90-B797-10165DD6705F}.Release|Any CPU.Build.0 = Release|Any CPU
- {847B0590-A76F-4B90-B797-10165DD6705F}.Release|x64.ActiveCfg = Release|Any CPU
- {847B0590-A76F-4B90-B797-10165DD6705F}.Release|x64.Build.0 = Release|Any CPU
- {847B0590-A76F-4B90-B797-10165DD6705F}.Release|x86.ActiveCfg = Release|Any CPU
- {847B0590-A76F-4B90-B797-10165DD6705F}.Release|x86.Build.0 = Release|Any CPU
- EndGlobalSection
- GlobalSection(SolutionProperties) = preSolution
- HideSolutionNode = FALSE
- EndGlobalSection
- GlobalSection(ExtensibilityGlobals) = postSolution
- SolutionGuid = {464E76E6-53B0-4E56-B267-22F7F82476F1}
- EndGlobalSection
-EndGlobal
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 16
+VisualStudioVersion = 16.0.29709.97
+MinimumVisualStudioVersion = 15.0.26124.0
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GitExtensions.GerritPlugin", "src\GitExtensions.GerritPlugin\GitExtensions.GerritPlugin.csproj", "{58C09A62-E18E-4B76-AADB-D0B176C5424E}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GitExtensions.GerritPlugin.Tests", "UnitTests\GitExtensions.GerritPlugin.Tests\GitExtensions.GerritPlugin.Tests.csproj", "{847B0590-A76F-4B90-B797-10165DD6705F}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {58C09A62-E18E-4B76-AADB-D0B176C5424E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {58C09A62-E18E-4B76-AADB-D0B176C5424E}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {58C09A62-E18E-4B76-AADB-D0B176C5424E}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {58C09A62-E18E-4B76-AADB-D0B176C5424E}.Release|Any CPU.Build.0 = Release|Any CPU
+ {847B0590-A76F-4B90-B797-10165DD6705F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {847B0590-A76F-4B90-B797-10165DD6705F}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {847B0590-A76F-4B90-B797-10165DD6705F}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {847B0590-A76F-4B90-B797-10165DD6705F}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {464E76E6-53B0-4E56-B267-22F7F82476F1}
+ SolutionGuid = {F41D2140-C196-4AA5-B8C2-23BC5BEA8D01}
+ EndGlobalSection
+EndGlobal
diff --git a/GitExtensions.settings b/GitExtensions.settings
index 475863e..9f6007b 100644
--- a/GitExtensions.settings
+++ b/GitExtensions.settings
@@ -1,116 +1,116 @@
-
-
- -
-
- BuildServer.AppVeyor.AppVeyorDisplayGitHubPullRequests
-
-
- false
-
-
- -
-
- BuildServer.AppVeyor.AppVeyorLoadTestsResults
-
-
- false
-
-
- -
-
- BuildServer.AppVeyor.AppVeyorProjectName
-
-
- gitextensions/gitextensions-gerritplugin
-
-
- -
-
- BuildServer.EnableIntegration
-
-
- true
-
-
- -
-
- BuildServer.Type
-
-
- AppVeyor
-
-
- -
-
- dictionary
-
-
- en-US
-
-
- -
-
- RevisionLinkDefs
-
-
- <?xml version="1.0" encoding="utf-16"?>
-<ArrayOfGitExtLinkDef>
- <GitExtLinkDef>
- <Enabled>true</Enabled>
- <LinkFormats>
- <GitExtLinkFormat>
- <Caption>View on GitHub</Caption>
- <Format>https://github.com/gitextensions/GitExtensions.GerritPlugin/commit/%COMMIT_HASH%</Format>
- </GitExtLinkFormat>
- </LinkFormats>
- <Name>GitHub - commit</Name>
- <NestedSearchPattern />
- <RemoteSearchInParts />
- <SearchInParts>
- <RevisionPart>Message</RevisionPart>
- </SearchInParts>
- <SearchPattern>.*</SearchPattern>
- <UseOnlyFirstRemote>false</UseOnlyFirstRemote>
- </GitExtLinkDef>
- <GitExtLinkDef>
- <Enabled>true</Enabled>
- <LinkFormats>
- <GitExtLinkFormat>
- <Caption>Issue {0}</Caption>
- <Format>https://github.com/gitextensions/GitExtensions.GerritPlugin/issues/{0}</Format>
- </GitExtLinkFormat>
- </LinkFormats>
- <Name>GitHub - issues</Name>
- <NestedSearchPattern>\d+</NestedSearchPattern>
- <RemoteSearchInParts />
- <SearchInParts>
- <RevisionPart>Message</RevisionPart>
- <RevisionPart>LocalBranches</RevisionPart>
- <RevisionPart>RemoteBranches</RevisionPart>
- </SearchInParts>
- <SearchPattern>(?i)(?<!pull request |pr[ _]?)(#|(((feat(ure)?)|fix)[/_-]))\d+</SearchPattern>
- <UseOnlyFirstRemote>false</UseOnlyFirstRemote>
- </GitExtLinkDef>
- <GitExtLinkDef>
- <Enabled>true</Enabled>
- <LinkFormats>
- <GitExtLinkFormat>
- <Caption>PR {0}</Caption>
- <Format>https://github.com/gitextensions/GitExtensions.GerritPlugin/pull/{0}</Format>
- </GitExtLinkFormat>
- </LinkFormats>
- <Name>GitHub - PR</Name>
- <NestedSearchPattern>\d+</NestedSearchPattern>
- <RemoteSearchInParts />
- <SearchInParts>
- <RevisionPart>Message</RevisionPart>
- <RevisionPart>LocalBranches</RevisionPart>
- <RevisionPart>RemoteBranches</RevisionPart>
- </SearchInParts>
- <SearchPattern>(?i)(pull request |pr[ _]?)#?\d+</SearchPattern>
- <UseOnlyFirstRemote>false</UseOnlyFirstRemote>
- </GitExtLinkDef>
-</ArrayOfGitExtLinkDef>
-
-
+
+
+ -
+
+ BuildServer.AppVeyor.AppVeyorDisplayGitHubPullRequests
+
+
+ false
+
+
+ -
+
+ BuildServer.AppVeyor.AppVeyorLoadTestsResults
+
+
+ false
+
+
+ -
+
+ BuildServer.AppVeyor.AppVeyorProjectName
+
+
+ gitextensions/gitextensions-gerritplugin
+
+
+ -
+
+ BuildServer.EnableIntegration
+
+
+ true
+
+
+ -
+
+ BuildServer.Type
+
+
+ AppVeyor
+
+
+ -
+
+ dictionary
+
+
+ en-US
+
+
+ -
+
+ RevisionLinkDefs
+
+
+ <?xml version="1.0" encoding="utf-16"?>
+<ArrayOfGitExtLinkDef>
+ <GitExtLinkDef>
+ <Enabled>true</Enabled>
+ <LinkFormats>
+ <GitExtLinkFormat>
+ <Caption>View on GitHub</Caption>
+ <Format>https://github.com/gitextensions/GitExtensions.GerritPlugin/commit/%COMMIT_HASH%</Format>
+ </GitExtLinkFormat>
+ </LinkFormats>
+ <Name>GitHub - commit</Name>
+ <NestedSearchPattern />
+ <RemoteSearchInParts />
+ <SearchInParts>
+ <RevisionPart>Message</RevisionPart>
+ </SearchInParts>
+ <SearchPattern>.*</SearchPattern>
+ <UseOnlyFirstRemote>false</UseOnlyFirstRemote>
+ </GitExtLinkDef>
+ <GitExtLinkDef>
+ <Enabled>true</Enabled>
+ <LinkFormats>
+ <GitExtLinkFormat>
+ <Caption>Issue {0}</Caption>
+ <Format>https://github.com/gitextensions/GitExtensions.GerritPlugin/issues/{0}</Format>
+ </GitExtLinkFormat>
+ </LinkFormats>
+ <Name>GitHub - issues</Name>
+ <NestedSearchPattern>\d+</NestedSearchPattern>
+ <RemoteSearchInParts />
+ <SearchInParts>
+ <RevisionPart>Message</RevisionPart>
+ <RevisionPart>LocalBranches</RevisionPart>
+ <RevisionPart>RemoteBranches</RevisionPart>
+ </SearchInParts>
+ <SearchPattern>(?i)(?<!pull request |pr[ _]?)(#|(((feat(ure)?)|fix)[/_-]))\d+</SearchPattern>
+ <UseOnlyFirstRemote>false</UseOnlyFirstRemote>
+ </GitExtLinkDef>
+ <GitExtLinkDef>
+ <Enabled>true</Enabled>
+ <LinkFormats>
+ <GitExtLinkFormat>
+ <Caption>PR {0}</Caption>
+ <Format>https://github.com/gitextensions/GitExtensions.GerritPlugin/pull/{0}</Format>
+ </GitExtLinkFormat>
+ </LinkFormats>
+ <Name>GitHub - PR</Name>
+ <NestedSearchPattern>\d+</NestedSearchPattern>
+ <RemoteSearchInParts />
+ <SearchInParts>
+ <RevisionPart>Message</RevisionPart>
+ <RevisionPart>LocalBranches</RevisionPart>
+ <RevisionPart>RemoteBranches</RevisionPart>
+ </SearchInParts>
+ <SearchPattern>(?i)(pull request |pr[ _]?)#?\d+</SearchPattern>
+ <UseOnlyFirstRemote>false</UseOnlyFirstRemote>
+ </GitExtLinkDef>
+</ArrayOfGitExtLinkDef>
+
+
\ No newline at end of file
diff --git a/appveyor.yml b/appveyor.yml
index 2290b4a..30d7ecd 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -3,7 +3,7 @@
#---------------------------------#
# version format
-version: 1.3.2.{build}
+version: 2.0.0.{build}
# version suffix, if any (e.g. '-RC1', '-beta' otherwise '')
environment:
diff --git a/src/GitExtensions.GerritPlugin/FormGerritDownload.cs b/src/GitExtensions.GerritPlugin/FormGerritDownload.cs
index 9032ac4..93beeba 100644
--- a/src/GitExtensions.GerritPlugin/FormGerritDownload.cs
+++ b/src/GitExtensions.GerritPlugin/FormGerritDownload.cs
@@ -1,257 +1,251 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text.RegularExpressions;
-using System.Threading.Tasks;
-using System.Windows.Forms;
-using GitCommands;
-using GitCommands.Git.Commands;
-using GitExtUtils.GitUI;
-using GitUI;
-using GitUIPluginInterfaces;
-using Newtonsoft.Json.Linq;
-using ResourceManager;
-
-namespace GitExtensions.GerritPlugin
-{
- public partial class FormGerritDownload : FormGerritBase
- {
- private string _currentBranchRemote;
-
- #region Translation
- private readonly TranslationString _downloadGerritChangeCaption = new("Download Gerrit Change");
-
- private readonly TranslationString _downloadCaption = new("Download change {0}");
-
- private readonly TranslationString _error = new("Error");
- private readonly TranslationString _selectRemote = new("Please select a remote repository");
- private readonly TranslationString _selectChange = new("Please enter a change");
- private readonly TranslationString _cannotGetChangeDetails = new("Could not retrieve the change details");
- private readonly TranslationString _cannotGetPatchSetDetails = new("Could not retrieve the patchset details");
- private readonly TranslationString _changeHelp = new("Enter the Change-Id or the number from the Gerrit URL");
- private readonly TranslationString _patchSetHelp = new("Optionally enter the Patchset # to download (the latest by default)");
- #endregion
-
- public FormGerritDownload(IGitUICommands uiCommand)
- : base(uiCommand)
- {
- InitializeComponent();
- InitializeComplete();
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text.RegularExpressions;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+using GitCommands;
+using GitCommands.Git.Commands;
+using GitExtUtils.GitUI;
+using GitUI;
+using GitUIPluginInterfaces;
+using Newtonsoft.Json.Linq;
+using ResourceManager;
+
+namespace GitExtensions.GerritPlugin
+{
+ public partial class FormGerritDownload : FormGerritBase
+ {
+ private string _currentBranchRemote;
+
+ #region Translation
+ private readonly TranslationString _downloadGerritChangeCaption = new("Download Gerrit Change");
+
+ private readonly TranslationString _downloadCaption = new("Download change {0}");
+
+ private readonly TranslationString _error = new("Error");
+ private readonly TranslationString _selectRemote = new("Please select a remote repository");
+ private readonly TranslationString _selectChange = new("Please enter a change");
+ private readonly TranslationString _cannotGetChangeDetails = new("Could not retrieve the change details");
+ private readonly TranslationString _cannotGetPatchSetDetails = new("Could not retrieve the patchset details");
+ private readonly TranslationString _changeHelp = new("Enter the Change-Id or the number from the Gerrit URL");
+ private readonly TranslationString _patchSetHelp = new("Optionally enter the Patchset # to download (the latest by default)");
+ #endregion
+
+ public FormGerritDownload(IGitUICommands uiCommand)
+ : base(uiCommand)
+ {
+ InitializeComponent();
+ InitializeComplete();
+ }
+
+ protected ToolTip ToolTip => toolTip;
+
+ private void DownloadClick(object sender, EventArgs e)
+ {
+ if (ThreadHelper.JoinableTaskFactory.Run(() => DownloadChangeAsync(this)))
+ {
+ Close();
+ }
+ }
+
+ private async Task DownloadChangeAsync(IWin32Window owner)
+ {
+ await this.SwitchToMainThreadAsync();
+
+ string change = _NO_TRANSLATE_Change.Text.Trim();
+
+ if (string.IsNullOrEmpty(_NO_TRANSLATE_Remotes.Text))
+ {
+ MessageBox.Show(owner, _selectRemote.Text, _error.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return false;
+ }
+
+ if (string.IsNullOrEmpty(change))
+ {
+ MessageBox.Show(owner, _selectChange.Text, _error.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return false;
+ }
+
+ GerritUtil.StartAgent(owner, Module, _NO_TRANSLATE_Remotes.Text);
+
+ int? patchSet = null;
+ if (int.TryParse(_NO_TRANSLATE_Patchset.Text.Trim(), out int inputtedPatchSet))
+ {
+ patchSet = inputtedPatchSet;
+ }
+
+ var reviewInfo = await LoadReviewInfoAsync(patchSet);
+ await this.SwitchToMainThreadAsync();
+
+ if (reviewInfo?["id"] == null)
+ {
+ MessageBox.Show(owner, _cannotGetChangeDetails.Text, _error.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return false;
+ }
+
+ // The user can enter both the Change-Id or the number. Here we
+ // force the number to get prettier branches.
+
+ JObject patchSetInfo = patchSet == null
+ ? (JObject)reviewInfo["currentPatchSet"]
+ : (JObject)((JArray)reviewInfo["patchSets"]).FirstOrDefault(q => (int)q["number"] == patchSet);
+ if (patchSetInfo == null)
+ {
+ MessageBox.Show(owner, _cannotGetPatchSetDetails.Text, _error.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return false;
+ }
+
+ change = (string)reviewInfo["number"];
+ string topic = _NO_TRANSLATE_TopicBranch.Text.Trim();
+
+ if (string.IsNullOrEmpty(topic))
+ {
+ var topicNode = (JValue)reviewInfo["topic"];
+ topic = topicNode == null
+ ? change + "/" + (string)patchSetInfo["number"]
+ : (string)topicNode.Value;
+ }
+
+ var authorValue = (string)((JValue)reviewInfo["owner"]["name"]).Value;
+ string author = Regex.Replace(authorValue.ToLowerInvariant(), "\\W+", "_");
+ string branchName = "review/" + author + "/" + topic;
+ var refSpec = (string)((JValue)patchSetInfo["ref"]).Value;
+
+ var fetchCommand = UiCommands.CreateRemoteCommand();
+
+ fetchCommand.CommandText = FetchCommand(_NO_TRANSLATE_Remotes.Text, refSpec);
+
+ if (!RunCommand(fetchCommand, change))
+ {
+ return false;
+ }
+
+ var checkoutCommand = UiCommands.CreateRemoteCommand();
+
+ checkoutCommand.CommandText = GitCommandHelpers.BranchCmd(branchName, "FETCH_HEAD", true);
+ checkoutCommand.Completed += (s, e) =>
+ {
+ if (e.IsError && e.Command.CommandText.Contains("already exists"))
+ {
+ // Recycle the current review branch.
+
+ var recycleCommand = UiCommands.CreateRemoteCommand();
+
+ recycleCommand.CommandText = "checkout " + branchName;
+
+ if (!RunCommand(recycleCommand, change))
+ {
+ return;
+ }
+
+ var resetCommand = UiCommands.CreateRemoteCommand();
+
+ resetCommand.CommandText = GitCommandHelpers.ResetCmd(ResetMode.Hard, "FETCH_HEAD");
+
+ if (!RunCommand(resetCommand, change))
+ {
+ return;
+ }
+
+ e = new GitRemoteCommandCompletedEventArgs(e.Command, false, e.Handled);
+ }
+ };
+
+ return RunCommand(checkoutCommand, change);
+ }
+
+ private bool RunCommand(IGitRemoteCommand command, string change)
+ {
+ command.OwnerForm = this;
+ command.Title = string.Format(_downloadCaption.Text, change);
+ command.Remote = _NO_TRANSLATE_Remotes.Text;
+
+ command.Execute();
+
+ return !command.ErrorOccurred;
+ }
+
+ private static string FetchCommand(string remote, string remoteBranch)
+ {
+ remote = FixPath(remote);
+
+ // Remove spaces...
+ remoteBranch = remoteBranch?.Replace(" ", string.Empty);
+
+ return "fetch --progress \"" + remote.Trim() + "\" " + remoteBranch;
+ }
+
+ private static string FixPath(string path)
+ {
+ path = path.Trim();
+ return path.ToPosixPath();
}
- protected ToolTip ToolTip => toolTip;
-
- private void DownloadClick(object sender, EventArgs e)
- {
- if (ThreadHelper.JoinableTaskFactory.Run(() => DownloadChangeAsync(this)))
- {
- Close();
- }
- }
-
- private async Task DownloadChangeAsync(IWin32Window owner)
- {
- await this.SwitchToMainThreadAsync();
-
- string change = _NO_TRANSLATE_Change.Text.Trim();
-
- if (string.IsNullOrEmpty(_NO_TRANSLATE_Remotes.Text))
- {
- MessageBox.Show(owner, _selectRemote.Text, _error.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
- return false;
- }
-
- if (string.IsNullOrEmpty(change))
- {
- MessageBox.Show(owner, _selectChange.Text, _error.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
- return false;
- }
-
- GerritUtil.StartAgent(owner, Module, _NO_TRANSLATE_Remotes.Text);
-
- int? patchSet = null;
- if (int.TryParse(_NO_TRANSLATE_Patchset.Text.Trim(), out int inputtedPatchSet))
- {
- patchSet = inputtedPatchSet;
- }
-
- var reviewInfo = await LoadReviewInfoAsync(patchSet);
- await this.SwitchToMainThreadAsync();
-
- if (reviewInfo?["id"] == null)
- {
- MessageBox.Show(owner, _cannotGetChangeDetails.Text, _error.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
- return false;
- }
-
- // The user can enter both the Change-Id or the number. Here we
- // force the number to get prettier branches.
-
- JObject patchSetInfo = patchSet == null
- ? (JObject)reviewInfo["currentPatchSet"]
- : (JObject)((JArray)reviewInfo["patchSets"]).FirstOrDefault(q => (int)q["number"] == patchSet);
- if (patchSetInfo == null)
- {
- MessageBox.Show(owner, _cannotGetPatchSetDetails.Text, _error.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
- return false;
- }
-
- change = (string)reviewInfo["number"];
- string topic = _NO_TRANSLATE_TopicBranch.Text.Trim();
-
- if (string.IsNullOrEmpty(topic))
- {
- var topicNode = (JValue)reviewInfo["topic"];
- topic = topicNode == null
- ? change + "/" + (string)patchSetInfo["number"]
- : (string)topicNode.Value;
- }
-
- var authorValue = (string)((JValue)reviewInfo["owner"]["name"]).Value;
- string author = Regex.Replace(authorValue.ToLowerInvariant(), "\\W+", "_");
- string branchName = "review/" + author + "/" + topic;
- var refSpec = (string)((JValue)patchSetInfo["ref"]).Value;
-
- var fetchCommand = UiCommands.CreateRemoteCommand();
-
- fetchCommand.CommandText = FetchCommand(_NO_TRANSLATE_Remotes.Text, refSpec);
-
- if (!RunCommand(fetchCommand, change))
- {
- return false;
- }
-
- var checkoutCommand = UiCommands.CreateRemoteCommand();
-
- checkoutCommand.CommandText = GitCommandHelpers.BranchCmd(branchName, "FETCH_HEAD", true);
- checkoutCommand.Completed += (s, e) =>
- {
- if (e.IsError && e.Command.CommandText.Contains("already exists"))
- {
- // Recycle the current review branch.
-
- var recycleCommand = UiCommands.CreateRemoteCommand();
-
- recycleCommand.CommandText = "checkout " + branchName;
-
- if (!RunCommand(recycleCommand, change))
- {
- return;
- }
-
- var resetCommand = UiCommands.CreateRemoteCommand();
-
- resetCommand.CommandText = GitCommandHelpers.ResetCmd(ResetMode.Hard, "FETCH_HEAD");
-
- if (!RunCommand(resetCommand, change))
- {
- return;
- }
-
- e = new GitRemoteCommandCompletedEventArgs(e.Command, false, e.Handled);
- }
- };
-
- return RunCommand(checkoutCommand, change);
- }
-
- private bool RunCommand(IGitRemoteCommand command, string change)
- {
- command.OwnerForm = this;
- command.Title = string.Format(_downloadCaption.Text, change);
- command.Remote = _NO_TRANSLATE_Remotes.Text;
-
- command.Execute();
-
- return !command.ErrorOccurred;
- }
-
- private static string FetchCommand(string remote, string remoteBranch)
- {
- var progressOption = string.Empty;
- if (GitVersion.Current.FetchCanAskForProgress)
- {
- progressOption = "--progress ";
- }
-
- remote = FixPath(remote);
-
- // Remove spaces...
- remoteBranch = remoteBranch?.Replace(" ", string.Empty);
-
- return "fetch " + progressOption + "\"" + remote.Trim() + "\" " + remoteBranch;
- }
-
- private static string FixPath(string path)
- {
- path = path.Trim();
- return path.ToPosixPath();
- }
-
- private async Task LoadReviewInfoAsync(int? patchSet = null)
- {
- var fetchUrl = GerritUtil.GetFetchUrl(Module, _currentBranchRemote);
-
- string projectName = fetchUrl.AbsolutePath.TrimStart('/');
-
- if (projectName.EndsWith(".git"))
- {
- projectName = projectName.Substring(0, projectName.Length - 4);
- }
-
- string change = await GerritUtil
- .RunGerritCommandAsync(
- this,
- Module,
- string.Format(
- "gerrit query --format=JSON project:{0} {1} change:{2}",
- projectName,
- patchSet == null ? "--current-patch-set" : "--patch-sets",
- _NO_TRANSLATE_Change.Text),
- fetchUrl,
- _currentBranchRemote,
- null)
- .ConfigureAwait(false);
-
- foreach (string line in change.Split('\n'))
- {
- try
- {
- return JObject.Parse(line);
- }
- catch
- {
- // Ignore exceptions.
- }
- }
-
- return null;
- }
-
- private void FormGerritDownloadLoad(object sender, EventArgs e)
- {
- _NO_TRANSLATE_Remotes.DataSource = Module.GetRemoteNames();
-
- _currentBranchRemote = Settings.DefaultRemote;
-
- var remotes = (IList)_NO_TRANSLATE_Remotes.DataSource;
- int i = remotes.IndexOf(_currentBranchRemote);
- _NO_TRANSLATE_Remotes.SelectedIndex = i >= 0 ? i : 0;
-
- _NO_TRANSLATE_Change.Select();
-
- Text = string.Concat(_downloadGerritChangeCaption.Text, " (", Module.WorkingDir, ")");
-
- ToolTip.SetToolTip(_NO_TRANSLATE_ChangeHelp, _changeHelp.Text);
- ToolTip.SetToolTip(_NO_TRANSLATE_PatchsetHelp, _patchSetHelp.Text);
- _NO_TRANSLATE_ChangeHelp.Size = DpiUtil.Scale(_NO_TRANSLATE_ChangeHelp.Size);
- _NO_TRANSLATE_PatchsetHelp.Size = DpiUtil.Scale(_NO_TRANSLATE_PatchsetHelp.Size);
- }
-
- private void AddRemoteClick(object sender, EventArgs e)
- {
- UiCommands.StartRemotesDialog(this);
- _NO_TRANSLATE_Remotes.DataSource = Module.GetRemoteNames();
- }
- }
+ private async Task LoadReviewInfoAsync(int? patchSet = null)
+ {
+ var fetchUrl = GerritUtil.GetFetchUrl(Module, _currentBranchRemote);
+
+ string projectName = fetchUrl.AbsolutePath.TrimStart('/');
+
+ if (projectName.EndsWith(".git"))
+ {
+ projectName = projectName[..^4];
+ }
+
+ string change = await GerritUtil
+ .RunGerritCommandAsync(
+ this,
+ Module,
+ string.Format(
+ "gerrit query --format=JSON project:{0} {1} change:{2}",
+ projectName,
+ patchSet == null ? "--current-patch-set" : "--patch-sets",
+ _NO_TRANSLATE_Change.Text),
+ fetchUrl,
+ _currentBranchRemote,
+ null)
+ .ConfigureAwait(false);
+
+ foreach (string line in change.Split('\n'))
+ {
+ try
+ {
+ return JObject.Parse(line);
+ }
+ catch
+ {
+ // Ignore exceptions.
+ }
+ }
+
+ return null;
+ }
+
+ private void FormGerritDownloadLoad(object sender, EventArgs e)
+ {
+ _NO_TRANSLATE_Remotes.DataSource = Module.GetRemoteNames();
+
+ _currentBranchRemote = Settings.DefaultRemote;
+
+ var remotes = (IList)_NO_TRANSLATE_Remotes.DataSource;
+ int i = remotes.IndexOf(_currentBranchRemote);
+ _NO_TRANSLATE_Remotes.SelectedIndex = i >= 0 ? i : 0;
+
+ _NO_TRANSLATE_Change.Select();
+
+ Text = string.Concat(_downloadGerritChangeCaption.Text, " (", Module.WorkingDir, ")");
+
+ ToolTip.SetToolTip(_NO_TRANSLATE_ChangeHelp, _changeHelp.Text);
+ ToolTip.SetToolTip(_NO_TRANSLATE_PatchsetHelp, _patchSetHelp.Text);
+ _NO_TRANSLATE_ChangeHelp.Size = DpiUtil.Scale(_NO_TRANSLATE_ChangeHelp.Size);
+ _NO_TRANSLATE_PatchsetHelp.Size = DpiUtil.Scale(_NO_TRANSLATE_PatchsetHelp.Size);
+ }
+
+ private void AddRemoteClick(object sender, EventArgs e)
+ {
+ UiCommands.StartRemotesDialog(this);
+ _NO_TRANSLATE_Remotes.DataSource = Module.GetRemoteNames();
+ }
+ }
}
\ No newline at end of file
diff --git a/src/GitExtensions.GerritPlugin/FormGerritPublish.cs b/src/GitExtensions.GerritPlugin/FormGerritPublish.cs
index a538cb2..5724560 100644
--- a/src/GitExtensions.GerritPlugin/FormGerritPublish.cs
+++ b/src/GitExtensions.GerritPlugin/FormGerritPublish.cs
@@ -41,8 +41,7 @@ protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
- _capabilities.PublishTypes.ForEach(
- item => PublishType.Items.Add(item));
+ _capabilities.PublishTypes.ForEach(item => PublishType.Items.Add(item));
PublishType.SelectedIndex = 0;
}
@@ -58,7 +57,7 @@ private static ArgumentString PushCmd(string remote, string toBranch)
{
return new GitArgumentBuilder("push")
{
- { GitVersion.Current.PushCanAskForProgress, "--progress" },
+ "--progress",
remote.ToPosixPath().Trim().Quote(),
$"HEAD:{GitRefName.GetFullBranchName(toBranch)?.Replace(" ", string.Empty)}"
};
@@ -177,7 +176,9 @@ private void FormGerritPublishLoad(object sender, EventArgs e)
int remoteIndex = remotes.IndexOf(_currentBranchRemote);
_NO_TRANSLATE_Remotes.SelectedIndex = remoteIndex >= 0 ? remoteIndex : 0;
- _NO_TRANSLATE_Branch.DataSource = Module.GetRefs(false).Select(branch => branch.LocalName).ToList();
+ _NO_TRANSLATE_Branch.DataSource = Module.GetRefs(RefsFilter.Remotes)
+ .Select(branch => branch.LocalName)
+ .ToList();
_NO_TRANSLATE_Branch.Text = GetBranchName(Settings.DefaultBranch);
var branches = (IList)_NO_TRANSLATE_Branch.DataSource;
diff --git a/src/GitExtensions.GerritPlugin/GerritPlugin.cs b/src/GitExtensions.GerritPlugin/GerritPlugin.cs
index c533396..d66ac98 100644
--- a/src/GitExtensions.GerritPlugin/GerritPlugin.cs
+++ b/src/GitExtensions.GerritPlugin/GerritPlugin.cs
@@ -94,7 +94,7 @@ private void UpdateGerritMenuItems(object sender, GitUIEventArgs e)
bool isEnabled = _gerritEnabled.ValueOrDefault(Settings);
bool hasGitreviewFile = File.Exists(Path.Combine(gitModule.WorkingDir, ".gitreview"));
bool showGerritItems = isEnabled && isValidWorkingDir && hasGitreviewFile;
- bool hasValidCommitMsgHook = HasValidCommitMsgHook(gitModule, true);
+ bool hasValidCommitMsgHook = showGerritItems && HasValidCommitMsgHook(gitModule, true);
if (isValidWorkingDir)
{
@@ -435,7 +435,7 @@ private async Task DownloadFromScpAsync(GerritSettings settings)
return null;
}
- string header = content.Substring(0, index);
+ string header = content[..index];
if (!header.EndsWith(" commit-msg"))
{
@@ -445,7 +445,7 @@ private async Task DownloadFromScpAsync(GerritSettings settings)
// This looks like a valid scp response; return the rest of the
// response.
- content = content.Substring(index + 1);
+ content = content[(index + 1)..];
// The file should be terminated by a nul.
@@ -455,7 +455,7 @@ private async Task DownloadFromScpAsync(GerritSettings settings)
if (index != -1)
{
- content = content.Substring(0, index);
+ content = content[..index];
}
return content;
diff --git a/src/GitExtensions.GerritPlugin/GerritUtil.cs b/src/GitExtensions.GerritPlugin/GerritUtil.cs
index b9d12ce..67904e4 100644
--- a/src/GitExtensions.GerritPlugin/GerritUtil.cs
+++ b/src/GitExtensions.GerritPlugin/GerritUtil.cs
@@ -81,7 +81,7 @@ public static async Task RunGerritCommandAsync(
var sshCmd = GitSshHelpers.Plink()
? AppSettings.Plink
- : SshPathLocatorInstance.Find(AppSettings.GitBinDir);
+ : SshPathLocatorInstance.GetSshFromGitDir(AppSettings.GitBinDir);
if (string.IsNullOrEmpty(sshCmd))
{
@@ -115,7 +115,7 @@ public static async Task RunGerritCommandAsync(
sb.Append(" \"");
sb.Append(command);
- sb.Append("\"");
+ sb.Append('"');
return await new Executable(sshCmd)
.GetOutputAsync(sb.ToString(), stdIn)
diff --git a/src/GitExtensions.GerritPlugin/GitExtensions.GerritPlugin.csproj b/src/GitExtensions.GerritPlugin/GitExtensions.GerritPlugin.csproj
index 1277762..e6dea09 100644
--- a/src/GitExtensions.GerritPlugin/GitExtensions.GerritPlugin.csproj
+++ b/src/GitExtensions.GerritPlugin/GitExtensions.GerritPlugin.csproj
@@ -4,19 +4,17 @@
true
-
-
-
-
-
true
-
+
+ true
+
+
true
-
+
true
@@ -25,7 +23,7 @@
-
+
@@ -48,7 +46,6 @@
-
diff --git a/src/GitExtensions.GerritPlugin/GitExtensions.GerritPlugin.csproj.user b/src/GitExtensions.GerritPlugin/GitExtensions.GerritPlugin.csproj.user
index 70526f8..8f5e213 100644
--- a/src/GitExtensions.GerritPlugin/GitExtensions.GerritPlugin.csproj.user
+++ b/src/GitExtensions.GerritPlugin/GitExtensions.GerritPlugin.csproj.user
@@ -1,13 +1,13 @@
-
-
-
-
- ..\..\..\gitextensions.shared
-
- v3.5.4
-
- GitHub
-
-
-
+
+
+
+
+ ..\..\..\gitextensions.shared
+
+ latest
+
+ AppVeyor
+
+
+
\ No newline at end of file
diff --git a/src/GitExtensions.GerritPlugin/GitExtensions.GerritPlugin.nuspec b/src/GitExtensions.GerritPlugin/GitExtensions.GerritPlugin.nuspec
index e08c18d..2f6326d 100644
--- a/src/GitExtensions.GerritPlugin/GitExtensions.GerritPlugin.nuspec
+++ b/src/GitExtensions.GerritPlugin/GitExtensions.GerritPlugin.nuspec
@@ -11,17 +11,17 @@
Resources\IconGerrit.png
-
+
-
-
-
+
+
+
-
+
\ No newline at end of file
diff --git a/src/GitExtensions.GerritPlugin/app.config b/src/GitExtensions.GerritPlugin/app.config
deleted file mode 100644
index 4a96db7..0000000
--- a/src/GitExtensions.GerritPlugin/app.config
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-