summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/git/diff.py1
-rw-r--r--lib/git/index.py20
-rw-r--r--test/git/test_index.py6
3 files changed, 25 insertions, 2 deletions
diff --git a/lib/git/diff.py b/lib/git/diff.py
index 3a94d0c2..dfeb7064 100644
--- a/lib/git/diff.py
+++ b/lib/git/diff.py
@@ -39,6 +39,7 @@ class Diffable(object):
``other``
Is the item to compare us with.
If None, we will be compared to the working tree.
+ If Treeish, it will be compared against the respective tree
If Index ( type ), it will be compared against the index.
It defaults to Index to assure the method will not by-default fail
on bare repositories.
diff --git a/lib/git/index.py b/lib/git/index.py
index 54bb0209..61307bb8 100644
--- a/lib/git/index.py
+++ b/lib/git/index.py
@@ -191,7 +191,7 @@ class IndexEntry(BaseIndexEntry):
Instance of type BaseIndexEntry
"""
time = struct.pack(">LL", 0, 0)
- return IndexEntry((base.mode, base.sha, base.stage, base.path, time, time, 1, 1, 1, 1, 0))
+ return IndexEntry((base.mode, base.sha, base.stage, base.path, time, time, 0, 0, 0, 0, 0))
@classmethod
def from_blob(cls, blob):
@@ -352,6 +352,10 @@ class IndexFile(LazyMixin, diff.Diffable):
# the footer contains extension data and a sha on the content so far
# Keep the extension footer,and verify we have a sha in the end
+ # Extension data format is:
+ # 4 bytes ID
+ # 4 bytes length of chunk
+ # repeated 0 - N times
self._extension_data = stream.read(~0)
assert len(self._extension_data) > 19, "Index Footer was not at least a sha on content as it was only %i bytes in size" % len(self._extension_data)
@@ -733,9 +737,23 @@ class IndexFile(LazyMixin, diff.Diffable):
index_path = self._index_path()
tmp_index_mover = _TemporaryFileSwap(index_path)
+ # IMPORTANT: If we have TREE extension data, it will actually
+ # ignore the index and write the stored tree instead. Hence we
+ # temporarily forget about it, and in fact I don't know what git
+ # uses it for
+ stored_ext_data = None
+ if self._extension_data and self._extension_data[:4] == 'TREE':
+ stored_ext_data = self._extension_data
+ self._extension_data = ''
+ # END extension data special handling
+
self.write(index_path)
tree_sha = self.repo.git.write_tree(missing_ok=missing_ok)
+ if stored_ext_data:
+ self._extension_data = stored_ext_data
+ # END reset stored exstension data
+
return Tree(self.repo, tree_sha, 0, '')
def _process_diff_args(self, args):
diff --git a/test/git/test_index.py b/test/git/test_index.py
index 0161e9ec..e6e23ba7 100644
--- a/test/git/test_index.py
+++ b/test/git/test_index.py
@@ -14,7 +14,6 @@ import glob
import shutil
from stat import *
-
class TestTree(TestBase):
def __init__(self, *args):
@@ -464,6 +463,7 @@ class TestTree(TestBase):
full_index_entry = IndexEntry.from_base(BaseIndexEntry((0120000, entries[0].sha, 0, entries[0].path)))
entry_key = index.get_entries_key(full_index_entry)
index.reset(new_commit)
+
assert entry_key not in index.entries
index.entries[entry_key] = full_index_entry
index.write()
@@ -471,6 +471,10 @@ class TestTree(TestBase):
new_entry = index.entries[entry_key]
assert S_ISLNK(new_entry.mode)
+ # a tree created from this should contain the symlink
+ tree = index.write_tree(True)
+ assert fake_symlink_relapath in tree
+
# checkout the fakelink, should be a link then
assert not S_ISLNK(os.stat(fake_symlink_path)[ST_MODE])
os.remove(fake_symlink_path)