| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent ab7c322 commit 8f043d8
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,6 +2,12 @@ | |||
| 2 | 2 | Changelog | |
| 3 | 3 | ========= | |
| 4 | 4 | ||
| 5 | + 0.3.7 - Fixes | ||
| 6 | + ============= | ||
| 7 | + * `IndexFile.add()` will now write the index without any extension data by default. However, you may override this behaviour with the new `write_extension_data` keyword argument. | ||
| 8 | + | ||
| 9 | + - Renamed `ignore_tree_extension_data` keyword argument in `IndexFile.write(...)` to `ignore_extension_data` | ||
| 10 | + | ||
| 5 | 11 | 0.3.6 - Features | |
| 6 | 12 | ================ | |
| 7 | 13 | * **DOCS** | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -172,16 +172,17 @@ def _entries_sorted(self): | |||
| 172 | 172 | """:return: list of entries, in a sorted fashion, first by path, then by stage""" | |
| 173 | 173 | return sorted(self.entries.values(), key=lambda e: (e.path, e.stage)) | |
| 174 | 174 | ||
| 175 | - def _serialize(self, stream, ignore_tree_extension_data=False): | ||
| 175 | + def _serialize(self, stream, ignore_extension_data=False): | ||
| 176 | 176 | entries = self._entries_sorted() | |
| 177 | - write_cache(entries, | ||
| 178 | - stream, | ||
| 179 | - (ignore_tree_extension_data and None) or self._extension_data) | ||
| 177 | + extension_data = self._extension_data | ||
| 178 | + if ignore_extension_data: | ||
| 179 | + extension_data = None | ||
| 180 | + write_cache(entries, stream, extension_data) | ||
| 180 | 181 | return self | |
| 181 | 182 | ||
| 182 | 183 | #} END serializable interface | |
| 183 | 184 | ||
| 184 | - def write(self, file_path=None, ignore_tree_extension_data=False): | ||
| 185 | + def write(self, file_path=None, ignore_extension_data=False): | ||
| 185 | 186 | """Write the current state to our file path or to the given one | |
| 186 | 187 | ||
| 187 | 188 | :param file_path: | |
@@ -190,9 +191,10 @@ def write(self, file_path=None, ignore_tree_extension_data=False): | |||
| 190 | 191 | Please note that this will change the file_path of this index to | |
| 191 | 192 | the one you gave. | |
| 192 | 193 | ||
| 193 | - :param ignore_tree_extension_data: | ||
| 194 | + :param ignore_extension_data: | ||
| 194 | 195 | If True, the TREE type extension data read in the index will not | |
| 195 | - be written to disk. Use this if you have altered the index and | ||
| 196 | + be written to disk. NOTE that no extension data is actually written. | ||
| 197 | + Use this if you have altered the index and | ||
| 196 | 198 | would like to use git-write-tree afterwards to create a tree | |
| 197 | 199 | representing your written changes. | |
| 198 | 200 | If this data is present in the written index, git-write-tree | |
@@ -208,7 +210,7 @@ def write(self, file_path=None, ignore_tree_extension_data=False): | |||
| 208 | 210 | lfd = LockedFD(file_path or self._file_path) | |
| 209 | 211 | stream = lfd.open(write=True, stream=True) | |
| 210 | 212 | ||
| 211 | - self._serialize(stream, ignore_tree_extension_data) | ||
| 213 | + self._serialize(stream, ignore_extension_data) | ||
| 212 | 214 | ||
| 213 | 215 | lfd.commit() | |
| 214 | 216 | ||
@@ -612,7 +614,7 @@ def _entries_for_paths(self, paths, path_rewriter, fprogress, entries): | |||
| 612 | 614 | return entries_added | |
| 613 | 615 | ||
| 614 | 616 | def add(self, items, force=True, fprogress=lambda *args: None, path_rewriter=None, | |
| 615 | - write=True): | ||
| 617 | + write=True, write_extension_data=False): | ||
| 616 | 618 | """Add files from the working tree, specific blobs or BaseIndexEntries | |
| 617 | 619 | to the index. | |
| 618 | 620 | ||
@@ -689,8 +691,19 @@ def add(self, items, force=True, fprogress=lambda *args: None, path_rewriter=Non | |||
| 689 | 691 | Please note that entry.path is relative to the git repository. | |
| 690 | 692 | ||
| 691 | 693 | :param write: | |
| 692 | - If True, the index will be written once it was altered. Otherwise | ||
| 693 | - the changes only exist in memory and are not available to git commands. | ||
| 694 | + If True, the index will be written once it was altered. Otherwise | ||
| 695 | + the changes only exist in memory and are not available to git commands. | ||
| 696 | + | ||
| 697 | + :param write_extension_data: | ||
| 698 | + If True, extension data will be written back to the index. This can lead to issues in case | ||
| 699 | + it is containing the 'TREE' extension, which will cause the `git commit` command to write an | ||
| 700 | + old tree, instead of a new one representing the now changed index. | ||
| 701 | + This doesn't matter if you use `IndexFile.commit()`, which ignores the `TREE` extension altogether. | ||
| 702 | + You should set it to True if you intend to use `IndexFile.commit()` exclusively while maintaining | ||
| 703 | + support for third-party extensions. Besides that, you can usually safely ignore the built-in | ||
| 704 | + extensions when using GitPython on repositories that are not handled manually at all. | ||
| 705 | + All current built-in extensions are listed here: | ||
| 706 | + http://opensource.apple.com/source/Git/Git-26/src/git-htmldocs/technical/index-format.txt | ||
| 694 | 707 | ||
| 695 | 708 | :return: | |
| 696 | 709 | List(BaseIndexEntries) representing the entries just actually added. | |
@@ -763,7 +776,7 @@ def handle_null_entries(self): | |||
| 763 | 776 | self.entries[(entry.path, 0)] = IndexEntry.from_base(entry) | |
| 764 | 777 | ||
| 765 | 778 | if write: | |
| 766 | - self.write() | ||
| 779 | + self.write(ignore_extension_data=not write_extension_data) | ||
| 767 | 780 | # END handle write | |
| 768 | 781 | ||
| 769 | 782 | return entries_added | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -44,11 +44,8 @@ | |||
| 44 | 44 | BaseIndexEntry, | |
| 45 | 45 | IndexEntry | |
| 46 | 46 | ) | |
| 47 | - from gitdb.test.lib import with_rw_directory | ||
| 48 | 47 | from git.index.fun import hook_path | |
| 49 | 48 | ||
| 50 | - import git | ||
| 51 | - | ||
| 52 | 49 | ||
| 53 | 50 | class TestIndex(TestBase): | |
| 54 | 51 | ||
@@ -768,15 +765,3 @@ def test_index_bare_add(self, rw_bare_repo): | |||
| 768 | 765 | except InvalidGitRepositoryError: | |
| 769 | 766 | asserted = True | |
| 770 | 767 | assert asserted, "Adding using a filename is not correctly asserted." | |
| 771 | - | ||
| 772 | - @with_rw_directory | ||
| 773 | - def test_index_add_corruption(self, rw_dir): | ||
| 774 | - # Test for https://github.com/gitpython-developers/GitPython/issues/265 | ||
| 775 | - repo = git.Repo.clone_from("git://pkgs.fedoraproject.org/GitPython", rw_dir) | ||
| 776 | - assert not repo.is_dirty() | ||
| 777 | - file_path = os.path.join(rw_dir, "GitPython.spec") | ||
| 778 | - open(file_path, 'wb').close() | ||
| 779 | - assert repo.is_dirty() | ||
| 780 | - repo.index.add(['0001-GPG-signature-support-on-commit-object.patch', 'GitPython.spec', '.gitignore', 'sources']) | ||
| 781 | - repo.git.commit(m="committing file") | ||
| 782 | - assert not repo.is_dirty() | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments