diff --git a/src/lib/Hydra/Plugin/GitInput.pm b/src/lib/Hydra/Plugin/GitInput.pm index 0de02128..e927b533 100644 --- a/src/lib/Hydra/Plugin/GitInput.pm +++ b/src/lib/Hydra/Plugin/GitInput.pm @@ -142,14 +142,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.