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/index | |
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/index')
-rw-r--r-- | git/index/base.py | 11 |
1 files changed, 11 insertions, 0 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)): |