Repository: adamchainz/pygments-git (language: python)

Issue:
git attributes files
### Description

https://git-scm.com/docs/gitattributes


Discussion / hints:

Fix patch:
diff --git a/CHANGELOG.rst b/CHANGELOG.rst
index 7d7cad8..c8046b8 100644
--- a/CHANGELOG.rst
+++ b/CHANGELOG.rst
@@ -2,7 +2,7 @@
 Changelog
 =========
 
-* Add ``git-conflict-markers``.
+* Add ``git-attributes`` and ``git-conflict-markers`` lexers.
 
 1.1.0 (2023-04-06)
 ------------------
diff --git a/setup.cfg b/setup.cfg
index c1d625c..32bec5d 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -44,6 +44,7 @@ where = src
 
 [options.entry_points]
 pygments.lexers =
+    git-attributes=pygments_git:GitAttributesLexer
     git-commit-edit-msg=pygments_git:GitCommitEditMsgLexer
     git-conflict-markers=pygments_git:GitConflictMarkersLexer
     git-console=pygments_git:GitBashSessionLexer
diff --git a/src/pygments_git/__init__.py b/src/pygments_git/__init__.py
index fe1ffb6..8e64833 100644
--- a/src/pygments_git/__init__.py
+++ b/src/pygments_git/__init__.py
@@ -10,13 +10,47 @@
 from pygments.token import Comment
 from pygments.token import Generic
 from pygments.token import Keyword
+from pygments.token import Literal
 from pygments.token import Name
 from pygments.token import Number
+from pygments.token import Operator
 from pygments.token import Punctuation
 from pygments.token import String
 from pygments.token import Text
 
 
+class GitAttributesLexer(RegexLexer):
+    name = "Git Attributes"
+    aliases = ("git-attributes",)
+    flags = re.MULTILINE
+
+    tokens = {
+        "root": [
+            (r"^#.*$", Comment),
+            (
+                r"^(\S+)(\s+)",
+                bygroups(Literal, Text),  # type: ignore[no-untyped-call]
+                "attributes",
+            ),
+            (r"^.*\n", Text),
+        ],
+        "attributes": [
+            (
+                r"(-)?(.+?)(=)([^ \t\n]+)",
+                bygroups(  # type: ignore[no-untyped-call]
+                    Operator, Name.Variable, Operator, String.Symbol
+                ),
+            ),
+            (
+                r"(-)?([^ \t\n]+)",
+                bygroups(Operator, Name.Variable),  # type: ignore[no-untyped-call]
+            ),
+            (r"[ \t]+", Text),
+            (r"$", Text, "#pop"),
+        ],
+    }
+
+
 class GitCommitEditMsgLexer(RegexLexer):
     name = "Git Commit Edit-Msg"
     aliases = ("git-commit-edit-msg",)


Test patch:
diff --git a/tests/index.html b/tests/index.html
index 95a66b1..0896807 100644
--- a/tests/index.html
+++ b/tests/index.html
@@ -98,6 +98,31 @@
 </head>
 <body>
 <h1>Tests</h1>
+<h2 id=test_git_attributes>
+test_git_attributes
+<a href=#test_git_attributes>#</a>
+</h2>
+<p>
+Lexer: git-attributes
+</p>
+<div class=compare><code>
+<pre>
+# Hello attributes
+*.txt       text
+*	text=auto
+*.sh        text eol=lf
+*.jpg -text
+*.ps1 text working-tree-encoding=UTF-16LE eol=CRLF
+</pre>
+</code>
+<div class="highlight"><pre><span></span><span class="c"># Hello attributes</span>
+<span class="l">*.txt</span>       <span class="nv">text</span>
+<span class="l">*</span>	<span class="nv">text</span><span class="o">=</span><span class="ss">auto</span>
+<span class="l">*.sh</span>        <span class="nv">text eol</span><span class="o">=</span><span class="ss">lf</span>
+<span class="l">*.jpg</span> <span class="o">-</span><span class="nv">text</span>
+<span class="l">*.ps1</span> <span class="nv">text working-tree-encoding</span><span class="o">=</span><span class="ss">UTF-16LE</span><span class="nv"> eol</span><span class="o">=</span><span class="ss">CRLF</span>
+</pre></div>
+</div>
 <h2 id=test_git_commit_edit_msg>
 test_git_commit_edit_msg
 <a href=#test_git_commit_edit_msg>#</a>
diff --git a/tests/test_pygments_git.py b/tests/test_pygments_git.py
index 8f139ef..3904539 100644
--- a/tests/test_pygments_git.py
+++ b/tests/test_pygments_git.py
@@ -119,6 +119,21 @@ def check(self, testid: str, lexer: str, given: str) -> None:
         index.write_text("\n".join(lines))
 
 
+def test_git_attributes(golden_file):
+    golden_file.check(
+        "test_git_attributes",
+        "git-attributes",
+        """\
+        # Hello attributes
+        *.txt       text
+        *\ttext=auto
+        *.sh        text eol=lf
+        *.jpg -text
+        *.ps1 text working-tree-encoding=UTF-16LE eol=CRLF
+        """,
+    )
+
+
 def test_git_commit_edit_msg(golden_file):
     golden_file.check(
         "test_git_commit_edit_msg",