Skip to content

Instantly share code, notes, and snippets.

@okurz
Created July 13, 2022 15:00
Show Gist options
  • Save okurz/49b7ca78611350b6293fc2a79e1f8345 to your computer and use it in GitHub Desktop.
Save okurz/49b7ca78611350b6293fc2a79e1f8345 to your computer and use it in GitHub Desktop.
# succeeds as expected, shows hash
sudo -u _openqa-worker perl -wE '
my $dirname = "/var/lib/openqa/share/tests/opensuse";
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 && echo rm -r \$HOME)};
$version ||= "(unreadable git hash)";
chomp($version);
say "HASH: $version"'
# fails as expected, shows git error about unsafe repository
sudo -u _openqa-worker perl -wE '
my $dirname = "/var/lib/openqa/share/tests/opensuse";
my $version = qx{git -C "$dirname" rev-parse HEAD};
$version ||= "(unreadable git hash)";
chomp($version);
say "HASH: $version"'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment