Skip to content

bit_remote: resolve_gitdir treats absolute Windows drive paths as relative #209

Description

@Milky2018

Summary

mizchi/bit_remote 0.48.0 resolves an absolute Windows gitdir: target as a relative path. For example:

  • .git path: C:/linked/.git
  • Contents: gitdir: C:/repo/.git/worktrees/linked
  • Expected: C:/repo/.git/worktrees/linked
  • Actual: C:/linked/C:/repo/.git/worktrees/linked

The published package reproduces this deterministically. Current main at 2681c3bc815d01aa56e678f45eb98e268c052481 still checks only whether the target starts with /.

Minimal reproduction

This test injects Windows-style .git contents through the public RepoFileSystem trait, so it runs without a Windows host or any actual repository. Create these files and run moon test --target native.

moon.mod

name = "repro/bit-gitdir"
version = "0.0.0"
import {
  "mizchi/bit_remote@0.48.0",
  "mizchi/bit_types@0.48.0",
}

moon.pkg

import {
  "mizchi/bit_remote" @remote,
  "mizchi/bit_types" @types,
  "moonbitlang/core/encoding/utf8",
} for "wbtest"

repro_wbtest.mbt

///|
priv struct GitdirFixture { target : String }

///|
impl @types.RepoFileSystem for GitdirFixture with fn read_file(self, _) {
  @utf8.encode("gitdir: " + self.target + "\n")
}

///|
impl @types.RepoFileSystem for GitdirFixture with fn readdir(_, _) { [] }

///|
impl @types.RepoFileSystem for GitdirFixture with fn is_dir(_, _) { false }

///|
impl @types.RepoFileSystem for GitdirFixture with fn is_file(_, _) { true }

///|
impl @types.RepoFileSystem for GitdirFixture with fn mtime(_, _) { (0, 0) }

///|
test "absolute Windows gitdir" {
  let target = "C:/repo/.git/worktrees/linked"
  let fs = GitdirFixture::{ target }
  assert_eq(@remote.resolve_gitdir(fs, "C:/linked/.git"), target)
}

Actual assertion failure:

"C:/linked/C:/repo/.git/worktrees/linked" != "C:/repo/.git/worktrees/linked"

Cause and suggested coverage

resolve_gitdir treats every target not starting with / as relative and prepends the .git file's parent. detect_git_dir uses that result, so library callers can receive an invalid metadata directory for a Windows linked worktree.

Please use platform-aware absolute-path and parent-path handling. Regression coverage should include Windows drive-rooted paths, native-backslash/UNC forms, existing POSIX absolute paths, and ordinary relative gitdir: paths. Drive-relative paths such as C:relative should remain distinct from C:/absolute.

Verification scope

  • Executed the injected-filesystem reproduction on macOS against mizchi/bit_remote@0.48.0 and mizchi/bit_types@0.48.0.
  • Confirmed the unchanged resolver in current upstream source.
  • I have not run a real linked-worktree integration test on Windows. The Windows end-to-end impact is inferred from the reproduced path-resolution result.
  • Toolchain: moon 0.1.20260920 (914d7da), moonc v0.10.14+7d59c7ec9.

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