Creating a git branch that ends in "BUILD" confuses Bazel
Description of the bug:
If you create a git branch like ob/BUILD or ob/build (on macOS where the file system is case insensitive) bazel thinks it's a build file and chokes on it.
Which category does this issue belong to?
Core
What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
$ git init demo
$ cd demo
$ touch MODULE.bazel WORKSPACE
$ git add -A
$ git commit -am "init bazel repo"
[main (root-commit) f45e299] init bazel repo
2 files changed, 0 insertions(+), 0 deletions(-)
create mode 100644 MODULE.bazel
create mode 100644 WORKSPACE
$ git checkout -b ob/build
Switched to a new branch 'ob/build'
$ bazel build //...
ERROR: /Users/obonilla/tmp/demo/.git/logs/refs/heads/ob/BUILD:1:1: invalid octal literal: 0000000000000000000000000000000000000000 (use '0o000000000000000000000000000000000000000')
ERROR: /Users/obonilla/tmp/demo/.git/logs/refs/heads/ob/BUILD:1:42: syntax error at 'f45e29939884f14e45e1dac396a2534ce168ee1c': expected newline
ERROR: /Users/obonilla/tmp/demo/.git/logs/refs/heads/ob/BUILD:1:104: invalid character: '@'
ERROR: /Users/obonilla/tmp/demo/.git/logs/refs/heads/ob/BUILD:1:128: invalid octal literal: 0700 (use '0o700')
ERROR: /Users/obonilla/tmp/demo/.git/logs/refs/heads/ob/BUILD:1:149: keyword 'from' not supported
ERROR: /Users/obonilla/tmp/demo/.git/refs/heads/ob/BUILD:1:1: name 'f45e29939884f14e45e1dac396a2534ce168ee1c' is not defined
ERROR: package contains errors: .git/logs/refs/heads/ob
ERROR: package contains errors: .git/refs/heads/ob
WARNING: Target pattern parsing failed.
ERROR: Skipping '//...': Error evaluating '//...': error loading package '.git/logs/refs/heads/ob': Package '.git/logs/refs/heads/ob' contains errors
ERROR: Error evaluating '//...': error loading package '.git/logs/refs/heads/ob': Package '.git/logs/refs/heads/ob' contains errors
INFO: Elapsed time: 2.027s
INFO: 0 processes.
ERROR: Build did NOT complete successfully
Which operating system are you running Bazel on?
macOS
What is the output of bazel info release?
release 7.3.1
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 ?
No response
If this is a regression, please try to identify the Bazel commit where the bug was introduced with bazelisk --bisect.
No response
Have you found anything relevant by searching the web?
No response
Any other information, logs, or outputs that you want to share?
No response
Could you try adding .git to .bazelignore?
Could you try adding
.gitto.bazelignore?
That works but I wonder if it should be ignored by default? Does it ever make sense to look for BUILD files in the .git directory? Seems like just wasting time scanning what could potentially be a large directory...
I can imagine use cases for using gitattributes in actions (tests), though most of the things under .git are probably not useful