Browse Source

Do not crash when cloning HEAD-less repo

For a git repository HEAD reference is optional.
.clone() would crash at the attempt to update
target repo 'HEAD' reference if source repo is HEAD-less.
D-Key 12 years ago
parent
commit
b53142a4e6
1 changed files with 3 additions and 2 deletions
  1. 3 2
      dulwich/repo.py

+ 3 - 2
dulwich/repo.py

@@ -1383,8 +1383,9 @@ class Repo(BaseRepo):
 
         # Update target head
         head, head_sha = self.refs._follow('HEAD')
-        target.refs.set_symbolic_ref('HEAD', head)
-        target['HEAD'] = head_sha
+        if head is not None and head_sha is not None:
+            target.refs.set_symbolic_ref('HEAD', head)
+            target['HEAD'] = head_sha
 
         if not bare:
             # Checkout HEAD to target dir