Skip to content

[Fix] Configure bare linked worktrees#67

Merged
samzong merged 2 commits intomainfrom
fix/worktree-config-bare
Apr 27, 2026
Merged

[Fix] Configure bare linked worktrees#67
samzong merged 2 commits intomainfrom
fix/worktree-config-bare

Conversation

@samzong
Copy link
Copy Markdown
Owner

@samzong samzong commented Apr 27, 2026

What's changed?

  • Set core.bare=false in newly created linked worktrees when extensions.worktreeConfig is enabled.
  • Apply the same worktree-local config fix to wt add, wt dup, and PR worktree creation.
  • Add regression coverage for .bare + extensions.worktreeConfig and for bare layouts without worktree config.

Why

  • Fixes linked worktrees inheriting core.bare=true from .bare/config, which made normal Git commands fail with fatal: this operation must be run in a work tree.

Fixes #66

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces logic to ensure that new worktrees are correctly configured when extensions.worktreeConfig is enabled, specifically by setting core.bare to false in the worktree-specific configuration. These changes are integrated into the AddPR, Add, and Dup methods, and are supported by new test cases for bare repository layouts. Feedback was provided regarding the efficiency of the Dup method, where calling ensureAddedWorktreeConfig inside a loop results in redundant Git process executions; it is recommended to check the repository-level configuration once or cache the result.

Comment on lines +786 to +788
if err := c.ensureAddedWorktreeConfig(targetPath); err != nil {
return nil, err
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Calling ensureAddedWorktreeConfig inside the loop in Dup is inefficient because it spawns a redundant git config process for every worktree created to check the repository-level extensions.worktreeConfig setting. Since this setting is constant for the repository during the operation, consider checking it once before the loop and only calling the configuration command if necessary, or caching the result in the Client instance.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 96194aa831

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread internal/worktree/worktree.go Outdated
}

func (c *Client) ensureAddedWorktreeConfig(targetPath string) error {
if c.getGitOutput(c.repoDir, "config", "--bool", "extensions.worktreeConfig") != "true" {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Check worktreeConfig in local repo scope only

The guard reads extensions.worktreeConfig without a scope, so a global value (git config --global extensions.worktreeConfig true) is treated as if the repository enabled the extension; in that case ensureAddedWorktreeConfig runs git config --worktree ... and Git errors (--worktree cannot be used with multiple working trees unless ... enabled), causing wt add, wt dup, and PR worktree creation to fail in repos that do not have the extension set locally. The check should be restricted to repository/local config (or the common repo config file) before using --worktree.

Useful? React with 👍 / 👎.

@samzong samzong merged commit c03c9d4 into main Apr 27, 2026
1 check passed
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.

gmc wt add creates unusable worktrees when worktreeConfig inherits core.bare

1 participant