首页 > 解决方案 > github-linguist 包括语言统计中具有 linguist-vendred 属性的文件

问题描述

我有一个主要是 C++ 的 github 存储库,但有很多供应商生成的 C 代码(微控制器的驱动程序),这些代码完全抛弃了语言统计信息。我已阅读此页面,并在我的存储库中创建了一个.gitattributes文件,该文件应将所有这些驱动程序文件标记为linguist-vendored并防止它们包含在统计信息中。尽管git check-attr报告该linguist-vendored属性已设置,但github-linguist命令行工具仍会忽略这一点。我究竟做错了什么?

$ cat .gitattributes
STM32[[:space:]]Code/*/** linguist-vendored
STM32[[:space:]]Code/*/Core/Src/** -linguist-vendored
STM32[[:space:]]Code/*/Core/Inc/** -linguist-vendored

$ git add .gitattributes
$ git commit --amend --no-edit
[master 017861e] fix github language metrics
 Date: Sat Sep 25 16:09:00 2021 -0700
 1 file changed, 3 insertions(+)
 create mode 100644 .gitattributes

$ git check-attr -a "STM32 Code/BLDC/Drivers/STM32F3xx_HAL_Driver/Src/stm32f3xx_hal.c"
STM32 Code/BLDC/Drivers/STM32F3xx_HAL_Driver/Src/stm32f3xx_hal.c: linguist-vendored: set

$ github-linguist --breakdown
94.75%  C
2.92%   C++
2.09%   Makefile
0.23%   Assembly
0.01%   Shell

...
C:
STM32 Code/BLDC/Drivers/STM32F3xx_HAL_Driver/Src/stm32f3xx_hal.c
...

我也尝试将.gitattributes文件更改为

STM32[[:space:]]Code/** linguist-vendored

它仍然不会忽略里面的文件。

标签: gitgithub-linguist

解决方案


我怀疑您可能正在使用旧版本的语言学家和/或粗犷(这是检查 gitattributes 的内容);可能是您的操作系统附带的版本,因为我无法使用 GitHub 使用的最新版本重现您的行为:

$ gem install github-linguist
Fetching github-linguist-7.16.1.gem
Building native extensions. This could take a while...
Successfully installed github-linguist-7.16.1
1 gem installed
$ git init foo
Initialized empty Git repository in /Users/lildude/Downloads/trash/foo/.git/
$ mkdir -p "foo/STM32 Code/BLDC/Drivers/STM32F3xx_HAL_Driver/Src/"
$ echo "foo" > "foo/STM32 Code/BLDC/Drivers/STM32F3xx_HAL_Driver/Src/stm32f3xx_hal.c"
$ cd foo
$ git add .
$ git commit -m 'Initial commit'
$ github-linguist . --breakdown
100.00% 4          C

C:
STM32 Code/BLDC/Drivers/STM32F3xx_HAL_Driver/Src/stm32f3xx_hal.c

$ echo "STM32[[:space:]]Code/*/** linguist-vendored" > .gitattributes
$ git add .gitattributes
$ git commit -m 'overwrite'
[main 15e0a4e] overwrite
 1 file changed, 1 insertion(+)
 create mode 100644 .gitattributes
$ github-linguist . --breakdown


$

推荐阅读