This commit is contained in:
2025-10-13 07:30:12 +04:00
parent 73ff7e5534
commit a056c830d2
5 changed files with 166 additions and 5 deletions

View File

@@ -0,0 +1,2 @@
!!git.check
filter: 'test_repo'

View File

@@ -163,4 +163,74 @@ fn play_git(mut plbook PlayBook) ! {
gs = gittools.new(coderoot: coderoot)!
gs.load(true)! // Force reload
}
// Handle !!git.check
check_actions := plbook.find(filter: 'git.check')!
for action in check_actions {
mut p := action.params
filter_str := p.get_default('filter', '')!
name := p.get_default('name', '')!
account := p.get_default('account', '')!
provider := p.get_default('provider', '')!
error_ignore := p.get_default_false('error_ignore')
mut repos := gs.get_repos(
filter: filter_str
name: name
account: account
provider: provider
)!
if repos.len == 0 {
if !error_ignore {
return error('No repositories found for git.check with filter: ${filter_str}, name: ${name}, account: ${account}, provider: ${provider}')
}
console.print_stderr('No repositories found for git.check. Ignoring due to error_ignore: true.')
continue
}
for mut repo in repos {
repo.lfs_check() or {
if !error_ignore {
return error('LFS check failed for ${repo.name}: ${err}')
}
console.print_stderr('LFS check failed for ${repo.name}: ${err}. Ignoring due to error_ignore: true.')
}
}
}
// Handle !!git.lfs
lfs_actions := plbook.find(filter: 'git.lfs')!
for action in lfs_actions {
mut p := action.params
filter_str := p.get_default('filter', '')!
name := p.get_default('name', '')!
account := p.get_default('account', '')!
provider := p.get_default('provider', '')!
error_ignore := p.get_default_false('error_ignore')
mut repos := gs.get_repos(
filter: filter_str
name: name
account: account
provider: provider
)!
if repos.len == 0 {
if !error_ignore {
return error('No repositories found for git.lfs with filter: ${filter_str}, name: ${name}, account: ${account}, provider: ${provider}')
}
console.print_stderr('No repositories found for git.lfs. Ignoring due to error_ignore: true.')
continue
}
for mut repo in repos {
repo.lfs_init() or {
if !error_ignore {
return error('LFS initialization failed for ${repo.name}: ${err}')
}
console.print_stderr('LFS initialization failed for ${repo.name}: ${err}. Ignoring due to error_ignore: true.')
}
}
}
}

View File

@@ -5,7 +5,7 @@ import incubaid.herolib.core.pathlib
import incubaid.herolib.ui.console
import os
pub const gitcmds = 'clone,commit,pull,push,delete,reload,list,edit,sourcetree,path,exists'
pub const gitcmds = 'clone,commit,pull,push,delete,reload,list,edit,sourcetree,path,exists,check,lfs'
@[params]
pub struct ReposActionsArgs {
@@ -301,6 +301,87 @@ pub fn (mut gs GitStructure) do(args_ ReposActionsArgs) !string {
}
// end for the commit, pull, push, delete
if args.cmd == 'check' {
gs.repos_print(
filter: args.filter
name: args.repo
account: args.account
provider: args.provider
)!
if repos.len == 0 {
console.print_header(' - nothing to check.')
return ''
}
mut ok := false
if args.script {
ok = true
} else {
ok = ui.ask_yesno(question: 'Run check on ${repos.len} repo(s)?')!
}
if !ok {
return error('Check cancelled by user.\n${args}')
}
for mut repo in repos {
console.print_header(' - checking LFS for ${repo.account}/${repo.name}')
repo.lfs_check() or {
console.print_stderr('LFS check failed for ${repo.name}: ${err}')
continue
}
}
return ''
}
if args.cmd == 'lfs' {
gs.repos_print(
filter: args.filter
name: args.repo
account: args.account
provider: args.provider
)!
if repos.len == 0 {
console.print_header(' - nothing to initialize.')
return ''
}
mut ok := false
if args.script {
ok = true
} else {
ok = ui.ask_yesno(
question: 'Initialize LFS for ${repos.len} repo(s)? This will modify repository configuration.'
)!
}
if !ok {
return error('LFS initialization cancelled by user.\n${args}')
}
for mut repo in repos {
console.print_header(' - initializing LFS for ${repo.account}/${repo.name}')
repo.lfs_init() or {
console.print_stderr('LFS initialization failed for ${repo.name}: ${err}')
if !args.script {
continue_anyway := ui.ask_yesno(
question: 'Continue with remaining repositories?'
)!
if !continue_anyway {
return error('LFS initialization stopped by user.')
}
}
continue
}
console.print_green('LFS initialized successfully for ${repo.name}')
}
return ''
}
$if debug {
print_backtrace()
}

View File

@@ -0,0 +1,8 @@
module gittools
pub fn (mut repo GitRepo) check() ! {
repo.init()!
if repo.lfs()! {
repo.lfs_check()!
}
}

View File

@@ -12,7 +12,7 @@ const binary_extensions = ['.pdf', '.docx', '.xlsx', '.pptx', '.zip', '.tar', '.
'.mkv', '.wav', '.exe', '.dll', '.so', '.dylib', '.bin', '.dat', '.iso']
// check if repo has lfs enabled
pub fn (mut repo GitRepo) check() ! {
pub fn (mut repo GitRepo) lfs_check() ! {
repo.init()!
// Get list of all files in the repository
@@ -165,6 +165,9 @@ pub fn (mut repo GitRepo) lfs_init() ! {
console.print_debug('.gitattributes created with LFS tracking rules.')
}
repo.commit('chore: Initialize Git LFS and track binary files')!
repo.push()!
// Step 7: Verify LFS is properly configured
if !repo.lfs()! {
return error('Git LFS initialization failed verification')
@@ -172,9 +175,6 @@ pub fn (mut repo GitRepo) lfs_init() ! {
console.print_green('Git LFS initialized successfully for ${repo.name}')
console.print_header('Next steps:')
console.print_item('1. Review .gitattributes to ensure all desired files are tracked')
console.print_item('2. Run: git add .gitattributes')
console.print_item('3. Commit the changes: git commit -m "chore: Initialize Git LFS"')
}
// Check if repo has lfs enabled