GitInput: Avoid fetch if rev is available

Similar to libfetcher in Nix, avoid fetching if rev is already
available.
This commit is contained in:
Christian Kögler 2021-02-07 19:41:01 +01:00
parent d8a5892795
commit a8d20ee46e

View file

@ -141,14 +141,19 @@ sub fetchInput {
die "error creating git repo in `$clonePath':\n$res->{stderr}" if $res->{status}; die "error creating git repo in `$clonePath':\n$res->{stderr}" if $res->{status};
} }
# This command forces the update of the local branch to be in the same as $res = run(cmd => ["git", "cat-file", "-t", $branch], dir => $clonePath);
# the remote branch for whatever the repository state is. This command mirrors if (! _isHash($branch) || $res->{status}) {
# only one branch of the remote repository. # This command forces the update of the local branch to be in the same as
my $localBranch = _isHash($branch) ? "_hydra_tmp" : $branch; # the remote branch for whatever the repository state is. This command mirrors
$res = run(cmd => ["git", "fetch", "-fu", "origin", "+$branch:$localBranch"], dir => $clonePath, # only one branch of the remote repository.
timeout => $cfg->{timeout}); my $localBranch = _isHash($branch) ? "_hydra_tmp" : $branch;
$res = run(cmd => ["git", "fetch", "-fu", "origin"], dir => $clonePath, timeout => $cfg->{timeout}) if $res->{status}; $res = run(cmd => ["git", "fetch", "-fu", "origin", "+$branch:$localBranch"], dir => $clonePath,
die "error fetching latest change from git repo at `$uri':\n$res->{stderr}" if $res->{status}; timeout => $cfg->{timeout});
$res = run(cmd => ["git", "fetch", "-fu", "origin"], dir => $clonePath, timeout => $cfg->{timeout}) if $res->{status};
die "error fetching latest change from git repo at `$uri':\n$res->{stderr}" if $res->{status};
} else {
$res = run(cmd => ["git", "branch", "-f", "_hydra_tmp", "$branch"], dir => $clonePath, timeout => $cfg->{timeout});
}
# If deepClone is defined, then we look at the content of the repository # If deepClone is defined, then we look at the content of the repository
# to determine if this is a top-git branch. # to determine if this is a top-git branch.