#StackBounty: #git #powershell #tfs #git-lfs #git-ls-files Is comparing git lfs ls-files with git ls-files ':(attr:filter=lfs)'…

Bounty: 150

I try to find a way to determine whether the files in git repository are correctly managed by git-lfs.

So far, I have found that comparing results from git lfs ls-files and git ls-files ':(attr:filter=lfs)' seems to give me what I want.

Add-Type -AssemblyName 'System.Linq';
[string[]] $actualLfsFilePaths = git lfs ls-files | `
    ForEach-Object `
        #'12345678 * my.dll' - not all lfs versions support -n flag, so it is better to be conservative
        $_.Split(' ', 3)[2]
[string[]] $shouldBeUnderLfsFilePaths = git ls-files ':(attr:filter=lfs)';
$filePathsNotUnderLfs = [System.Linq.Enumerable]::ToArray(
    [System.Linq.Enumerable]::Except($shouldBeUnderLfsFilePaths, $actualLfsFilePaths)
$count = $filePathsNotUnderLfs.Count;
Write-Host "There are $($count) lfs files that are not under lfs";
foreach ($filePathNotUnderLfs in $filePathsNotUnderLfs)
    Write-Host "`t'$filePathNotUnderLfs'";
if ($count -gt 0)
    Write-Error "There are $count lfs files that are not under lfs";
    return 1;
return 0;

Still I am not sure that is a reliable way. So, is it a reliable/correct way?

P.S.: What I am trying to achieve is to create a pull request validation build(for TFS repository) that will detect lfs violations (files committed without being added to lfs) that often occur for one or another reason and lead to unnecessary warnings and repo bloat at best and major nuisances at worst.

Well, found out that there are some issues with the current code:

  1. empty files handling
  2. octal encoding for non-ASCII chars in ls-files

but they are relatively easily fixed and do not change the gist of the question.

Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.