-
-
Notifications
You must be signed in to change notification settings - Fork 965
Respect os.Pathlike
#2086
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
George-Ogden
wants to merge
19
commits into
gitpython-developers:main
Choose a base branch
from
George-Ogden:true-pathlike
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+433
−344
Draft
Respect os.Pathlike
#2086
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
e3f38ff
Move clone tests into dedicated file
George-Ogden 24abf10
Allow Pathlike urls and destinations when cloning
George-Ogden ad1ae5f
Simplify logic with direct path conversion
George-Ogden 5d26325
Allow Pathlike paths when creating a git repo
George-Ogden 59c3c80
Fix missing path conversion
George-Ogden 91d4cc5
Use os.fspath instead of __fspath__ for reading paths
George-Ogden 0414bf7
Replace extra occurrences of str with fspath
George-Ogden 3801505
Convert paths in constructors and large function calls
George-Ogden 086e832
Fix union type conversion to path
George-Ogden b3908ed
Use converted file path
George-Ogden 50aea99
Remove redundant `fspath`
George-Ogden 57a3af1
Remove redundant `fspath`
George-Ogden df8087a
Remove a large number of redundant fspaths
George-Ogden 1722561
Remove redundant str call
George-Ogden 921ca8a
Limit mypy version due to Cygwin errors
George-Ogden b5abe0f
Merge branch 'main' into true-pathlike
George-Ogden 12e15ba
Validate every fspath with tests
George-Ogden 8434967
Fix type hints
George-Ogden 1710626
Add tests with non-ascii characters
George-Ogden File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -126,6 +126,7 @@ class Repo: | |
| working_dir: PathLike | ||
| """The working directory of the git command.""" | ||
|
|
||
| # stored as string for easier processing, but annotated as path for clearer intention | ||
| _working_tree_dir: Optional[PathLike] = None | ||
|
|
||
| git_dir: PathLike | ||
|
|
@@ -215,15 +216,13 @@ def __init__( | |
| epath = path or os.getenv("GIT_DIR") | ||
| if not epath: | ||
| epath = os.getcwd() | ||
| epath = os.fspath(epath) | ||
| if Git.is_cygwin(): | ||
| # Given how the tests are written, this seems more likely to catch Cygwin | ||
| # git used from Windows than Windows git used from Cygwin. Therefore | ||
| # changing to Cygwin-style paths is the relevant operation. | ||
| epath = cygpath(str(epath)) | ||
| epath = cygpath(epath) | ||
|
|
||
| epath = epath or path or os.getcwd() | ||
| if not isinstance(epath, str): | ||
| epath = str(epath) | ||
| if expand_vars and re.search(self.re_envvars, epath): | ||
| warnings.warn( | ||
| "The use of environment variables in paths is deprecated" | ||
|
|
@@ -957,7 +956,7 @@ def is_dirty( | |
| if not submodules: | ||
| default_args.append("--ignore-submodules") | ||
| if path: | ||
| default_args.extend(["--", str(path)]) | ||
| default_args.extend(["--", os.fspath(path)]) | ||
| if index: | ||
| # diff index against HEAD. | ||
| if osp.isfile(self.index.path) and len(self.git.diff("--cached", *default_args)): | ||
|
|
@@ -1357,9 +1356,9 @@ def _clone( | |
| ) -> "Repo": | ||
| odbt = kwargs.pop("odbt", odb_default_type) | ||
|
|
||
| # When pathlib.Path or other class-based path is passed | ||
| if not isinstance(path, str): | ||
| path = str(path) | ||
| # url may be a path and this has no effect if it is a string | ||
| url = os.fspath(url) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. URL is not a path though.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here, |
||
| path = os.fspath(path) | ||
|
|
||
| ## A bug win cygwin's Git, when `--bare` or `--separate-git-dir` | ||
| # it prepends the cwd or(?) the `url` into the `path, so:: | ||
|
|
@@ -1376,7 +1375,7 @@ def _clone( | |
| multi = shlex.split(" ".join(multi_options)) | ||
|
|
||
| if not allow_unsafe_protocols: | ||
| Git.check_unsafe_protocols(str(url)) | ||
| Git.check_unsafe_protocols(url) | ||
| if not allow_unsafe_options: | ||
| Git.check_unsafe_options(options=list(kwargs.keys()), unsafe_options=cls.unsafe_git_clone_options) | ||
| if not allow_unsafe_options and multi_options: | ||
|
|
@@ -1385,7 +1384,7 @@ def _clone( | |
| proc = git.clone( | ||
| multi, | ||
| "--", | ||
| Git.polish_url(str(url)), | ||
| Git.polish_url(url), | ||
| clone_path, | ||
| with_extended_output=True, | ||
| as_process=True, | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.