Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Untracked dirs on commit with pygit2

I'm working on a non-bare repository with pygit2

index = repo.index
index.read()

# write in test/test.txt

index.add('test/test.txt')
treeid = index.write_tree()

repo.create_commit(
    'HEAD',
    author, committer,
    'test commit',
    treeid,
    [repo.head.oid]
)

This is successful, but when I perform a git status, I got this :

# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#   deleted:    test/test.txt
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   test/

And after a git reset --hard, everything is fixed.

Is there a way to update correctly the index with pygit ?

like image 856
linkdd Avatar asked Apr 17 '13 09:04

linkdd


1 Answers

You're only writing out a tree from your in-memory index and leaving the on-disc index unmodified, so after the commit it is at the same state as it was before you did anything.

You need to write out the index (index.write()) if you want your changes to be stored on disc.

like image 145
Carlos Martín Nieto Avatar answered Sep 20 '22 19:09

Carlos Martín Nieto