-
-
Notifications
You must be signed in to change notification settings - Fork 979
Support relative worktree paths (git 2.48+ worktree.useRelativePaths) #2151
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
elovelan
wants to merge
2
commits into
gitpython-developers:main
Choose a base branch
from
elovelan:relative_worktree_support
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.
+22
−5
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,7 +41,7 @@ | |
| from git.repo.fun import touch | ||
| from git.util import bin_to_hex, cwd, cygpath, join_path_native, rmfile, rmtree | ||
|
|
||
| from test.lib import TestBase, fixture, with_rw_directory, with_rw_repo, PathLikeMock | ||
| from test.lib import TestBase, fixture, with_rw_directory, with_rw_repo, PathLikeMock, skipIf | ||
|
|
||
|
|
||
| def iter_flatten(lol): | ||
|
|
@@ -1094,7 +1094,7 @@ def test_is_valid_object(self): | |
| self.assertFalse(repo.is_valid_object(tag_sha, "commit")) | ||
|
|
||
| @with_rw_directory | ||
| def test_git_work_tree_dotgit(self, rw_dir): | ||
| def test_git_work_tree_dotgit(self, rw_dir, use_relative_paths=False): | ||
| """Check that we find .git as a worktree file and find the worktree | ||
| based on it.""" | ||
| git = Git(rw_dir) | ||
|
|
@@ -1106,7 +1106,11 @@ def test_git_work_tree_dotgit(self, rw_dir): | |
| worktree_path = join_path_native(rw_dir, "worktree_repo") | ||
| if Git.is_cygwin(): | ||
| worktree_path = cygpath(worktree_path) | ||
| rw_master.git.worktree("add", worktree_path, branch.name) | ||
| wt_add_kwargs = {"insert_kwargs_after": "add"} | ||
| # relative worktree paths introduced in git 2.48.0 | ||
| if use_relative_paths and git.version_info[:3] >= (2, 48, 0): | ||
| wt_add_kwargs["relative_paths"] = True | ||
| rw_master.git.worktree("add", worktree_path, branch.name, **wt_add_kwargs) | ||
|
|
||
| # This ensures that we can read the repo's gitdir correctly. | ||
| repo = Repo(worktree_path) | ||
|
|
@@ -1124,6 +1128,18 @@ def test_git_work_tree_dotgit(self, rw_dir): | |
|
|
||
| self.assertIsInstance(repo.heads["aaaaaaaa"], Head) | ||
|
|
||
| @skipIf( | ||
| Git().version_info[:3] < (2, 48, 0), | ||
| reason="relative worktree feature unsupported (needs git 2.48.0 or later)", | ||
| ) | ||
|
Comment on lines
+1131
to
+1134
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. this is a good suggestion. It's also done at |
||
| def test_git_work_tree_dotgit_relative(self): | ||
| """Check that we find .git as a worktree file containing a relative path | ||
| and find the worktree based on it.""" | ||
|
|
||
| # this class inherits from TestCase so we can't use pytest.mark.parametrize on | ||
| # test_git_work_tree_dotgit; delegate instead | ||
| self.test_git_work_tree_dotgit(use_relative_paths=True) | ||
|
|
||
| @with_rw_directory | ||
| def test_git_work_tree_env(self, rw_dir): | ||
| """Check that we yield to GIT_WORK_TREE.""" | ||
|
|
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fix won't work because it's doing the same thing as the original code (because
expand_pathcallsosp.abspath). To do this properly, I'd have to create a copy ofexpand_paththat doesn't callosp.abspath, or add a flag to the existing function.@Byron, I was double checking how Git handles this and it turns out it doesn't do
~and env var expansion, it only does the equivalent ofosp.normpathviastrbuf_realpath. I'm wondering if GitPython should match, which means my existing code will work by replacing the call toexpand_pathwithosp.normpath. Or should I do what I mentioned above and useexpand_path(without its call toosp.abspath) just in case Git decides to support expansions of thegitdirin the future?