cake-contrib / Cake_Git

Cake AddIn that extends Cake with Git features using LibGit2 and LibGit2Sharp

Home Page:https://cakebuild.net/extensions/cake-git

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

GitFindRootFromPath will loop forever if a valid Git repository can't be found.

kcamp opened this issue · comments

commented

If you call GitFindRootFromPath("./") from a path where no ancestor contains a valid Git repository, the method will loop forever.

Repro
Create a folder where a valid git repository is not accessible - i.e., c:\git\repro and add this cake script.

#addin "nuget:?package=Cake.Git&version=0.22"

Task("Default")
  .Does(() => {
    Information("Finding git root");
    GitFindRootFromPath(MakeAbsolute(new DirectoryPath(".")));
  });

RunTarget("Default");

The task will get caught in the do..while loop and loop forever.

do
{
if (Repository.IsValid(fsPath.FullPath))
return fsPath;
var parentDir = fsPath.Combine("../").Collapse();
if (!context.FileSystem.Exist(parentDir))
throw new RepositoryNotFoundException($"Path '{path}' doesn't point at a valid Git repository or workdir.");
fsPath = parentDir;
}
while (true);

We need to add a termination condition to the loop and allow the exception to be thrown.

Closed in #128