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

tools: fix vpm on macos, when using the bundled git executable #21292

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion cmd/tools/vpm/vcs.v
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const vcs_info = init_vcs_info() or {
}

fn init_vcs_info() !map[VCS]VCSInfo {
git_installed_raw_ver := os.execute_opt('git --version')!.output.all_after_last(' ').all_before('.windows').trim_space()
git_installed_raw_ver := parse_git_version(os.execute_opt('git --version')!.output) or { '' }
git_installed_ver := semver.from(git_installed_raw_ver)!
git_submod_filter_ver := semver.from('2.36.0')!
mut git_install_cmd := 'clone --depth=1 --recursive --shallow-submodules --filter=blob:none'
Expand Down Expand Up @@ -89,3 +89,17 @@ fn vcs_from_str(str string) ?VCS {
else { none }
}
}

// parse_git_version retrieves only the stable version part of the output of `git version`.
// For example: parse_git_version('git version 2.39.3')! will return just '2.39.3'.
pub fn parse_git_version(version string) !string {
git_version_start := 'git version '
// The output from `git version` varies, depending on how git was compiled. Here are some examples:
// `git version 2.44.0` when compiled from source, or from brew on macos.
// `git version 2.39.3 (Apple Git-146)` on macos with XCode's cli tools.
// `git version 2.44.0.windows.1` on windows's Git Bash shell.
if !version.starts_with(git_version_start) {
return error('should start with `${git_version_start}`')
}
return version.all_after(git_version_start).all_before(' ').all_before('.windows').trim_space()
}
10 changes: 10 additions & 0 deletions cmd/tools/vpm/vcs_test.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module main

fn test_parse_git_version() {
if _ := parse_git_version('abcd') {
assert false
}
assert parse_git_version('git version 2.44.0.windows.1')! == '2.44.0'
assert parse_git_version('git version 2.34.0')! == '2.34.0'
assert parse_git_version('git version 2.39.3 (Apple Git-146)')! == '2.39.3'
}