-
Notifications
You must be signed in to change notification settings - Fork 431
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
Fix retrieving git worktree path #1008
base: v2.x
Are you sure you want to change the base?
Conversation
@@ -36,7 +39,22 @@ public function locate(string $gitDir): string | |||
$gitRepositoryDir = $matches[1]; | |||
|
|||
if ($this->filesystem->isAbsolutePath($gitRepositoryDir)) { |
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.
I was a bit confused whilst trying to figure out how this works exactly. (took around 30 minutes to click)
Would you mind moving this logic into a private function and add documentation on how this logic works in that function's docblock?
Thanks for reporting @bart-jaskulski. Configured myself some worktrees locally to see what is going on exactly. |
@@ -69,7 +69,10 @@ public function it_can_passthrough_git_dir_path_if_file_is_not_parseable(): void | |||
*/ | |||
public function it_can_locate_git_dir_in_workspaces(): void | |||
{ | |||
$this->filesystem->dumpFile($this->gitDir, 'gitdir: /dev/null'); | |||
$this->assertEquals('/dev/null', $this->locator->locate($this->gitDir)); | |||
$worktreeRoot = $this->workspace.'/git_root/worktrees/git_worktree/'; |
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.
maybe better to name git_root
-> .git
and maybe git_worktree
to worktree1
or myworktree
(since I though this might have been a git folder)
@@ -36,7 +39,22 @@ public function locate(string $gitDir): string | |||
$gitRepositoryDir = $matches[1]; | |||
|
|||
if ($this->filesystem->isAbsolutePath($gitRepositoryDir)) { | |||
return $gitRepositoryDir; | |||
if (!$this->filesystem->isFile($gitRepositoryDir.DIRECTORY_SEPARATOR.'commondir')) { | |||
throw new RuntimeException('The git directory for worktree could not be found.'); |
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.
Is this expected behaviour? Or should we just link to the absolute dir instead?
Either way : we'll need a test for this
@bart-jaskulski Got any time to look at the comments I added above? Is there anything else I can do to get this merged? |
@veewee Actually, I've made a bad assumption previously submitting PR (#1003) for git worktree path - git does store absolute path in
.git
file, but that's absolute path to the current worktree, while hooks are fired from common worktree root directory.The hierarchy looks something like:
With current patch, we are actually getting absolute path to worktree and reading the path from
commondir
file, which usually points up in hierarchy, to the root of git directory.