[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [rbm/master] Only run 'git checkout --detach' when necessary



commit ff4299fcf372aef5d28fe7024a60d81d413fcd6f
Author: Nicolas Vigier <boklm@xxxxxxxxxxxxxx>
Date:   Tue Aug 1 22:40:16 2017 +0200

    Only run 'git checkout --detach' when necessary
    
    Before updating local branches, we need to detach HEAD to be able to
    update the current branch. However, we only need to do that if we are
    on a branch, and when this branch exists.
    
    This avoids an error when the repository we have cloned does not have a
    master branch: in that case we are in a branch that does not exist,
    which cause an error when running 'git checkout --detach'.
---
 lib/RBM.pm | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/lib/RBM.pm b/lib/RBM.pm
index 6825050..888c3e1 100644
--- a/lib/RBM.pm
+++ b/lib/RBM.pm
@@ -390,8 +390,12 @@ 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";
-        system('git', 'checkout', '-q', '--detach') == 0
+        my ($ref, undef, $success) = capture_exec('git', 'symbolic-ref', 'HEAD');
+        chomp $ref;
+        if ($success && -e ".git/$ref") {
+            system('git', 'checkout', '-q', '--detach') == 0
                 || exit_error "Error running git checkout --detach";
+        }
         system('git', 'fetch', @fetch_submod, 'origin',
                                 '+refs/heads/*:refs/heads/*') == 0
                 || exit_error "Error fetching git repository";

_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits