diff options
author | Sebastian Thiel <byronimo@gmail.com> | 2015-06-26 09:58:47 +0200 |
---|---|---|
committer | Sebastian Thiel <byronimo@gmail.com> | 2015-06-26 09:58:47 +0200 |
commit | cfc70fe92d42a853d4171943bde90d86061e3f3a (patch) | |
tree | d7540e9eb18588f834e91599c274e31bf38167bd /git/test/test_index.py | |
parent | 8724dfa6bf8f6de9c36d10b9b52ab8a1ea30c3b2 (diff) | |
download | gitpython-cfc70fe92d42a853d4171943bde90d86061e3f3a.tar.gz |
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
Diffstat (limited to 'git/test/test_index.py')
-rw-r--r-- | git/test/test_index.py | 28 |
1 files changed, 16 insertions, 12 deletions
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 |