t7800-difftool.sh: Fix a test failure on Cygwin
PATCH 7/14 t7800-difftool.sh: Fix a test failure on Cygwin
In particular, test 14 'difftool last flag wins' fails. This is caused by git-difftool.perl passing both GIT_DIFFTOOL_NO_PROMPT (='true') and GIT_DIFFTOOL_PROMPT (='true') to the difftool helper script. Despite the appropriate key being deleted from the ENV hash, it seems that once a key has been set in the hash, it gets passed along to the system() call. (ie deleting the key does not do the equivalent of unsetenv()).
In order to fix the problem, we keep track of the required prompt state while processing the arguments, and then set the relevant ENV hash key only once at the end.
--- git-difftool.perl | 12 ++++++++---- 1 files changed, 8 insertions(+), 4 deletions(-)
git-difftool.perl +8 -4
@@ -52,6 +52,7 @@ sub generate_command my @command = (exe('git'), 'diff'); my $skip_next = 0; my $idx = -1; + my $prompt = ''; for my $arg (@ARGV) { $idx++; if ($skip_next) {
@@ -89,13 +90,11 @@ sub generate_command next; } if ($arg eq '-y' || $arg eq '--no-prompt') { - $ENV{GIT_DIFFTOOL_NO_PROMPT} = 'true'; - delete $ENV{GIT_DIFFTOOL_PROMPT}; + $prompt = 'no'; next; } if ($arg eq '--prompt') { - $ENV{GIT_DIFFTOOL_PROMPT} = 'true'; - delete $ENV{GIT_DIFFTOOL_NO_PROMPT}; + $prompt = 'yes'; next; } if ($arg eq '-h' || $arg eq '--help') {
@@ -103,6 +102,11 @@ sub generate_command } push @command, $arg; } + if ($prompt eq 'yes') { + $ENV{GIT_DIFFTOOL_PROMPT} = 'true'; + } elsif ($prompt eq 'no') { + $ENV{GIT_DIFFTOOL_NO_PROMPT} = 'true'; + } return @command }
Signature · 1 line
1.7.3
This is not just "test failure" but can cause a failure in the real life for people who want "the last flag wins" to work, no?
I'll retitle the patch and queue it separately from other test fixes.
Thanks.
Quoted 2 lines · Junio C Hamano
This is not just "test failure" but can cause a failure in the real life for people who want "the last flag wins" to work, no?
Yes, indeed. I was concentrating on fixing test-suite failures (and that can mean you have to modify the test, the application or both) so...
Quoted 1 line
I'll retitle the patch and queue it separately from other test fixes.
Thanks!
ATB,
Ramsay Jones
Quoted 23 lines · Ramsay Jones
In particular, test 14 'difftool last flag wins' fails. This is caused by git-difftool.perl passing both
GIT_DIFFTOOL_NO_PROMPT(='true') andGIT_DIFFTOOL_PROMPT(='true') to the difftool helper script. Despite the appropriate key being deleted from the ENV hash, it seems that once a key has been set in the hash, it gets passed along to thesystem()call. (ie deleting the key does not do the equivalent ofunsetenv()).In order to fix the problem, we keep track of the required prompt state while processing the arguments, and then set the relevant ENV hash key only once at the end.
Signed-off-by Ramsay Jones <[email protected]>--- git-difftool.perl | 12 ++++++++---- 1 files changed, 8 insertions(+), 4 deletions(-)git-difftool.perl +0
-0
git-difftool.perl sub generate_command · line 55
Quoted 4 lines
git-difftool.perl +1
-0@@ -52,6 +52,7 @@ sub generate_command my @command = (exe('git'), 'diff'); my $skip_next = 0; my $idx = -1; + my $prompt = '';
Would it be simpler to set $prompt = 1 and then flip it to 0 when -y | or --no-prompt is supplied?
Quoted 20 lines
git-difftool.perl +2
-4for my $arg (@ARGV) { $idx++; if ($skip_next) {@@ -89,13 +90,11 @@ sub generate_command next; } if ($arg eq '-y' || $arg eq '--no-prompt') { - $ENV{GIT_DIFFTOOL_NO_PROMPT} = 'true'; - delete $ENV{GIT_DIFFTOOL_PROMPT}; + $prompt = 'no'; next; } if ($arg eq '--prompt') { - $ENV{GIT_DIFFTOOL_PROMPT} = 'true'; - delete $ENV{GIT_DIFFTOOL_NO_PROMPT}; + $prompt = 'yes'; next; } if ($arg eq '-h' || $arg eq '--help') {
git-difftool.perl sub generate_command · line 105
Quoted 4 lines
git-difftool.perl +1
-0@@ -103,6 +102,11 @@ sub generate_command } push @command, $arg; } + if ($prompt eq 'yes') {
This would become:
if ($prompt) {
...
}
else {
...
}Quoted 11 lines
git-difftool.perl +4
-0+ $ENV{GIT_DIFFTOOL_PROMPT} = 'true'; + } elsif ($prompt eq 'no') { + $ENV{GIT_DIFFTOOL_NO_PROMPT} = 'true'; + } return @command }Signature · 1 line
1.7.3
Signature · 1 line
David
Quoted 14 lines · David Aguilar
git-difftool.perl sub generate_command · line 55
Quoted 9 lines
git-difftool.perl +1
-0@@ -52,6 +52,7 @@ sub generate_command my @command = (exe('git'), 'diff'); my $skip_next = 0; my $idx = -1; + my $prompt = '';Would it be simpler to set $prompt = 1 and then flip it to 0 when -y | or --no-prompt is supplied?
...
Quoted 8 lines
This would become:
if ($prompt) { ... } else { ... }
But that is not what the patch does, is it?
Isn't it more like initializing $prompt to undef and then the above condition becomes:
if (!defined $prompt) {
; # nothing
elsif ($prompt) {
setenv PROMPT true
} else {
setenv NO_PROMPT true
}no?
Quoted 37 lines · Junio C Hamano
Quoted 13 lines · David Aguilar
git-difftool.perl sub generate_command · line 55
Quoted 9 lines
git-difftool.perl +1
-0@@ -52,6 +52,7 @@ sub generate_command my @command = (exe('git'), 'diff'); my $skip_next = 0; my $idx = -1; + my $prompt = '';Would it be simpler to set $prompt = 1 and then flip it to 0 when -y | or --no-prompt is supplied?
...Quoted 8 lines
This would become:
if ($prompt) { ... } else { ... }But that is not what the patch does, is it?
Isn't it more like initializing $prompt to undef and then the above condition becomes:
if (!defined $prompt) { ; # nothing elsif ($prompt) { setenv PROMPT true } else { setenv NO_PROMPT true }
Quoted 1 line
no?
Yes. :-P
At least that is what I was aiming for.
In particular, if none of -y, --no-prompt or --prompt is passed on the command-line, I don't want to set either key in the hash. (Or, to put it another way, I don't want to change the behaviour in this case, where neither variable is set in the environment of the helper script)
ATB,
Ramsay Jones