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

pytmc template hits an infinite loop if not in a git repository #325

Open
ZLLentz opened this issue Jan 18, 2024 · 0 comments
Open

pytmc template hits an infinite loop if not in a git repository #325

ZLLentz opened this issue Jan 18, 2024 · 0 comments

Comments

@ZLLentz
Copy link
Member

ZLLentz commented Jan 18, 2024

pytmc template needs some version control information to annotate the st.cmd file.
If this is run in a case where there is no git information, the code as-written hits an infinite loop and runs forever.

This infinite loop happens in find_git_root at

pytmc/pytmc/bin/template.py

Lines 130 to 135 in 2c4f412

def find_git_root(fn: pathlib.Path) -> Optional[pathlib.Path]:
"""Given a file, find the git repository root (if it exists)."""
while fn:
if (fn / ".git").exists():
return fn
fn = fn.parent

This function is a while loop that continually checks the parent directory if it has not yet found a .git directory.
Unfortunately, there is no termination for this loop in the case of no .git directories at all, and also unfortunately, the parent of the root directory in pathlib is the root directory again, so this loop quickly reaches the point where it is repeatedly stat-ing for /.git on the filesystem infinitely.

To resolve, this should either raise an error or have fallback behavior for cases with no git repository information.

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

No branches or pull requests

1 participant