Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf2254af

Browse files
committed
_to_relative_path to support mixing slashes and backslashes
Working on Windows you sometime end up having some paths with backslashes (windows native) and some with slashes - this PR will resolve the issue using gitpython for those kind of cases (see example below). It will also fix the issues if paths contain redundant separators or "..".```import gitrepo = git.Repo(r"C:\gittest")repo.index.add(r"C:\gittest\1.txt")# Traceback (most recent call last):# File "c:\second_test.py", line 5, in <module># repo.index.add(r"C:/gittest/2.txt")# File "Python311\Lib\site-packages\git\index\base.py", line 879, in add# paths, entries = self._preprocess_add_items(items)# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^# File "Python311\Lib\site-packages\git\index\base.py", line 672, in _preprocess_add_items# paths.append(self._to_relative_path(item))# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^# File "Python311\Lib\site-packages\git\index\base.py", line 657, in _to_relative_path# raise ValueError("Absolute path %r is not in git repository at %r" % (path, self.repo.working_tree_dir))# ValueError: Absolute path 'C:/gittest/2.txt' is not in git repository at 'C:\\gittest'repo.index.add(r"C:/gittest/2.txt")repo.index.commit("test")```
1 parentcfadd9e commitf2254af

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

‎git/index/base.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,7 @@ def _to_relative_path(self, path: PathLike) -> PathLike:
653653
returnpath
654654
ifself.repo.bare:
655655
raiseInvalidGitRepositoryError("require non-bare repository")
656-
ifnotstr(path).startswith(str(self.repo.working_tree_dir)):
656+
ifnotosp.normpath(str(path)).startswith(osp.normpath(str(self.repo.working_tree_dir))):
657657
raiseValueError("Absolute path %r is not in git repository at %r"% (path,self.repo.working_tree_dir))
658658
returnos.path.relpath(path,self.repo.working_tree_dir)
659659

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp