Skip to content

Commit

Permalink
Fix error from stricter git permission checks
Browse files Browse the repository at this point in the history
git version 2.35 introduced strict checks on directory ownership
refusing to operate on directories not owned by the user calling git.
In the case of openQA tests not running from openQA worker cache
synchronized test distributions this caused the git revision of test
distribution directories to be not parsed and ending up as 'UNKNOWN',
our fallback string.

This commit fixes this problem by adding the requested git directory to
the list of "safe directories" in a temporary user's global git config.
This of course means that the user account must be able to write to the
according config file so this is why we use a temporary home directory.

Related progress issue: https://progress.opensuse.org/issues/113030
  • Loading branch information
okurz committed Jul 6, 2022
1 parent 1daea56 commit bafb9ef
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 7 additions & 2 deletions OpenQA/Isotovideo/Utils.pm
Expand Up @@ -15,8 +15,13 @@ use Try::Tiny;
our @EXPORT_OK = qw(git_rev_parse checkout_git_repo_and_branch
checkout_git_refspec handle_generated_assets load_test_schedule);

sub git_rev_parse($dirname) {
chomp(my $version = (-e "$dirname/.git" ? qx{git -C $dirname rev-parse HEAD} : '') || 'UNKNOWN');
sub git_rev_parse ($dirname) {
return 'UNKNOWN' unless -e "$dirname/.git";
my $checksafe = q{git config --global --get safe.directory | grep -q};
my $addsafe = q{HOME=$(mktemp -d --tmpdir os-autoinst-git.XXXXX) && git config --global --add safe.directory};
my $version = qx{($checksafe "$dirname" && git -C "$dirname" rev-parse HEAD || $addsafe "$dirname" && git -C "$dirname" rev-parse HEAD && rm -r \$HOME)};
$version ||= '(unreadable git hash)';
chomp($version);
return $version;
}

Expand Down
2 changes: 2 additions & 0 deletions t/99-full-stack.t
Expand Up @@ -49,6 +49,8 @@ EOV
path('live_log')->touch;
system("cd $toplevel_dir && perl $toplevel_dir/isotovideo --workdir $pool_dir -d 2>&1 | tee $pool_dir/autoinst-log.txt");
my $log = path('autoinst-log.txt')->slurp;
my $version = -e "$toplevel_dir/.git" ? qr/[a-f0-9]+/ : 'UNKNOWN';
like $log, qr/Current version is $version [interface v[0-9]+]/, 'version read from git';
like $log, qr/\d*: EXIT 0/, 'test executed fine';
like $log, qr/\d* Snapshots are supported/, 'Snapshots are enabled';
unlike $log, qr/Tests died:/, 'Tests did not fail within modules' or diag "autoinst-log.txt: $log";
Expand Down

0 comments on commit bafb9ef

Please sign in to comment.