The issue appeared with yay 9.4.3 and still happens with 9.4.4.
When running 'yay -Sc' to clean up packages it prints an error on last step: fatal: not a git repository (or any of the parent directories): .git
$ yay -Sc
Packages to keep:
All locally installed packages
Cache directory: /var/cache/pacman/pkg/
:: Do you want to remove all other packages from cache? [Y/n]
removing old packages from cache...
Database directory: /var/lib/pacman/
:: Do you want to remove unused repositories? [Y/n]
removing unused sync repositories...
Build directory: /home/max/.cache/yay
==> Do you want to remove all other AUR packages from cache? [Y/n]
removing AUR packages from cache...
==> Do you want to remove ALL untracked AUR files? [Y/n]
removing Untracked AUR files from cache...
fatal: not a git repository (or any of the parent directories): .git
Sounds like you have a single package (folder) in the yay cache that is being mishandled.
yay -Sc functionality still works fine. It appears to go in alphabetical order so check the first folder in the yay cache.
[parker@wolfcola build]$ pacman -Q yay
yay-git 9.4.4.r0.g3a5a6a7-1
[parker@wolfcola build]$ yay -Sc
Packages to keep:
All locally installed packages
Cache directory: /var/cache/pacman/pkg/
:: Do you want to remove all other packages from cache? [Y/n]
removing old packages from cache...
Database directory: /var/lib/pacman/
:: Do you want to remove unused repositories? [Y/n]
removing unused sync repositories...
Build directory: /home/parker/.cache/yay
==> Do you want to remove all other AUR packages from cache? [Y/n]
removing AUR packages from cache...
==> Do you want to remove ALL untracked AUR files? [Y/n]
removing Untracked AUR files from cache...
Removing binfmt-qemu-static-20190112-4-any.pkg.tar
Removing ddcci-driver-linux-dkms-0.3.3-1-x86_64.pkg.tar
Removing ddcci-driver-linux-v0.3.3.tar.gz
Removing discord-canary-0.0.98-1-x86_64.pkg.tar.xz
Removing discord-canary-0.0.98.tar.gz
Removing doom1-wad-1.9-2-any.pkg.tar
Removing doom19s.zip
Removing flashpoint-bin-6.3-2.1-x86_64.pkg.tar
Removing flashpoint-linux-x64-20191112.tar.gz
Removing gconf-3.2.6+11+g07808097-6-x86_64.pkg.tar
Removing glmark2-git-r908.24a1139-1-x86_64.pkg.tar
Removing glmark2-git-r910.72dabc5-1-x86_64.pkg.tar
Removing google-chrome-beta-79.0.3945.88-1-x86_64.pkg.tar
Removing google-chrome-beta-80.0.3987.16-1-x86_64.pkg.tar
Removing google-chrome-beta-80.0.3987.42-1-x86_64.pkg.tar
Removing google-chrome-beta-80.0.3987.53-1-x86_64.pkg.tar
Removing google-chrome-beta_79.0.3945.88_amd64.deb
Removing google-chrome-beta_80.0.3987.16_amd64.deb
Removing google-chrome-beta_80.0.3987.42_amd64.deb
Removing google-chrome-beta_80.0.3987.53_amd64.deb
Removing gzdoom-git-4.3pre+668+gf85e3fb9a-1-x86_64.pkg.tar
Removing gzdoom-git-4.3pre+674+ge68b46cb6-1-x86_64.pkg.tar
Removing inxi-git-3.0.37.r0.gc9c56887-1-any.pkg.tar
Removing lutris-git-0.5.4.r105.g146d2c2c-1-any.pkg.tar
Removing lutris-git-0.5.4.r82.g1f1d570d-1-any.pkg.tar
Removing lutris-git-0.5.4.r92.gad819ea0-1-any.pkg.tar
Removing minecraft-launcher-2.1.10835-1-x86_64.pkg.tar
Removing minecraft-launcher-2.1.9618-2-x86_64.pkg.tar
Removing minecraft-launcher.svg
Removing minecraft-launcher_2.1.10835.tar.gz
Removing minecraft-launcher_2.1.9618.tar.gz
Removing odamex-0.8.1-1-x86_64.pkg.tar
Removing odamex-src-0.8.1.tar.gz
Removing powder-toy-94.1-1-x86_64.pkg.tar
Removing powder-toy-94.1-340.tar.gz
Removing qemu-user-static-bin-4.2-1-x86_64.pkg.tar
Removing qemu-user-static_4.2-1_amd64.deb
Removing qstlink2-git-1:1.2.4.r252.cd27f4b-1-x86_64.pkg.tar
Removing radeontop-git-1:1.2.r33.gda9b7c1-1-x86_64.pkg.tar
Removing radeontop-git-1:1.2.r34.gf2d55d6-1-x86_64.pkg.tar
Removing retroarch-git-1.8.2.r4.3ce38ffe91-1-x86_64.pkg.tar
Removing retroarch-git-1.8.2.r99.d88e37a2f1-1-x86_64.pkg.tar
Removing retroarch-git-1.8.3.r32.76c6e01534-1-x86_64.pkg.tar
Removing retroarch-git-1.8.4.r8.fe9022afe0-1-x86_64.pkg.tar
Removing s-tui-git-v0.8.3.r121.gf2f3f5f-1-any.pkg.tar
Removing yay-git-9.4.4.r0.g3a5a6a7-1-x86_64.pkg.tar
No, all folders are proper git directories. Downgrading to yay 9.4.2 works as intended:
$ yay --version
yay v9.4.2 - libalpm v12.0.1
$ yay -Sc
Packages to keep:
All locally installed packages
Cache directory: /var/cache/pacman/pkg/
:: Do you want to remove all other packages from cache? [Y/n]
removing old packages from cache...
Database directory: /var/lib/pacman/
:: Do you want to remove unused repositories? [Y/n]
removing unused sync repositories...
Build directory: /home/max/.cache/yay
==> Do you want to remove all other AUR packages from cache? [Y/n]
removing AUR packages from cache...
==> Do you want to remove ALL untracked AUR files? [Y/n]
removing Untracked AUR files from cache...
Removing yay-bin-9.4.4-1-x86_64.pkg.tar.xz
Removing yay_9.4.4_x86_64.tar.gz
Hmm, that's odd, it seems to be working fine for me as well.
I'm using version 9.4.4 (and I didn't have this problem in version 9.4.3 either).
A bit different output:
> yay -V
yay v9.4.3 - libalpm v12.0.1
> yay -Sc
Packages to keep:
All locally installed packages
Cache directory: /var/cache/pacman/pkg/
:: Do you want to remove all other packages from cache? [Y/n]
removing old packages from cache...
Database directory: /var/lib/pacman/
:: Do you want to remove unused repositories? [Y/n]
removing unused sync repositories...
Build directory: /home/alex/.cache/yay/
==> Do you want to remove all other AUR packages from cache? [Y/n]
removing AUR packages from cache...
==> Do you want to remove ALL untracked AUR files? [Y/n]
removing Untracked AUR files from cache...
fatal: not a git repository (or any parent up to mount point /)
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).
How old is your cache? We've removed tar support now and assume everything in your cache is managed by git. Maybe that's it.
I don't have any tar files in my directory (checked with find ~/.cache/yay/ -type f -name '*.tar*') so old cache is also not the problem I guess.
There would be no tar files. Yay would have downloaded the tar and extracted it there. Check for dirs lacking a .git folder.
Ah, that explains it then. I found one directory without a .git directory, deleted it and now it works.
Most helpful comment
There would be no tar files. Yay would have downloaded the tar and extracted it there. Check for dirs lacking a .git folder.