<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugzilla.yoctoproject.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.6"
          urlbase="https://bugzilla.yoctoproject.org/"
          
          maintainer="it-coreprojects-helpdesk@linuxfoundation.org"
>

    <bug>
          <bug_id>15917</bug_id>
          
          <creation_ts>2025-06-27 08:52:19 +0000</creation_ts>
          <short_desc>fetch2/git: `_contains_lfs` check is falsely triggered by commented lines in .gitattributes</short_desc>
          <delta_ts>2025-08-14 14:54:15 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>7</classification_id>
          <classification>Build System, Metadata &amp; Runtime</classification>
          <product>BitBake</product>
          <component>bitbake</component>
          <version>unspecified</version>
          <rep_platform>x86</rep_platform>
          <op_sys>x86_64</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>Medium</priority>
          <bug_severity>enhancement</bug_severity>
          <target_milestone>5.3</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Markus Isaksson">markus.isaksson</reporter>
          <assigned_to name="Markus Isaksson">markus.isaksson</assigned_to>
          <cc>poky.bs.watcher</cc>
    
    <cc>poky.watcher</cc>
    
    <cc>randy.macleod</cc>
    
    <cc>richard.purdie</cc>
          
          
          <cf_os>---</cf_os>
          <cf_regression_type>---</cf_regression_type>
          
          <cf_docchange>No (bug/feature does not impact docs)</cf_docchange>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>102355</commentid>
    <comment_count>0</comment_count>
    <who name="Markus Isaksson">markus.isaksson</who>
    <bug_when>2025-06-27 08:52:19 +0000</bug_when>
    <thetext>**Environment:**
```
$ bitbake --version
BitBake Build Tool Core version 2.8.0

$ lscpu
Architecture:             x86_64
  CPU op-mode(s):         32-bit, 64-bit
  Address sizes:          43 bits physical, 48 bits virtual
  Byte Order:             Little Endian
CPU(s):                   8
  On-line CPU(s) list:    0-7
Vendor ID:                GenuineIntel
  Model name:             Intel(R) Xeon(R) CPU E5-2695 v4 @ 2.10GHz

$ cat /etc/os-release
PRETTY_NAME=&quot;Debian GNU/Linux 12 (bookworm)&quot;
NAME=&quot;Debian GNU/Linux&quot;
VERSION_ID=&quot;12&quot;
VERSION=&quot;12 (bookworm)&quot;
VERSION_CODENAME=bookworm
ID=debian
```

Inspecting master branch in (https://github.com/openembedded/bitbake) shows the same issue

**Description:**
When creating a recipe for a Git repository that contains a `.gitattributes` file with commented-out LFS rules, the `do_fetch` task incorrectly detects LFS content. This causes the fetcher to attempt `git lfs` commands, leading to a build failure on any host where the `git-lfs` client is not installed.

This behavior is confusing because the repository does not actually use or require Git LFS.

**Steps to Reproduce:**

1.  Use a build host that does not have the `git-lfs` package installed.
2.  Create a recipe for a repository containing a `.gitattributes` file with commented-out LFS rules. A specific example is `MicrochipTech/cryptoauthlib` at version 3.7.4 or later. The relevant `.gitattributes` file contains:
    ```
    # Reinstate LFS if pdf sizes increase considerably in the future releases
    # *.pdf filter=lfs diff=lfs merge=lfs -text
    ```
3.  Use the following minimal recipe:
    ```bb
    SRC_URI = &quot;git://github.com/MicrochipTech/cryptoauthlib.git;protocol=https;branch=main&quot;
    SRCREV = &quot;a7bbe3a2d6851dea2ae624b598a823c0fb70d48c&quot; # Corresponds to v3.7.8

    S = &quot;${WORKDIR}/git&quot;
    ```
4.  Attempt to build the recipe (`bitbake cryptoauthlib`).

**Expected Result:**
The `do_fetch` task should successfully clone the repository. Since no files are actually managed by LFS, the fetcher should not attempt any `git lfs` operations.

**Actual Result:**
The `do_fetch` task fails with an error indicating that `git lfs` is not a valid command.

```
WARNING: cryptoauthlib-3.7.8+git-r0 do_fetch: Failed to fetch URL git://github.com/MicrochipTech/cryptoauthlib.git;protocol=https;branch=main, attempting MIRRORS if available
ERROR: cryptoauthlib-3.7.8+git-r0 do_fetch: Fetcher failure: Fetch command export PSEUDO_DISABLED=1; &lt;...more exports...&gt; git -c gc.autoDetach=false -c core.pager=cat -c safe.bareRepository=all lfs ls-files -l a7bbe3a2d6851dea2ae624b598a823c0fb70d48c failed with exit code 1, output:
git: &apos;lfs&apos; is not a git command. See &apos;git --help&apos;.

The most similar command is
    log
```

**Analysis:**
The root cause is the implementation of the `_contains_lfs` helper function in `openembedded/bitbake/lib/bb/fetch2/git.py`.

The function uses the following command to detect LFS content:

```python
cmd = &quot;%s grep lfs %s:.gitattributes | wc -l&quot; % (
    ud.basecmd, ud.revision)
```

This command uses `git grep` to find the literal string &quot;lfs&quot; within the `.gitattributes` file. However, `grep` does not account for comment characters (`#`) in this context. It finds the string &quot;lfs&quot; on the commented-out line, causing `wc -l` to return a non-zero value.

This false positive triggers the subsequent LFS logic, leading to the failure.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>102386</commentid>
    <comment_count>1</comment_count>
    <who name="Randy MacLeod">randy.macleod</who>
    <bug_when>2025-07-03 14:37:55 +0000</bug_when>
    <thetext>Markus, 

Are you willing and able to submit a patch.
https://docs.yoctoproject.org/contributor-guide/index.html

If so please accept this defect. 
If not, it will be unassigned until someone has time to get to it.
- YP Bug review</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>102603</commentid>
    <comment_count>2</comment_count>
    <who name="Richard Purdie">richard.purdie</who>
    <bug_when>2025-08-14 14:53:46 +0000</bug_when>
    <thetext>https://git.yoctoproject.org/poky/commit/?id=5bdce86cde17f57ffcea81895ea06689ac77fe0a</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>