Skip to content
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

Open
wants to merge 4 commits into
base: v2.x
Choose a base branch
from

Conversation

bart-jaskulski
Copy link
Contributor

@bart-jaskulski bart-jaskulski commented May 19, 2022

Q A
Branch master for features and deprecations
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Documented? no
Fixed tickets

@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:

git-worktree
 > hooks
 > worktrees
   > worktree-1
      > commondir
   > worktree-2
      > commondir
worktree-1
  > .git
worktree-2
  > .git

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.

@@ -36,7 +39,22 @@ public function locate(string $gitDir): string
$gitRepositoryDir = $matches[1];

if ($this->filesystem->isAbsolutePath($gitRepositoryDir)) {
Copy link
Contributor

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?

@veewee
Copy link
Contributor

veewee commented May 27, 2022

Thanks for reporting @bart-jaskulski.

Configured myself some worktrees locally to see what is going on exactly.
Looks like this implementation works. I did add some minor comments to make it less confusing for future reference.

@@ -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/';
Copy link
Contributor

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.');
Copy link
Contributor

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

@veewee
Copy link
Contributor

veewee commented Aug 26, 2022

@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 veewee changed the base branch from master to v2.x June 18, 2023 13:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants