LINUX.ORG.RU

что есть git index в pygit2?


0

0

Книга говорит

The Git index is used as a staging area between your working directory and your repository. You can use the index to build up a set of changes that you want to commit together. When you create a commit, what is committed is what is currently in the index, not what is in your working directory.

тоесть ниже у меня индекс пустой

vv@crusader ~/work/own/python/config_tool/my_confman/configs $ ls -l
total 8
-rw-r--r-- 1 vv vv 2 січ  1 13:58 1
-rw-r--r-- 1 vv vv 2 січ  1 13:58 2
vv@crusader ~/work/own/python/config_tool/my_confman/configs $ gt status
# On branch tee
nothing to commit (working directory clean)
vv@crusader ~/work/own/python/config_tool/my_confman/configs $

но следующий «скрипт»

..
    index = repository.index
    # lets check if index is empty
    #print dir(index)
    #pprint (vars(index))
    #print index[0]
    print len(index)
    print index['1']
    print index['2']
..

выдает немного не те результаты

vv@crusader ~/work/own/python/config_tool/my_confman/configs $ !p
python ../confman
2
<pygit2.IndexEntry object at 0xb746e0f0>
<pygit2.IndexEntry object at 0xb746e0f0>
vv@crusader ~/work/own/python/config_tool/my_confman/configs $

wtf?

★★★★★

Ответ на: комментарий от ZuBB

challenge accepted

from pygit2 import Repository
repo = Repository('.git')

git_status = repo.status()
for path, status in git_status.items():
    print path, status

вообще если тебе чтото не очевидно в работе библиотеки стоит начинать копать с тестов

zz ★★★★
()

Если git status выдет «nothing to commit», то это означает, что индекс совпадает с рабочей копией, а не то, что индекс пуст.

dmitry_vk ★★★
()

ок, всем спасибо. разобрался

ZuBB ★★★★★
() автор топика
Вы не можете добавлять комментарии в эту тему. Тема перемещена в архив.