Преглед на файлове

set detached HEAD properly

Peter Rowlands преди 4 години
родител
ревизия
f4dddb4c34
променени са 2 файла, в които са добавени 13 реда и са изтрити 6 реда
  1. 6 1
      dulwich/porcelain.py
  2. 7 5
      dulwich/repo.py

+ 6 - 1
dulwich/porcelain.py

@@ -458,7 +458,12 @@ def clone(
         )
         for key, target_ref in fetch_result.symrefs.items():
             target_repo.refs.set_symbolic_ref(key, target_ref)
-        return fetch_result.symrefs.get(b"HEAD", None)
+        head_ref = fetch_result.symrefs.get(b"HEAD", None)
+        try:
+            head_sha = target_repo[fetch_result.refs[b"HEAD"]].id
+        except KeyError:
+            head_sha = None
+        return head_ref, head_sha
 
     try:
         return Repo.do_clone(

+ 7 - 5
dulwich/repo.py

@@ -1402,8 +1402,9 @@ class Repo(BaseRepo):
             except KeyError:
                 pass
 
-            head_chain, _sha = self.refs.follow(b"HEAD")
-            return head_chain[-1] if head_chain else None
+            head_chain, sha = self.refs.follow(b"HEAD")
+            head_chain = head_chain[-1] if head_chain else None
+            return head_chain, sha
 
         encoded_path = self.path
         if not isinstance(encoded_path, bytes):
@@ -1466,7 +1467,9 @@ class Repo(BaseRepo):
             target_config.write_to_path()
 
             ref_message = b"clone: from " + source_path
-            origin_head = clone_refs(target, ref_message)
+            origin_head, origin_sha = clone_refs(target, ref_message)
+            if origin_sha:
+                target.refs[b"HEAD"] = origin_sha
 
             # set refs/remotes/origin/HEAD
             if origin_head and origin_head.startswith(LOCAL_BRANCH_PREFIX):
@@ -1487,7 +1490,7 @@ class Repo(BaseRepo):
 
             if checkout and head is not None:
                 if errstream:
-                    errstream.write(b"Checking out " + head.id + b"\n")
+                    errstream.write(b"Checking out " + head + b"\n")
                 target.reset_index()
         except BaseException:
             target.close()
@@ -1513,7 +1516,6 @@ class Repo(BaseRepo):
     @staticmethod
     def _clone_set_head(r, head_ref, ref_message):
         if head_ref.startswith(LOCAL_TAG_PREFIX):
-            print(r.refs)
             # detach HEAD at specified tag
             _cls, head_sha = r.refs[head_ref].object
             head = r[head_sha]