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

GH-127: Modify do/while in GitFindRootFromPath to avoid infinite loop #128

Merged
merged 2 commits into from Dec 13, 2021

Conversation

kcamp
Copy link
Contributor

@kcamp kcamp commented Nov 22, 2020

This change addresses GH-127 to look at the current iteration of parentDir and provides a graceful termination consistent with the path simply not existing.

Using System.IO.DirectoryInfo seemed to be the most straightforward/deterministic approach here; if there's a preferred approach, please feel free to suggest something different.

@pascalberger pascalberger self-requested a review November 27, 2020 13:27
Copy link
Member

@pascalberger pascalberger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kcamp Thanks for fixing this 👍

Code LGTM. Would it be possible for you to also add a test case testing the reported issue?

@kcamp
Copy link
Contributor Author

kcamp commented Nov 28, 2020

@pascalberger No problem, got those added. Let me know if there's anything else you'd like.

@kcamp
Copy link
Contributor Author

kcamp commented Nov 28, 2020

Looking into the test failures on the latest push. I think it's going to wind up being environmental on the Travis builds.

@kcamp
Copy link
Contributor Author

kcamp commented Nov 28, 2020

@pascalberger I'm at a bit of a loss for how to address this. In the latest Travis OSX job we get the following:

========================================
Git-Find-Root-From-Path-TempDirectory
========================================
Attempting to resolve Git root directory from temp directory '/var/folders/bb/n7t3rs157850byt_jfdcq9k80000gn/T/'...
...
Error: One or more errors occurred.
	Path at '/var/folders/bb/n7t3rs157850byt_jfdcq9k80000gn/T/' should not be a valid Git repository.  Found Git root at '.'.

To me, this seems unexpected (in terms of finding a valid git repository at that path), but I am not familiar with how Travis is configured. The behavior definitely seems to indicate that Repository.IsValid(".") is evaluating true for that path and the loop is being broken gracefully without necessarily invoking the fix applied here.

Does this simply become a matter of scoping this new test to the Local-Tests task chain? I added it to both Default-Tests and Local-Tests for good measure. I patterned it after the Git-IsValidRepository-TempDirectory tests, so if we need to make the new test a bit more deterministic, I can start digging in on that in the next few days.

edit: I changed the scoping of the tests around a bit as a what-if and found that the CI builds are actually running Local-Tests due to how the targets are being passed from the respective runners + evaluated for the tests. So I think what we'd have to do to scope the tests to escape inclusion in CI (short of reworking for determinism) would be to include them in Default-Tests and not Local-Tests.

Ideas or advice on how to proceed? Thanks! 👍

@kcamp kcamp force-pushed the GH-127 branch 2 times, most recently from 7401833 to e88f521 Compare November 28, 2020 16:05
@nils-a
Copy link
Contributor

nils-a commented Jun 5, 2021

@kcamp Thanks for your contribution. As far as I can see, the build fails because the fix you implemented does not work on non-windows systems.

The main problem seems to be the line var parentDir = fsPath.Combine("../").Collapse(); which on non-windows systems produces . as parent for /tmp. (And it will produce C:\ as parent for C:\ - which explains the infinite loop you observed.)

I have put up a solution that could be used to solve this at cake-build/cake#3387 (reply in thread)

Are you in a position to rebase this PR and implement a more general solution?

@kcamp
Copy link
Contributor Author

kcamp commented Jun 6, 2021

@nils-a Yes, I can rework based on what you've commented. Thanks for the feedback 👍

@nils-a
Copy link
Contributor

nils-a commented Dec 12, 2021

@kcamp sorry for being so rude and implementing the changes myself, but I wanted to get this into the next release. (Which should come soonish...)

@devlead
Copy link
Member

devlead commented Dec 12, 2021

@nils-a looks good to me, just need a rebase.

Copy link
Member

@augustoproiete augustoproiete left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Comment on lines 214 to 218
if (context.Environment.Platform.Family == PlatformFamily.Windows) {
// no more parents
return null;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (context.Environment.Platform.Family == PlatformFamily.Windows) {
// no more parents
return null;
}
if (context.Environment.Platform.Family == PlatformFamily.Windows)
{
// no more parents
return null;
}

nitpick / C# brackets police 🛃

src/Cake.Git/GitAliases.Repository.cs Outdated Show resolved Hide resolved
kcamp and others added 2 commits December 13, 2021 08:33
and added a workaround for the hitherto missing DirectoryInfo.GetParent()
@nils-a nils-a dismissed pascalberger’s stale review December 13, 2021 08:34

The requested test was added.

@nils-a nils-a merged commit 85395d9 into cake-contrib:develop Dec 13, 2021
@nils-a
Copy link
Contributor

nils-a commented Dec 13, 2021

@kcamp your changes have been merged, thanks for your contribution 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants