libgit2sharp icon indicating copy to clipboard operation
libgit2sharp copied to clipboard

FileHistory return empty enumerable for deleted files

Open TobiasBreuer opened this issue 7 years ago • 3 comments

Reproduction steps

  1. Create a file and commit
  2. Delete the file and commit
  3. Query the log for that specific file: IEnumerable<LogEntry> logs = repo.Commits.QueryBy(fileName);

Expected behavior

The logs enumerable contains 2 entries (initial commit and delete commit)

Actual behavior

The logs enumerable is empty

Version of LibGit2Sharp (release number or SHA1)

v0.25.2

Operating system(s) tested; .NET runtime tested

Windows 7 .Net Framework 4.7.1

Note that git log will also (by default) not return any results when specifying the file name only:

image

However, when telling git explicitly if a revision or a file is specified, git log will show the expected results:

image

TobiasBreuer avatar Sep 20 '18 06:09 TobiasBreuer

did you managed to solve this? if yes, could you share how?

ainglese avatar Aug 14 '19 00:08 ainglese

Unfortunately not. We only circumvented the issue, as in our case we use a git repository within an application to handle versions of scripts. However, once a script is deleted, the user will not see it anyway - so no need to show the history 😉 Still I would be very interested in a solution to this problem as there are other scenarios where this is definitely required.

TobiasBreuer avatar Aug 14 '19 05:08 TobiasBreuer

I ran into the same issue today. A crude workaround would be to ...

  • query the history without a filter for the path
  • for each Commit do a Diff.Compare against the Commit's Parent
  • Check if there is any TreeEntryChanges in the TreeChanges of the Diff pointing to the file in question and then add the Commit to your history output.

Very crude and probably also very slow with bigger repositories.

pstiefel avatar Oct 26 '21 18:10 pstiefel