2012-06-05 2 views
3

덜 리치와 git status을 어떻게 수행 할 수 있을지 궁금합니다. dulwich와 함께 프로그램 적으로`git status`

추가/변경/일부 파일의 이름을 변경하고 커밋을 준비 한 후,이 내가 일을 시도한 것입니다 :

나는이 시도

>>> list(changes) 
(('Makefile', None), (33188, None), ('9b20...', None)) 
(('test/README.txt', 'test/README.txt'), (33188, 33188), ('484b...', '4f89...')) 
((None, 'Makefile.mk'), (None, 33188), (None, '9b20...')) 
((None, 'TEST.txt'), (None, 33188), (None, '2a02...')) 
다음

from dulwich.repo import Repo 
from dulwich.index import changes_from_tree 
r = Repo('my-git-repo') 
index = r.open_index() 
changes = index.changes_from_tree(r.object_store, r['HEAD'].tree) 

출력

그러나이 출력을 처리하려면 추가 처리가 필요합니다.

  1. README.txt을 수정했습니다.
  2. Makefile에서 Makefile.mk으로 이름이 바뀌 었습니다.
  3. 나는 TEST.txt을 저장소에 추가했습니다.

dulwich.diff_tree의 기능은 트리 변경에 훨씬 멋진 인터페이스를 제공합니다 ... 실제로 커밋하기 전에는 가능하지 않습니까?

답변

2

dulwich.diff_tree.tree_changes을 사용하여 두 트리 간의 변경 사항을 감지 할 수 있어야합니다.

이 요구 사항 중 하나는 객체 저장소에 관련 트리 객체를 추가하는 것입니다. 여기에 dulwich.index.commit_index을 사용할 수 있습니다. 완성도를 들어

1

, 작업 예제 :() repo.head`이후 작동하지 나타나는

from dulwich.repo import Repo 
from dulwich.diff_tree import tree_changes 

repo = Repo("./") 

index = repo.open_index() 

try: 
    head_tree = repo.head().tree 
except KeyError: # in case of empty tree 
    head_tree = dulwich.objects.Tree() 

changes = list(tree_changes(repo, head_tree, index.commit(repo.object_store))) 


for change in changes: 
    print "%s: %s"%(change.type,change.new.path) 
+0

는'유형 인'str' 따라서 당신은 그것을'.tree'을 적용 할 수 없습니다 : ( – Mapio

+0

더 많은 api 변경이있는 것으로 보입니다. 'dulwich.porcelain.get_tree_changes (repo)'- "색인을 HEAD와 비교하여 트리에 추가/삭제/변경 사항을 반환하십시오."@Mapio – gameweld