Skip to content

Feature request: Support a {repo} placeholder in gtr.worktrees.dir #205

Open

Description

@arwtyxouymz

Use case

I'd like to use a single global configuration to customize worktree base directories while keeping the repository name in each path.
For example, I'd like each repository's worktrees to live in a sibling directory named <repo>-workspace:

/repo/
├── foo/
├── foo-workspace/
│   └── feature-login/
├── bar/
└── bar-workspace/
    └── fix-bug/

Current behavior

In gtr v2.11.1, the default base directory is generated from the main repository's directory name as <repo>-worktrees.
An explicit gtr.worktrees.dir supports absolute paths, paths relative to the main repository root, and tilde expansion, but it does not support a placeholder for the repository name.

As a result, the layout above requires a separate configuration for each repository.
It would be useful to express this naming convention once in the global configuration.

Proposed behavior

Support a {repo} placeholder in gtr.worktrees.dir that expands to the main repository's directory name.

For example, this global Git configuration:

[gtr "worktrees"]
    dir = "../{repo}-workspace"

would resolve as follows:

Main repository Worktree base directory
/repo/foo /repo/foo-workspace
/repo/bar /repo/bar-workspace

I suggest defining {repo} as the basename of repo_root, using gtr's existing main repository discovery logic.
It would not be derived from the remote URL or the current linked worktree's directory name.
Running gtr from a linked worktree or a subdirectory would therefore resolve to the same main repository name.

Placeholder expansion would happen before the existing tilde expansion and relative-path resolution.
Relative paths would continue to be resolved from the main repository root.

Scope and compatibility

  • Initially support only {repo}, without adding new configuration keys for a base-directory prefix or suffix.
  • Keep the existing <repo>-worktrees default when no base directory is configured.
  • Preserve existing paths that do not contain {repo}, as well as configuration precedence.
  • Keep gtr.worktrees.prefix and --folder behavior unchanged; these would continue to control individual worktree directory names.
  • Do not add automatic migration of existing worktrees.

Details such as handling existing paths that contain a literal {repo} and whether to provide an escape syntax could be discussed before implementation.

Questions

Would adding this placeholder to gtr.worktrees.dir fit the project's direction?
I'd also appreciate feedback on the {repo} syntax and the definition of the repository name above.

If this approach sounds reasonable, I'd be happy to prepare a PR with tests and documentation updates.

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