Skip to content

[bug] .gitattributes linguist-language overrides are ignored for files in subdirectories #1691

Description

@breken-ai

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

  1. In an indexed repo, add *.h linguist-language=C to .gitattributes and have a header in a subdirectory, e.g. src/foo.h.
  2. 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.)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions