From d82a6c5ed9108be5802a03c38f728a07da57438e Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Sun, 13 Dec 2015 13:10:33 +0100 Subject: 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 --- git/test/test_tree.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'git/test') 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) -- cgit v1.2.1