-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix problem with incorrect building command line arguments #3551
Fix problem with incorrect building command line arguments #3551
Conversation
@jbialobr is encouraging us to review each other's changes so if you don't mind, I'll review yours. Perhaps you can take a look at my change as well. |
GitUI/CommandsDialogs/FormPush.cs
Outdated
@@ -502,15 +502,15 @@ private bool HandlePushOnExit(ref bool isError, FormProcess form) | |||
|
|||
if (forcePush) | |||
{ | |||
if (!form.ProcessArguments.Contains(" -f ") && !form.ProcessArguments.Contains(" --force")) | |||
if (!form.ProcessArguments.Contains(" -f ") && !form.ProcessArguments.Contains(" --force") && !form.ProcessArguments.EndsWith(" -f")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand why you're checking if the args ends with -f here. Even if it were necessary, wouldn't you want to also check if it's --force?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not actual anymore, but answer is: I add -f to end of arguments, so check .Contains(" -f ") will not work because of trailing space.
So this condition should cover all possible cases:
push -f origin
push --force origin
push --force-with-lease origin
push origin ... -f
push origin ... --force
push origin ... --force-with-lease
GitUI/CommandsDialogs/FormPush.cs
Outdated
{ | ||
if (GitCommandHelpers.VersionInUse.SupportPushForceWithLease) | ||
{ | ||
form.ProcessArguments = form.ProcessArguments.Replace("push", "push --force-with-lease"); | ||
form.ProcessArguments = form.ProcessArguments + " --force-with-lease"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think appending to the end of the args is the right thing to do. At this point, args will look something like:
push --recurse-submodules=check --progress "origin" refs/heads/test-force-push:refs/heads/test-force-push
We usually want to avoid adding args after we specify the remote and name of branch. I'm surprised this works.
I tried something locally, and this seems to work:
if (forcePush)
{
if (!form.ProcessArguments.Contains(" -f ") && !form.ProcessArguments.Contains(" --force"))
{
string forceArg = GitCommandHelpers.VersionInUse.SupportPushForceWithLease? " --force-with-lease" : " -f";
form.ProcessArguments = form.ProcessArguments.Insert(form.ProcessArguments.IndexOf("push") + "push".Length, forceArg);
}
Or if we can assume "force" is always the first value in the args list, it can be simplified to:
if (forcePush)
{
if (!form.ProcessArguments.Contains(" -f ") && !form.ProcessArguments.Contains(" --force"))
{
string forceArg = GitCommandHelpers.VersionInUse.SupportPushForceWithLease? " --force-with-lease" : " -f";
form.ProcessArguments = form.ProcessArguments.Insert("push".Length, forceArg);
}
fd30312
to
3c80f98
Compare
@amaiorano, I update fix to your variant. I made it slightly more strict. |
GitUI/CommandsDialogs/FormPush.cs
Outdated
@@ -504,13 +504,14 @@ private bool HandlePushOnExit(ref bool isError, FormProcess form) | |||
{ | |||
if (!form.ProcessArguments.Contains(" -f ") && !form.ProcessArguments.Contains(" --force")) | |||
{ | |||
if (GitCommandHelpers.VersionInUse.SupportPushForceWithLease) | |||
if(form.ProcessArguments.StartsWith("push ", StringComparison.OrdinalIgnoreCase)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is better, but a few things:
- Missing a space between if and the open parenthesis.
- No need to check with ignore case for "push", Git is case sensitive so if it were anything but "push" it wouldn't work.
- In the few places in this code base where Debug.Assert is used, System.Diagnostics is imported at the top.
- I'm not a fan of Debug.Assert(false, ...) as we don't see the condition for the failure. In this case, it is extremely unlikely that "push" will be missing, so I would rather we just assert that it starts with "push", then just assume it, so like:
if (!form.ProcessArguments.Contains(" -f ") && !form.ProcessArguments.Contains(" --force"))
{
Debug.Assert(form.ProcessArguments.StartsWith("push"), "Arguments should start with 'push' command");
string forceArg = GitCommandHelpers.VersionInUse.SupportPushForceWithLease ? " --force-with-lease" : " -f";
form.ProcessArguments = form.ProcessArguments.Insert("push".Length, forceArg);
}
I personally prefer this over having the "safe code" with the else asserting false, but perhaps we should ask @jbialobr to weigh in on this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I personally prefer this over having the "safe code" with the else asserting false, but perhaps we should ask @jbialobr to weigh in on this.
First of all, I want to thank you for reviewing PRs. This is a community project and I don't want to force my coding preferences. Let's wait for @azarkevich to see his opinion (pros and cons). I will have to decide only If you won't find an agreement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree with your proposals and remarks. Pushed new version.
Though I use Trace.Assert instead of Debug.Assert, so this condition will be verified even in Release.
3c80f98
to
915563d
Compare
Branch name contains word 'push' (for example my-push-implementation) and remote reject push due to non-fast-forward and user select 'retry with force' then 'push' in branch name was replaced with 'push --force-with-lease'
915563d
to
d87d91a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me!
…-with-force Fix problem with incorrect building command line arguments (cherry picked from commit ca42b5e) # Conflicts: # GitUI/CommandsDialogs/FormPush.cs
Situation:
Branch name contains word
push
(for examplepr/fix-cmdline-in-retry-push-with-force
)and remote reject push due to non-fast-forward
and user select
retry with force
then word
push
in branch name was replaced with 'push --force-with-lease' by.Replace("push", "push --force-with-lease")