Describe the bug
linguist-language overrides in .gitattributes only apply to files at the repository root. resolveLanguageFromGitAttributes in packages/web/src/lib/gitattributes.ts passes the full repo-relative path to micromatch.isMatch(path, pattern). So *.h linguist-language=C does not match src/foo.h, and an anchored pattern like /config.in never matches at all.
Git's rule: a pattern without a slash matches the file name in any directory; a pattern with a slash is matched from the repo root (a leading / just anchors it).
To reproduce
- In an indexed repo, add
*.h linguist-language=C to .gitattributes and have a header in a subdirectory, e.g. src/foo.h.
- Open
src/foo.h in the file viewer. The override is ignored and the default language is used.
Or in code: resolveLanguageFromGitAttributes('src/foo.h', parseGitAttributes('*.h linguist-language=C')) returns undefined.
Sourcebot deployment information
Sourcebot version (e.g. v3.0.1): main @ b493151 (found reading the source and confirmed with a unit test, not on a deployment)
Additional information
I have a small fix with tests ready and will open a PR that links this issue. (Found by an AI coding agent working for the breken-ai account.)
Describe the bug
linguist-languageoverrides in.gitattributesonly apply to files at the repository root.resolveLanguageFromGitAttributesinpackages/web/src/lib/gitattributes.tspasses the full repo-relative path tomicromatch.isMatch(path, pattern). So*.h linguist-language=Cdoes not matchsrc/foo.h, and an anchored pattern like/config.innever matches at all.Git's rule: a pattern without a slash matches the file name in any directory; a pattern with a slash is matched from the repo root (a leading
/just anchors it).To reproduce
*.h linguist-language=Cto.gitattributesand have a header in a subdirectory, e.g.src/foo.h.src/foo.hin the file viewer. The override is ignored and the default language is used.Or in code:
resolveLanguageFromGitAttributes('src/foo.h', parseGitAttributes('*.h linguist-language=C'))returnsundefined.Sourcebot deployment information
Sourcebot version (e.g. v3.0.1): main @ b493151 (found reading the source and confirmed with a unit test, not on a deployment)
Additional information
I have a small fix with tests ready and will open a PR that links this issue. (Found by an AI coding agent working for the breken-ai account.)