Repository: spack/spack

Issue:
Tests involving the git version are failing on a mac
### Steps to reproduce

```console
$ spack unit-test --showlocals -v lib/spack/spack/test/cmd/ci.py
```

### Error message

There are on the order of 40 unit tests that are broken because of this check. For example,

```
$ spack unit-test --showlocals -v lib/spack/spack/test/cmd/ci.py
ERROR lib/spack/spack/test/cmd/ci.py::test_ci_validate_git_versions_valid[versions0] - AssertionError: assert not {'spack-stage-bsda66q9'}
ERROR lib/spack/spack/test/cmd/ci.py::test_ci_validate_git_versions_valid[versions1] - AssertionError: assert not {'spack-stage-a1a83x5f'}
ERROR lib/spack/spack/test/cmd/ci.py::test_ci_validate_git_versions_bad_tag[versions0] - AssertionError: assert not {'spack-stage-ehpwsrlk'}
ERROR lib/spack/spack/test/cmd/ci.py::test_ci_validate_git_versions_bad_tag[versions1] - AssertionError: assert not {'spack-stage-ki82kk0n'}
ERROR lib/spack/spack/test/cmd/ci.py::test_ci_validate_git_versions_invalid[versions0] - AssertionError: assert not {'spack-stage-aat8qxya'}
ERROR lib/spack/spack/test/cmd/ci.py::test_ci_validate_git_versions_invalid[versions1] - AssertionError: assert not {'spack-stage-gp8l5fkw'}
FAILED lib/spack/spack/test/cmd/ci.py::test_ci_validate_git_versions_valid[versions0] - ValueError: invalid literal for int() with base 10: 'Git-155)'
FAILED lib/spack/spack/test/cmd/ci.py::test_ci_validate_git_versions_valid[versions1] - ValueError: invalid literal for int() with base 10: 'Git-155)'
FAILED lib/spack/spack/test/cmd/ci.py::test_ci_validate_git_versions_bad_tag[versions0] - ValueError: invalid literal for int() with base 10: 'Git-155)'
FAILED lib/spack/spack/test/cmd/ci.py::test_ci_validate_git_versions_bad_tag[versions1] - ValueError: invalid literal for int() with base 10: 'Git-155)'
FAILED lib/spack/spack/test/cmd/ci.py::test_ci_validate_git_versions_invalid[versions0] - ValueError: invalid literal for int() with base 10: 'Git-155)'
FAILED lib/spack/spack/test/cmd/ci.py::test_ci_validate_git_versions_invalid[versions1] - ValueError: invalid literal for int() with base 10: 'Git-155)'

$git --version
git version 2.50.1 (Apple Git-155)
```

### Information on your system

* **Spack:** 1.2.0.dev0 (https://github.com/spack/spack/commit/92ea4117358f84b27ac4ccb60bd2ef57feea40d9)
* **Builtin repo:** git@github.com:tldahlgren/spack-packages/commit/b6fc100e66c121c9f595e77ce451c11f22dca8eb
* **Python:** 3.9.6
* **Platform:** darwin-sequoia-m3

### General information

- [x] I have run `spack debug report` and reported the version of Spack/Python/Platform
- [x] I have searched the issues of this repo and believe this is not a duplicate
- [x] I have run the failing commands in debug mode and reported the output

Discussion:

Fix (patch):
diff --git a/lib/spack/spack/util/git.py b/lib/spack/spack/util/git.py
index 446f79b7c905b7..cd8938d7eb7614 100644
--- a/lib/spack/spack/util/git.py
+++ b/lib/spack/spack/util/git.py
@@ -18,6 +18,9 @@
 # regex for a commit version
 COMMIT_VERSION = re.compile(r"^[a-f0-9]{40}$")
 
+# regex for a git version to extract only the numeric parts
+GIT_VERSION = re.compile(r"(\d+(?:\.\d+)*)")
+
 
 def is_git_commit_sha(string: str) -> bool:
     return len(string) == 40 and bool(COMMIT_VERSION.match(string))
@@ -29,9 +32,9 @@ def _find_git() -> Optional[str]:
     return exe.which_string("git", required=False)
 
 
-def extract_git_version_str(git_exe):
-    v_str = git_exe("--version", output=str).strip().split()[-1].replace("windows.", "")
-    return v_str
+def extract_git_version_str(git_exe: exe.Executable) -> str:
+    match = re.search(GIT_VERSION, git_exe("--version", output=str))
+    return match.group(1) if match else ""
 
 
 class GitExecutable(exe.Executable):


Test changes:
diff --git a/lib/spack/spack/test/util/git.py b/lib/spack/spack/test/util/git.py
index 70a6d5a5307aad..037f4605ec2150 100644
--- a/lib/spack/spack/test/util/git.py
+++ b/lib/spack/spack/test/util/git.py
@@ -84,7 +84,12 @@ def test_pull_checkout_branch(git, tmp_path: pathlib.Path, mock_git_version_info
 
 @pytest.mark.parametrize(
     "input,answer",
-    (["git version 1.7.1", (1, 7, 1)], ["git version 2.34.1.windows.2", (2, 34, 1, 2)]),
+    (
+        ["git version 1.7.1", (1, 7, 1)],
+        ["git version 2.34.1.windows.2", (2, 34, 1)],
+        ["git version 2.50.1 (Apple Git-155)", (2, 50, 1)],
+        ["git version 1.2.3.4.150.abcd10", (1, 2, 3, 4, 150)],
+    ),
 )
 def test_extract_git_version(mock_util_executable, input, answer):
     _, _, registered_responses = mock_util_executable