Search code examples
c#gitlibgit2libgit2sharpgit-blame

Programmatically do "Git blame -w" in C#


I need to programmatically get the last author of a specific line in the Git history with C#. I tried using libgit2sharp :

var repo = new LibGit2Sharp.Repository(gitRepositoryPath);
string relativePath = MakeRelativeSimple(filename);
var blameHunks = repo.Blame(relativePath);
// next : find the hunk which overlap the desired line number

But this is the equivalent of the command

git blame <file>

And in fact I need

git blame -w <file> (to ignore whitespace when comparing)

Libgit2sharp do not set the -w switch and don't provide any parameter/option to set it. What are my options ? Do you know any other library compatible with the -w switch of the blame command ?


Solution

  • When I hit similar advanced scenarios where the git lib isn't cutting it, I just shell out using start process to the real git command line. It's not sexy, but it's mighty effective.