Skip to content

GetDefaultRepoRoot() throws in git worktrees when running dotnet run --project #180

@BenjaminMichaelis

Description

@BenjaminMichaelis

Description

RepositoryPaths.GetDefaultRepoRoot() throws InvalidOperationException: SolutionDir is not a valid directory when tests
are run via dotnet run --project from a git worktree.

Two independent failure modes combine to produce this:

  1. $(SolutionDir) is unset during project-level builds. The WriteLaunchers MSBuild target (in
    IntelliTect.Multitool.targets) writes SolutionDir to %TEMP%\IntelliTect.MultiTool.BuildVariables.tmp at build time. When
    building via dotnet run --project, MSBuild has no solution context, so $(SolutionDir) is an empty string — and that
    gets written to the temp file, invalidating any previously correct value.
  2. The .git-walk fallback fails in git worktrees. TrySearchForGitContainingDirectory walks up the directory tree
    looking for a .git directory. In a git worktree, the checkout contains a .git file (a gitfile pointer) instead of a
    directory. The walk finds the file but not a directory, so the fallback also fails.

Either fix alone would resolve the issue; both need to be addressed for full robustness.


Repro Steps

  1. Clone the repo and create a worktree: git clone https://github.com//.git main
    cd main
    git worktree add ../my-branch my-branch
    cd ../my-branch
  2. Add a dependency on IntelliTect.Multitool in a test project that calls RepositoryPaths.GetDefaultRepoRoot() at
    runtime.
  3. Run the tests directly against the project (not the solution): dotnet run --project MyProject.Tests
  4. Observe the exception: InvalidOperationException: SolutionDir is not a valid directory.
    at IntelliTect.Multitool.RepositoryPaths.GetDefaultRepoRoot()

Workaround

Build from the solution first (which writes a valid SolutionDir to the temp file), then run with --no-build to skip the
project-level rebuild that would overwrite it:

dotnet build MyApp.sln
dotnet run --project MyProject.Tests --no-build


Expected Behavior

GetDefaultRepoRoot() should successfully locate the repo root from a git worktree, either by:

  • Recognising a .git file (not just a .git directory) as a valid repo root marker in
    TrySearchForGitContainingDirectory, and/or
  • Not overwriting the temp file with an empty SolutionDir when no solution is in context (e.g. only write when
    $(SolutionDir) is non-empty)

Environment

  • IntelliTect.Multitool version: 1.5.3
  • Git feature: worktrees (git worktree add)
  • Build tool: dotnet run --project (no solution file in context)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions