Skip to content

Commit

Permalink
vpm: check for git version before adding --also-filter-submodules flag
Browse files Browse the repository at this point in the history
  • Loading branch information
ttytm committed Apr 11, 2024
1 parent 27cd1b1 commit 7f7b057
Showing 1 changed file with 37 additions and 18 deletions.
55 changes: 37 additions & 18 deletions cmd/tools/vpm/vcs.v
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module main

import os
import semver

// Supported version control system commands.
enum VCS {
Expand All @@ -19,25 +20,43 @@ struct VCSInfo {
}
}

const vcs_info = {
VCS.git: VCSInfo{
dir: '.git'
args: struct {
install: 'clone --depth=1 --recursive --shallow-submodules --filter=blob:none --also-filter-submodules'
version: '--single-branch -b'
update: 'pull --recurse-submodules' // pulling with `--depth=1` leads to conflicts when the upstream has more than 1 new commits.
path: '-C'
outdated: ['fetch', 'rev-parse @', 'rev-parse @{u}']
}
const vcs_info = init_vcs_info() or {
vpm_error(err.msg())
exit(1)
}

fn init_vcs_info() !map[VCS]VCSInfo {
mut git_install_cmd := 'clone --depth=1 --recursive --shallow-submodules --filter=blob:none'
submod_filter_version := semver.from('2.36.0') or { panic(err) }
raw_installed_git_ver := os.execute_opt('git --version') or {
return error('failed to find git')
}.output.all_after_last(' ').trim_space()
installed_git_ver := semver.from(raw_installed_git_ver) or {
return error('failed to parse git version `${raw_installed_git_ver}`')
}
VCS.hg: VCSInfo{
dir: '.hg'
args: struct {
install: 'clone'
version: '--rev'
update: 'pull --update'
path: '-R'
outdated: ['incoming']
if installed_git_ver >= submod_filter_version {
git_install_cmd += ' --also-filter-submodules'
}
return {
VCS.git: VCSInfo{
dir: '.git'
args: struct {
install: git_install_cmd
version: '--single-branch -b'
update: 'pull --recurse-submodules' // pulling with `--depth=1` leads to conflicts when the upstream has more than 1 new commits.
path: '-C'
outdated: ['fetch', 'rev-parse @', 'rev-parse @{u}']
}
}
VCS.hg: VCSInfo{
dir: '.hg'
args: struct {
install: 'clone'
version: '--rev'
update: 'pull --update'
path: '-R'
outdated: ['incoming']
}
}
}
}
Expand Down

0 comments on commit 7f7b057

Please sign in to comment.