[makepkg] failure to fetch a Git source with LFS files
When a source is a Git repository that includes LFS files, the Creating Working Copy step fails with a "smudge" error. This issue can be reproduced by attempting to build the niri-git project:
$ makepkg
==> Making package: niri-git 0.1.4.r0.7ff2de1-2 (Thu Apr 11 02:47:00 2024)
==> Checking runtime dependencies...
==> Checking buildtime dependencies...
==> Retrieving sources...
-> Cloning niri git repo...
Cloning into bare repository '/tmp/snake/niri-git/niri'...
remote: Enumerating objects: 6257, done.
remote: Counting objects: 100% (2721/2721), done.
remote: Compressing objects: 100% (752/752), done.
remote: Total 6257 (delta 2100), reused 2430 (delta 1918), pack-reused 3536
Receiving objects: 100% (6257/6257), 1.80 MiB | 6.20 MiB/s, done.
Resolving deltas: 100% (4396/4396), done.
==> Validating source files with b2sums...
niri ... Skipped
==> Extracting sources...
-> Creating working copy of niri git repo...
Cloning into 'niri'...
done.
Downloading wiki/img/block-out-from-screencast.png (432 KB)
Error downloading object: wiki/img/block-out-from-screencast.png (65b22b8): Smudge error: Error downloading wiki/img/block-out-from-screencast.png (65b22b833dc0b05166b4b3403b1c6323315ca0885d4a75d2bbb68250a3855e96): error transferring "65b22b833dc0b05166b4b3403b1c6323315ca0885d4a75d2bbb68250a3855e96": [0] remote missing object 65b22b833dc0b05166b4b3403b1c6323315ca0885d4a75d2bbb68250a3855e96
Errors logged to '/tmp/snake/niri-git/src/niri/.git/lfs/logs/20240411T024702.031076121.log'.
Use `git lfs logs last` to view the log.
error: external filter 'git-lfs filter-process' failed
fatal: wiki/img/block-out-from-screencast.png: smudge filter lfs failed
warning: Clone succeeded, but checkout failed.
You can inspect what was checked out with 'git status'
and retry with 'git restore --source=HEAD :/'
==> ERROR: Failure while creating working copy of niri git repo
Aborting...
This happens because makepkg makes a bare clone of the source repository first, and then clones the local bare repository into the working copy. When the source repository contains LFS files, the second clone triggers the LFS Smudge filter which attempts to pull the large files from the local bare repository, which does not have them.
This issue can be reproduced using just Git with the following sequence of commands:
$ git clone https://github.com/YaLTeR/niri niri-bare --bare
Cloning into bare repository 'niri-bare'...
remote: Enumerating objects: 5776, done.
remote: Counting objects: 100% (2469/2469), done.
remote: Compressing objects: 100% (640/640), done.
remote: Total 5776 (delta 1930), reused 2220 (delta 1791), pack-reused 3307
Receiving objects: 100% (5776/5776), 1.66 MiB | 5.71 MiB/s, done.
Resolving deltas: 100% (4075/4075), done.
$ git clone niri-bare niri
Cloning into 'niri'...
done.
Downloading wiki/img/block-out-from-screencast.png (432 KB)
Error downloading object: wiki/img/block-out-from-screencast.png (65b22b8): Smudge error: Error downloading wiki/img/block-out-from-screencast.png (65b22b833dc0b05166b4b3403b1c6323315ca0885d4a75d2bbb68250a3855e96): error transferring "65b22b833dc0b05166b4b3403b1c6323315ca0885d4a75d2bbb68250a3855e96": [0] remote missing object 65b22b833dc0b05166b4b3403b1c6323315ca0885d4a75d2bbb68250a3855e96
Errors logged to '/tmp/snake/niri/.git/lfs/logs/20240411T025823.516562612.log'.
Use `git lfs logs last` to view the log.
error: external filter 'git-lfs filter-process' failed
fatal: wiki/img/block-out-from-screencast.png: smudge filter lfs failed
warning: Clone succeeded, but checkout failed.
You can inspect what was checked out with 'git status'
and retry with 'git restore --source=HEAD :/'
The workaround is to fetch the LFS files into the bare repository before cloning it.
$ git -C niri-bare lfs fetch
fetch: Fetching reference refs/heads/main
$ git clone niri-bare niri
Cloning into 'niri'...
done.