Running make pkg-stats fails when run outside of GIt repository
### Check-list
- [x] I did not find the issue in the existing issues
- [ ] I can reproduce the issue with unmodified Buildroot from [this
repository](https://gitlab.com/buildroot.org/buildroot), not from a
fork somewhere else
- [x] I can reproduce the issue on the latest commit of the branch I'm using:
- [ ] master
- [x] stable (buildroot-2025.02)
- [ ] LTS
- [x] I can reproduce the issue after running `make clean; make`
- [x] I attached the full build log file (e.g. `make 2>&1 |tee build.log`)
- [ ] I attached a **minimal** defconfig file that can reproduce the
issue (`make BR2_DEFCONFIG=$(pwd)/issue_defconfig savedefconfig`)
- [ ] I also attached the configuration for kconfig-based packages that
are enabled (and necessary to reproduce the issue), most notably:
- [ ] busybox
- [ ] linux
- [ ] uclibc
- [ ] uboot
- [ ] …
What I did
- Buildroot version: 2025.02 release
- Distribution of the build machine:
PRETTY_NAME="Debian GNU/Linux 12 (bookworm)"
NAME="Debian GNU/Linux"
VERSION_ID="12"
VERSION="12 (bookworm)"
VERSION_CODENAME=bookworm
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
I'm not certain if this is an issue or not--I did perform a quick search but found nothing that would indicate this behavior is correct--but when running make pkg-stats for Buildroot outside of a git repository, the process fails with the below output:
fatal: not a git repository (or any of the parent directories): .git
Traceback (most recent call last):
File "/home/anon/Development/buildroot-test/buildroot-2025.02-BAK/support/scripts/pkg-stats", line 1346, in <module>
__main__()
File "/home/anon/Development/buildroot-test/buildroot-2025.02-BAK/support/scripts/pkg-stats", line 1298, in __main__
commit = subprocess.check_output(['git', '-C', brpath,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/subprocess.py", line 466, in check_output
return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/subprocess.py", line 571, in run
raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['git', '-C', '/home/anon/Development/buildroot-test/buildroot-2025.02-BAK', 'rev-parse', 'HEAD']' returned non-zero exit status 128.
make: *** [Makefile:941: pkg-stats] Error 1
I know most--if not all--people would be running Buildroot in a git repository. I plan on doing this as well, but at this point, I'm just playing around with Buildroot to learn more about it's features. If this is the correct behavior, then feel free to close this ticket. If not, it may be nice to find a way to allow this to work; perhaps the hash could be set to some known value to indicate that Git is not currently set up?
The problem is resolved by creating a Git repository in the Buildroot directory and making at least one commit.
I believe the code responsible for this error is in support/scripts/pkg-stats:
1298 commit = subprocess.check_output(['git', '-C', brpath,
1299 'rev-parse',
1300 'HEAD']).splitlines()[0].decode()
I'm familiar enough with Python that I could attempt making a patch for this, but some clarification on what needs to happen here would be appreciated.