Skip to content

worktrees() and stash misbehave on a linked worktree handle #14

Closed

Description

@dnnsjsk

Two problems when Pitmaster works from a linked worktree handle (Pitmaster::open('/path/to/linked-worktree')):

  1. Repository::worktrees() builds its WorktreeManager with the handle's own working directory (
    public function worktrees(): array
    {
    $manager = new \Pitmaster\Worktree\WorktreeManager($this->commonDir, $this->workDir);
    return $manager->list();
    }
    ), and the manager uses that as the main worktree path (
    return new Worktree(
    name: null,
    path: $this->workDir,
    gitDir: $this->gitDir,
    branch: $branch,
    head: $headId,
    isMain: true,
    isDetached: $isDetached,
    ). The entry marked isMain therefore reports the linked worktree's path, so the main checkout's location is wrong and the linked one appears twice.
  2. Stash reads the identity from <gitDir>/config (
    $config = GitConfig::fromFile($this->gitDir . '/config');
    ) and writes logs/refs/stash under <gitDir> (
    $reflog = Reflog::open($this->gitDir, 'refs/stash');
    $reflog->append(
    $oldStash ?? ObjectId::zero($this->hashAlgo()),
    $stashId,
    $identity,
    $stashMessage,
    );
    ). In a linked worktree gitDir is .git/worktrees/<name>, which has no config, so stash commits are authored as Pitmaster <[email protected]> and the stash reflog lands in the per-worktree directory while refs/stash is shared; git stash list shows nothing. The CLI passes $repo->gitDir() to Stash (

    pitmaster/bin/pitmaster

    Lines 758 to 763 in 5beb97d

    $stash = new \Pitmaster\Stash\Stash(
    $repo->objectDatabase(),
    $repo->refDatabase(),
    $repo->gitDir(),
    $repo->workDir(),
    );
    ).

Expected

worktrees() reports the main working tree path regardless of which handle calls it, and stash uses the common directory's config and reflog, as git does.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions