diff options
-rw-r--r-- | git/index/base.py | 11 | ||||
-rw-r--r-- | git/test/test_index.py | 28 |
2 files changed, 27 insertions, 12 deletions
diff --git a/git/index/base.py b/git/index/base.py index 10de3358..f8696800 100644 --- a/git/index/base.py +++ b/git/index/base.py @@ -367,6 +367,17 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable): abs_path = os.path.join(r, path) # END make absolute path + try: + st = os.lstat(abs_path) # handles non-symlinks as well + except OSError: + # the lstat call may fail as the path may contain globs as well + pass + else: + if S_ISLNK(st.st_mode): + yield abs_path.replace(rs, '') + continue + # end check symlink + # resolve globs if possible if '?' in path or '*' in path or '[' in path: for f in self._iter_expand_paths(glob.glob(abs_path)): 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 |