diff options
author | Sebastian Thiel <byronimo@gmail.com> | 2015-12-13 13:10:33 +0100 |
---|---|---|
committer | Sebastian Thiel <byronimo@gmail.com> | 2015-12-13 13:10:33 +0100 |
commit | d82a6c5ed9108be5802a03c38f728a07da57438e (patch) | |
tree | 22476136137e46bb0a08fea8cabcaa805f7c024b /git/test/test_tree.py | |
parent | a1a59764096cef4048507cb50f0303f48b87a242 (diff) | |
download | gitpython-d82a6c5ed9108be5802a03c38f728a07da57438e.tar.gz |
fix(tree): tree item sort now uses git-style
Previously it was possible to generate trees which didn't
appear legit to git as gitpython's sorting was a simple alpha-numeric
sort. Git uses one that minimizes literal string comparisons though,
and thus behaves slightly differently sometimes.
Fixes #369
Diffstat (limited to 'git/test/test_tree.py')
-rw-r--r-- | git/test/test_tree.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/git/test/test_tree.py b/git/test/test_tree.py index 7a16b777..5e94e70b 100644 --- a/git/test/test_tree.py +++ b/git/test/test_tree.py @@ -77,10 +77,30 @@ class TestTree(TestBase): # del again, its fine del(mod[invalid_name]) + # SPECIAL ORDERING ! + # Add items which should sort differently from standard alum sort order + mod.add(hexsha, Tree.blob_id << 12, 'fild') + mod.add(hexsha, Tree.blob_id << 12, 'file') + mod.add(hexsha, Tree.blob_id << 12, 'file.second') + mod.add(hexsha, Tree.blob_id << 12, 'filf') + + def names_in_mod_cache(): + return [t[2] for t in mod._cache] + + def chunk_from(a, name, size): + index = a.index(name) + return a[index:index + size] + + assert chunk_from(names_in_mod_cache(), 'fild', 4) == ['fild', 'file', 'file.second', + 'filf'] + # have added one item, we are done mod.set_done() mod.set_done() # multiple times are okay + assert chunk_from(names_in_mod_cache(), 'fild', 4) == ['fild', 'file.second', 'file', + 'filf'] + # serialize, its different now stream = BytesIO() testtree._serialize(stream) |