pcdshub / pytmc

Generate EPICS IOCs and records from TwinCAT projects - along with many TwinCAT project tools
https://pcdshub.github.io/pytmc/
Other
10 stars 11 forks source link

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

Open ZLLentz opened 7 months ago

ZLLentz commented 7 months ago

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 https://github.com/pcdshub/pytmc/blob/2c4f4121cd109d2d2cee9bdcc357d792ddca01f7/pytmc/bin/template.py#L130-L135

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.