Bazel: git_repository dependency branch not followed

Created on 22 Jun 2019  路  2Comments  路  Source: bazelbuild/bazel

Description of the problem / feature request:

git-repository dependency on a branch is not properly followed. Example:

  • Project bz-main-project depends on bz-commons-values. Both are git repositories and the branch in the git_repository dependency is set to master
  • On initial build of bz-main-project, the build properly clone bz-commons-values project and uses the values from its master branch
  • We update bz-commons-values source code and push the changes to origin
  • We build again bz-main-project with bazel build //...

    • We get the following message on the log
      DEBUG: /home/oskrpko/.cache/bazel/_bazel_oskrpko/c429044b6da761f38a72b0fea910fe72/external/bazel_tools/tools/build_defs/repo/git.bzl:45:9: git.bzl: Cloning or updating (--depth=1) repository bz-commons-values using strip_prefix of [None].
      This is a similar message as on initial build.

    • However the actual build still uses the values of bz-commons-values from its initial clone. Since the git repository dependency uses a branch and not a tag or commit we expected bazel to detect the changes to the remote branch to be properly fetched.

Some remarks

  • If we clean the cache with bazel clean --expunge or bazel sync, we get the new code from the bz-commons-values origin. However I don't think we should have to clean the cache to get the new code.
  • If we make a change in bz-main-project, for example in WORKSPACE, and we rebuild it. We still don't get the new changes from bz-commons-values origin, but we even do not see ...Cloning or updating log message.... Whether or not we make a change in the dependent project, I think the build should use the latest sources from the dependency origin when using a branch.

Feature requests: what underlying problem are you trying to solve with this feature?

NA

Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

  • git clone https://github.com/oskrpko/bz-commons-values.git
  • git clone https://github.com/oskrpko/bz-main-project.git
  • In bz-main-project execute bazel build //...
  • The result is the one expected. MYVAR value is properly printed in the console.
  • Change the MYVAR value in bz-commons-values and push master to origin
  • In bz-main-project execute bazel build //...
  • The result is not anymore the one expected. The old MYVAR value is still printed in the console, not the new one.

What operating system are you running Bazel on?

CentOS 7

What's the output of bazel info release?

release 0.27.0

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

I did not built it myself. I used yum install bazel

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

NA. I did not build bazel from the sources.

Have you found anything relevant by searching the web?

From my searches on the web I understood that a git_repository with a branch attribute is supposed to be followed. I did not find mention of this specific issue.

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

area-ExternalDeps team-XProduct under investigation untriaged

All 2 comments

I think this is intended. I don't think Bazel should check the repository on each build command (that would make all builds slow).

I would suggest specifying the commit in the call to git_repository, and update it when you want.

Found this behavior surprising.
When pointing at a branch, the expectation I had was that I would be using the latest commit from that branch, not the commit that branch happened to point to at the time that the repository was cloned.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ttsugriy picture ttsugriy  路  3Comments

alexandrvb picture alexandrvb  路  3Comments

meteorcloudy picture meteorcloudy  路  3Comments

sandipmgiri picture sandipmgiri  路  3Comments

GaofengCheng picture GaofengCheng  路  3Comments