Skip to content

Can git.bzl support checking out repo to another sub directory #25453

Closed

Description

@mzhaom

Description of the feature request:

https://github.com/bazelbuild/bazel/blob/master/tools/build_defs/repo/git.bzl

The use case is for some jsonnet libraries, they are referred using their github module URL,
Take https://github.com/jsonnet-libs/xtd for example
The library is imported as

local xtd = import "github.com/jsonnet-libs/xtd/main.libsonnet"

So when we fetch it to prepare the build, ideally it should be checked out to github.com/jsonnet-libs/xtd instead xtd directory. So adding an option to support that would be nice.

Currently, I work around this by introducing a patch command like this:

    patch_cmds = [
        # Move the source code location with github.com/jsonnet-libs/xtd directory
        # So imports with such a prefix would work.
        "mkdir -p github.com/jsonnet-libs/xtd",
        "cp *.libsonnet github.com/jsonnet-libs/xtd",
    ],

It works but looks tedious.

Which category does this issue belong to?

No response

What underlying problem are you trying to solve with this feature?

No response

Which operating system are you running Bazel on?

No response

What is the output of bazel info release?

No response

If bazel info release returns development version or (@non-git), tell us how you built Bazel.

No response

What's the output of git remote get-url origin; git rev-parse HEAD ?


Have you found anything relevant by searching the web?

No response

Any other information, logs, or outputs that you want to share?

No response

Activity

  1. added
    untriaged
    on Mar 4, 2025
  2. added
    team-ExternalDeps
    on Mar 4, 2025
  3. meteorcloudy commented on Mar 11, 2025

    @meteorcloudy
    Member

    I could imagine we add an add_prefix attribute to git_repository (maybe also http_archive) to create the directory.

  4. meteorcloudy commented on Mar 11, 2025

    @meteorcloudy
    Member

    We actually already have it for http_archive:

    "add_prefix": attr.string(

  5. added
    P2
    help wanted
    and removed
    untriaged
    on Mar 11, 2025
  6. willstranton commented on May 2, 2026

    @willstranton
    Contributor

    I could imagine we add an add_prefix attribute to git_repository

    See the implementation of this in #29453

  7. added a commit that references this issue on May 5, 2026
    accb2de
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

    P2help wantedteam-ExternalDepstype: feature request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions