It seems that if index.add() is called with path_rewriter, it would cancel out the logic for automatic directory paths expansion and traversal. My use case is to call add with a directory and replace (truncate the dir prefix) the paths of the upcoming commit.
/repo/a/b/c/<files and dirs> <-- I want these files in a commit with a/b/c/ removed
Current behaviour:
Paths replaced first and then directories are not expanded.
Current workaround:
Expand directory paths manually with os.walk, glob etc.
Expected behavior:
repo.index.add('a/b/c/', path_rewriter=lambdap: osp.relpath(p, 'a/b/c/'))
# index includes <files> with a/b/c/ prefix removed in paths
The text was updated successfully, but these errors were encountered:
zhiltsov-max
changed the title
index.add with path_rewriter conflicts with directory paths expansion and traversal
index.add with path_rewriter conflicts with directory paths expansion
May 14, 2021
Thanks for posting. When taking a glance at the code it wasn't immediately obvious how the automatic expansion is cancelled, but maybe it has something to do with this line:
Hi, thanks for the response. Yes, I'm also thinking about this del call. The example:
mkdir -p test_git
cd test_git
mkdir -p a
touch a/f.txt
python
import git
rewriter = lambda e: 'rewritten'
r = git.Repo.init()
r.index.add('a', path_rewriter=rewriter)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/venv/lib/python3.6/site-packages/git/index/base.py", line 766, in add
handle_null_entries(self)
File "/venv/lib/python3.6/site-packages/git/index/util.py", line 91, in set_git_working_dir
return func(self, *args, **kwargs)
File "/venv/lib/python3.6/site-packages/git/index/base.py", line 759, in handle_null_entries
new_entry = self._store_path(null_entry.path, fprogress)
File "/venv/lib/python3.6/site-packages/git/index/base.py", line 594, in _store_path
with open_stream() as stream:
File "/venv/lib/python3.6/site-packages/git/index/base.py", line 593, in <lambda>
open_stream = lambda: open(filepath, 'rb')
IsADirectoryError: [Errno 21] Is a directory: 'a'
r.index.add('a/f.txt', path_rewriter=rewriter)
[(100644, e69de29bb2d1d6434b8b29ae775ad8c2e48c5391, 0, rewritten)]
It seems that if
index.add()
is called withpath_rewriter
, it would cancel out the logic for automatic directory paths expansion and traversal. My use case is to calladd
with a directory and replace (truncate the dir prefix) the paths of the upcoming commit.Current behaviour:
Paths replaced first and then directories are not expanded.
Current workaround:
Expand directory paths manually with
os.walk
,glob
etc.Expected behavior:
The text was updated successfully, but these errors were encountered: