Skip to content

BUG: When working with submodules the find_git_root! macro doesnt work #40

Description

@ScottGibb

Describe the bug
commitment-issues fails when a crate is built from a Git submodule checkout inside Docker. The crate detects the submodule working tree as the Git root because a .git entry exists, but in a submodule that .git is a pointer file (gitdir: ...) to the parent repository’s .git/modules/... directory. Inside the Docker build context that referenced path does not exist, so metadata generation fails.

To Reproduce
Steps to reproduce the behavior:

  1. Put a Rust crate that uses commitment_issues::include_metadata!(); inside a Git submodule.

  2. Add a build.rs containing:

        println!(
            "cargo:rerun-if-changed={}",
            commitment_issues::find_valid_git_root!()
        ); }
  3. Build that crate in Docker from the submodule directory as the build context, copying its  .git  entry into the image.

  4. Run  cargo build .

  5. See error:
    --> src/lib.rs:3:1
    |
    3 | commitment_issues::include_metadata!();
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expected behaviour
I expected  commitment-issues  to either:

• correctly handle submodule  .git  indirection, or
• fail with a clearer error explaining that the discovered  .git  file points to an external  gitdir  not available in the current build context.

Screenshots
Not applicable.

Hardware (please complete the following information):

• OS: MacOS / Linux (Docker build on Mac host, Linux container)
• OS Version: macOS Sequoia 15.x, Debian Bookworm container
• Rust Version: stable (exact version can be provided if needed)
• Commitment Issues Crate Version: 0.2
• Other Crate Versions: git2 via  commitment-issues 

Additional context
The relevant detail is that the submodule’s  .git  is not a real directory. It contains:

gitdir: ../../../.git/modules/PiHall/Home-Power-Monitor

 find_valid_git_root_inner()  currently appears to stop as soon as  path.join(".git").exists()  is true, and  Repository::open(&git_root)  later fails because the referenced  gitdir  path is outside the copied Docker build context.

This works fine in a normal standalone repository with a real  .git/  directory. The issue seems specific to submodules/worktrees where  .git  is an indirection file rather than a self-contained repo directory.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Fields

    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