From 8f043d8a1d7f4076350ff0c778bfa60f7aa2f7aa Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Wed, 8 Apr 2015 09:50:26 +0200 Subject: fix(index): don't write extension data by default It turned out that the index is not actually corrupted, which is good news. What happens is that `git` writes `TREE` extension data into the index, which causes it to write out the given tree *as is* next time a `git commit` is executed. When using `git add`, this extension data is maintained automatically. However, GitPython doesn't do that ... . Usually this is no problem at all, as you are supposed to use `IndexFile.commit(...)` along with `IndexFile.add(...)`. Thanks to a shortcoming in the GitPython API, the index was automatically written out whenever files have been added, without providing control over whether or not *extension data* will be written along with it. My fix consists of an additional flag in `IndexFile.add(...)`, which causes extension data not to be written by default, so commits can be safely done via `git commit` or `IndexFile.commit(...)`. However, this might introduce new subtle bugs in case someone is relying on extension data to be written. As this can be controlled through the said flag though, a fix is easily done in that case. Fixes #265 --- git/test/test_index.py | 15 --------------- 1 file changed, 15 deletions(-) (limited to 'git/test/test_index.py') diff --git a/git/test/test_index.py b/git/test/test_index.py index 8124ec16..63f99f10 100644 --- a/git/test/test_index.py +++ b/git/test/test_index.py @@ -44,11 +44,8 @@ from git.index.typ import ( BaseIndexEntry, IndexEntry ) -from gitdb.test.lib import with_rw_directory from git.index.fun import hook_path -import git - class TestIndex(TestBase): @@ -768,15 +765,3 @@ class TestIndex(TestBase): except InvalidGitRepositoryError: asserted = True assert asserted, "Adding using a filename is not correctly asserted." - - @with_rw_directory - def test_index_add_corruption(self, rw_dir): - # Test for https://github.com/gitpython-developers/GitPython/issues/265 - repo = git.Repo.clone_from("git://pkgs.fedoraproject.org/GitPython", rw_dir) - assert not repo.is_dirty() - file_path = os.path.join(rw_dir, "GitPython.spec") - open(file_path, 'wb').close() - assert repo.is_dirty() - repo.index.add(['0001-GPG-signature-support-on-commit-object.patch', 'GitPython.spec', '.gitignore', 'sources']) - repo.git.commit(m="committing file") - assert not repo.is_dirty() -- cgit v1.2.1