-
Notifications
You must be signed in to change notification settings - Fork 428
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?
Changes from 3 commits
638dac8
f4ca1c6
b65f4a2
d83c48b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,10 @@ | |
|
||
namespace GrumPHP\Locator; | ||
|
||
use GrumPHP\Exception\RuntimeException; | ||
use GrumPHP\Util\Filesystem; | ||
use Symfony\Component\Finder\Finder; | ||
use Symfony\Component\Finder\SplFileInfo; | ||
|
||
class GitRepositoryDirLocator | ||
{ | ||
|
@@ -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 commentThe 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? |
||
} | ||
|
||
$worktreeRelativeRoot = trim( | ||
$this->filesystem->readPath( | ||
$gitRepositoryDir.DIRECTORY_SEPARATOR.'commondir' | ||
) | ||
); | ||
|
||
return $this->filesystem->realpath( | ||
$this->filesystem->makePathAbsolute( | ||
$worktreeRelativeRoot, | ||
$gitRepositoryDir | ||
) | ||
); | ||
} | ||
|
||
return $this->filesystem->buildPath( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,7 +31,7 @@ protected function setUp(): void | |
|
||
$this->filesystem = new Filesystem(); | ||
$this->locator = new GitRepositoryDirLocator($this->filesystem); | ||
$this->gitDir = $this->workspace . DIRECTORY_SEPARATOR . '.git'; | ||
$this->gitDir = $this->workspace . DIRECTORY_SEPARATOR . '.git'; | ||
} | ||
|
||
/** | ||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. maybe better to name |
||
mkdir($worktreeRoot, 0777, true); | ||
$this->filesystem->dumpFile($worktreeRoot.'/commondir', '../..'); | ||
$this->filesystem->dumpFile($this->gitDir, 'gitdir: '.$this->workspace.'/git_root/worktrees/git_worktree'); | ||
$this->assertEquals($this->workspace.DIRECTORY_SEPARATOR.'git_root', $this->locator->locate($this->gitDir)); | ||
} | ||
} |
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?