Skip to content

Commit

Permalink
Only update clean git checkouts
Browse files Browse the repository at this point in the history
  • Loading branch information
asdil12 committed Aug 29, 2024
1 parent aa42e73 commit 9197913
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions lib/OpenQA/Task/Git/Clone.pm
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ sub _git_reset_hard ($path, $branch) {
die "Failed to reset to 'origin/$branch': $r->{stderr}" unless $r->{status};
}

sub _git_is_workdir_clean ($path) {
my $r = run_cmd_with_log_return_error(['git', '-C', $path, 'diff-index', 'HEAD', '--exit-code']);
return $r->{status};
}


sub _git_clone ($job, $ctx, $path, $url) {
$ctx->debug(qq{Updating $path to $url});
$url = Mojo::URL->new($url);
Expand All @@ -112,10 +118,15 @@ sub _git_clone ($job, $ctx, $path, $url) {
$ctx->debug(qq{Remote default branch $remote_default});
}

my $current_branch = _get_current_branch($path);
# updating default branch (including checkout)
_git_fetch($path, $requested_branch);
_git_reset_hard($path, $requested_branch) if ($requested_branch eq $current_branch);
if (_git_is_workdir_clean($path)) {
my $current_branch = _get_current_branch($path);
# updating default branch (including checkout)
_git_fetch($path, $requested_branch);
_git_reset_hard($path, $requested_branch) if ($requested_branch eq $current_branch);
}
else {
$ctx->warn("NOT updating dirty git checkout at $path");
}
}

1;

0 comments on commit 9197913

Please sign in to comment.