1
0
Fork 0
mirror of https://github.com/NixOS/hydra.git synced 2024-10-17 16:37:26 -04:00

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};
}
# This command forces the update of the local branch to be in the same as
# the remote branch for whatever the repository state is. This command mirrors
# only one branch of the remote repository.
my $localBranch = _isHash($branch) ? "_hydra_tmp" : $branch;
$res = run(cmd => ["git", "fetch", "-fu", "origin", "+$branch:$localBranch"], dir => $clonePath,
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};
$res = run(cmd => ["git", "cat-file", "-t", $branch], dir => $clonePath);
if (! _isHash($branch) || $res->{status}) {
# This command forces the update of the local branch to be in the same as
# the remote branch for whatever the repository state is. This command mirrors
# only one branch of the remote repository.
my $localBranch = _isHash($branch) ? "_hydra_tmp" : $branch;
$res = run(cmd => ["git", "fetch", "-fu", "origin", "+$branch:$localBranch"], dir => $clonePath,
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
# to determine if this is a top-git branch.