Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
kcamp opened this issue Nov 22, 2020 · 1 comment
Labels

Comments

@kcamp
Copy link
Contributor

kcamp commented Nov 22, 2020

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.

kcamp added a commit to kcamp/Cake_Git that referenced this issue Nov 22, 2020
@pascalberger pascalberger added this to the 0.23.0 milestone Nov 28, 2020
kcamp added a commit to kcamp/Cake_Git that referenced this issue Nov 28, 2020
kcamp added a commit to kcamp/Cake_Git that referenced this issue Nov 28, 2020
kcamp added a commit to kcamp/Cake_Git that referenced this issue Nov 28, 2020
nils-a pushed a commit to nils-a/Cake_Git that referenced this issue Dec 12, 2021
nils-a added a commit to nils-a/Cake_Git that referenced this issue Dec 12, 2021
and added a workaround for the hitherto missing DirectoryInfo.GetParent()
nils-a pushed a commit to nils-a/Cake_Git that referenced this issue Dec 13, 2021
nils-a added a commit to nils-a/Cake_Git that referenced this issue Dec 13, 2021
and added a workaround for the hitherto missing DirectoryInfo.GetParent()
nils-a added a commit that referenced this issue Dec 13, 2021
GH-127: Modify do/while in GitFindRootFromPath to avoid infinite loop
@nils-a
Copy link
Contributor

nils-a commented Dec 1, 2022

Closed in #128

@nils-a nils-a closed this as completed Dec 1, 2022
@nils-a nils-a removed this from the 1.x.z milestone Dec 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants