commit 70d1ff3e7c1c5c69a1b4cdb61ee1b6b9e2a9bc4a Author: Nicolas Vigier boklm@torproject.org Date: Mon Mar 11 11:26:48 2019 +0100
Bug 29572: Update the test before running git checkout --detach
The reason we don't run |git checkout --detach| in all cases is that it fails when we cloned a repository without a master branch. To avoid running it in this case, we were checking if HEAD is pointing to a branch which has a corresponding file in the .git directory.
However it seems there are other cases where HEAD is pointing to a branch which does not have a corresponding file in the .git directory. Instead we now check that |git rev-parse --verify HEAD| does not return an error, in which case we assume that |git checkout --detach| will not produce an error too. --- lib/RBM.pm | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/lib/RBM.pm b/lib/RBM.pm index 3ef20ae..1400700 100644 --- a/lib/RBM.pm +++ b/lib/RBM.pm @@ -397,9 +397,8 @@ sub git_clone_fetch_chdir { if (git_need_fetch($project, $options)) { system('git', 'remote', 'set-url', 'origin', $git_url) == 0 || exit_error "Error setting git remote"; - my ($ref, undef, $success) = capture_exec('git', 'symbolic-ref', 'HEAD'); - chomp $ref; - if ($success && -e ".git/$ref") { + my (undef, undef, $success) = capture_exec('git', 'rev-parse', '--verify', 'HEAD'); + if ($success) { system('git', 'checkout', '-q', '--detach') == 0 || exit_error "Error running git checkout --detach"; }
tor-commits@lists.torproject.org