Programmatically `git checkout .` with dulwich

前端 未结 3 1153
[愿得一人]
[愿得一人] 2020-12-30 15:50

Having this code

from dulwich.objects import Blob, Tree, Commit, parse_timezone
from dulwich.repo import Repo
from time import time

repo = Repo.init(\"myrep         


        
3条回答
  •  死守一世寂寞
    2020-12-30 16:08

    It is now possible since release 0.8.4, with the method dulwich.index.build_index_from_tree().

    It writes a tree to both the index file and the filesystem (working copy), which is a very basic form of checkout.

    See the note

    existing index is wiped and contents are not merged in a working dir. Suiteable only for fresh clones

    I could get it work with the following code

    from dulwich import index, repo
    #get repository object of current directory
    repo = repo.Repo('.')
    indexfile = repo.index_path()
    #we want to checkout HEAD
    tree = repo["HEAD"].tree
    
    index.build_index_from_tree(repo.path, indexfile, repo.object_store, tree)
    

提交回复
热议问题