Skip to content
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 quoting of git ssh arguments #5947

Merged
merged 1 commit into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/OpenQA/Git.pm
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ sub _run_cmd ($self, $args, $options = {}) {
my $include_git_path = $options->{include_git_path} // 1;
my $ssh_batchmode = $options->{ssh_batchmode} // 0;
my @cmd;
push @cmd, 'env', 'GIT_SSH_COMMAND="ssh -oBatchMode=yes"' if $ssh_batchmode;
push @cmd, 'env', 'GIT_SSH_COMMAND=ssh -oBatchMode=yes' if $ssh_batchmode;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have unit test coverage for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about it, but no good idea yet.
e.g. if we actually ran git on temporary git repositories created during unit tests, that would be an improvement, but we would use local git repositories in paths, not remote ones, I guess, so the ssh ... stuff would never be called.
Ideas welcome.
In any case, we should deploy this fix.

push @cmd, $self->_prepare_git_command($include_git_path), @$args;

my $result = run_cmd_with_log_return_error(\@cmd);
Expand Down
16 changes: 8 additions & 8 deletions t/14-grutasks-git.t
Original file line number Diff line number Diff line change
Expand Up @@ -94,18 +94,18 @@ subtest 'git clone' => sub {
['get-url' => 'git -C /branch/ remote get-url origin'],
['check dirty' => 'git -C /branch/ diff-index HEAD --exit-code'],
['current branch' => 'git -C /branch/ branch --show-current'],
['fetch branch' => 'env GIT_SSH_COMMAND="ssh -oBatchMode=yes" git -C /branch/ fetch origin foobranch'],
['fetch branch' => 'env GIT_SSH_COMMAND=ssh -oBatchMode=yes git -C /branch/ fetch origin foobranch'],

# /default/
['get-url' => 'git -C /default/ remote get-url origin'],
['check dirty' => 'git -C /default/ diff-index HEAD --exit-code'],
['default remote' => 'env GIT_SSH_COMMAND="ssh -oBatchMode=yes" git ls-remote --symref http://localhost/foo.git HEAD'],
['default remote' => 'env GIT_SSH_COMMAND=ssh -oBatchMode=yes git ls-remote --symref http://localhost/foo.git HEAD'],
['current branch' => 'git -C /default/ branch --show-current'],
['fetch default' => 'env GIT_SSH_COMMAND="ssh -oBatchMode=yes" git -C /default/ fetch origin master'],
['fetch default' => 'env GIT_SSH_COMMAND=ssh -oBatchMode=yes git -C /default/ fetch origin master'],
['reset' => 'git -C /default/ reset --hard origin/master'],

# /this_directory_does_not_exist/
['clone' => 'env GIT_SSH_COMMAND="ssh -oBatchMode=yes" git clone http://localhost/bar.git /this_directory_does_not_exist/'],
['clone' => 'env GIT_SSH_COMMAND=ssh -oBatchMode=yes git clone http://localhost/bar.git /this_directory_does_not_exist/'],
];
#>>> no perltidy
for my $i (0 .. $#$expected_calls) {
Expand Down Expand Up @@ -174,17 +174,17 @@ subtest 'git clone' => sub {
# /opensuse
['get-url' => 'git -C /opensuse remote get-url origin'],
['check dirty' => 'git -C /opensuse diff-index HEAD --exit-code'],
['default remote' => 'env GIT_SSH_COMMAND="ssh -oBatchMode=yes" git ls-remote --symref http://osado HEAD'],
['default remote' => 'env GIT_SSH_COMMAND=ssh -oBatchMode=yes git ls-remote --symref http://osado HEAD'],
['current branch' => 'git -C /opensuse branch --show-current'],
['fetch default ' => 'env GIT_SSH_COMMAND="ssh -oBatchMode=yes" git -C /opensuse fetch origin master'],
['fetch default ' => 'env GIT_SSH_COMMAND=ssh -oBatchMode=yes git -C /opensuse fetch origin master'],
['reset' => 'git -C /opensuse reset --hard origin/master'],

# /opensuse/needles
['get-url' => 'git -C /opensuse/needles remote get-url origin'],
['check dirty' => 'git -C /opensuse/needles diff-index HEAD --exit-code'],
['default remote' => 'env GIT_SSH_COMMAND="ssh -oBatchMode=yes" git ls-remote --symref http://osado HEAD'],
['default remote' => 'env GIT_SSH_COMMAND=ssh -oBatchMode=yes git ls-remote --symref http://osado HEAD'],
['current branch' => 'git -C /opensuse/needles branch --show-current'],
['fetch branch' => 'env GIT_SSH_COMMAND="ssh -oBatchMode=yes" git -C /opensuse/needles fetch origin master'],
['fetch branch' => 'env GIT_SSH_COMMAND=ssh -oBatchMode=yes git -C /opensuse/needles fetch origin master'],
['reset' => 'git -C /opensuse/needles reset --hard origin/master'],
];
#>>> no perltidy
Expand Down
Loading