From cfc70fe92d42a853d4171943bde90d86061e3f3a Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Fri, 26 Jun 2015 09:58:47 +0200 Subject: fix(index): handle adding symlinks to dirs When expanding directories, check if it is a symlink and don't expand them at all. Previously, we followed symlinks and expanded their contents, which could lead to weird index files. Fixes #302 --- git/test/test_index.py | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) (limited to 'git/test') diff --git a/git/test/test_index.py b/git/test/test_index.py index 63f99f10..8c3775d2 100644 --- a/git/test/test_index.py +++ b/git/test/test_index.py @@ -542,18 +542,22 @@ class TestIndex(TestBase): # add symlink if sys.platform != "win32": - basename = "my_real_symlink" - target = "/etc/that" - link_file = os.path.join(rw_repo.working_tree_dir, basename) - os.symlink(target, link_file) - entries = index.reset(new_commit).add([link_file], fprogress=self._fprogress_add) - self._assert_entries(entries) - self._assert_fprogress(entries) - assert len(entries) == 1 and S_ISLNK(entries[0].mode) - assert S_ISLNK(index.entries[index.entry_key("my_real_symlink", 0)].mode) - - # we expect only the target to be written - assert index.repo.odb.stream(entries[0].binsha).read().decode('ascii') == target + for target in ('/etc/nonexisting', '/etc/passwd', '/etc'): + basename = "my_real_symlink" + + link_file = os.path.join(rw_repo.working_tree_dir, basename) + os.symlink(target, link_file) + entries = index.reset(new_commit).add([link_file], fprogress=self._fprogress_add) + self._assert_entries(entries) + self._assert_fprogress(entries) + assert len(entries) == 1 and S_ISLNK(entries[0].mode) + assert S_ISLNK(index.entries[index.entry_key("my_real_symlink", 0)].mode) + + # we expect only the target to be written + assert index.repo.odb.stream(entries[0].binsha).read().decode('ascii') == target + + os.remove(link_file) + # end for each target # END real symlink test # add fake symlink and assure it checks-our as symlink -- cgit v1.2.1