friendlyanon / cmake-init

The missing CMake project initializer
GNU General Public License v3.0
1.98k stars 75 forks source link

Update git version search for Apple Git #45

Closed nreinicke closed 2 years ago

nreinicke commented 2 years ago

When running cmake-init on macOS Catalina with Apple Git installed, the following error is raised:

ValueError: invalid literal for int() with base 10: '1 (Apple Git-122'.

Running git --version yields: git version 2.21.1 (Apple Git-122.3)

This PR updates the determine_git_version() method to use regex to match the first valid version string from the output of git --version.

Testing this on various possible strings:

strings = [
    "git version 2.21.1 (Apple Git-122.3)",
    "git version 2.21.1.windows.0",
    "git version 2.21.1",
    "git version 2.21",
    "git version 0",
]

yields:

(2, 21, 1)
(2, 21, 1)
(2, 21, 1)
(2, 21, 0)
None
friendlyanon commented 2 years ago

Thanks! Added via 9d4cea6baade934f63842e97f451514737ee606f, I just edited the commit message a bit.