Skip to content

[build] consider using git worktrees for bazel-diff #817

@aaylward

Description

@aaylward

Is it possible to make bazel-diff diff against origin/main directly instead of having to clone with some sufficient depth in CI?

⏺ Yes, you can modify bazel-diff to work without checking out revisions by using git's ability to show files at specific commits. Here are a few approaches:

⏺ Read(scripts/diff-build)
⎿  Read 15 lines (ctrl+r to expand)

⏺ Option 1: Use git worktree - Create temporary worktrees for each revision instead of checking out:

Instead of checkout, use worktrees

TEMP_WORKTREE="/tmp/bazel-diff-base-$$"
git worktree add "$TEMP_WORKTREE" "$BASE_REVISION"
"$BAZEL_DIFF_BIN" generate-hashes -w "$TEMP_WORKTREE" -b "$BAZEL_PATH" $EXTERNAL_REPOS "$starting_hashes_json"
git worktree remove "$TEMP_WORKTREE"

Option 2: Use git archive - Extract files at specific commits:

Extract base revision files

BASE_DIR="/tmp/bazel-diff-base-$$"
git archive "$BASE_REVISION" | tar -x -C "$BASE_DIR"
"$BAZEL_DIFF_BIN" generate-hashes -w "$BASE_DIR" -b "$BAZEL_PATH" "$starting_hashes_json"

Option 3: Fetch only what you need:

In CI, fetch just the base branch

git fetch origin main:origin/main --depth=1

The git worktree approach (Option 1) is cleanest since it doesn't require checking out different revisions in your main workspace, and bazel-diff can still run against proper git repositories rather than extracted archives.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions