This commit is contained in:
2025-01-23 14:09:20 +01:00
parent f2b9b73528
commit 6637756088
16 changed files with 233 additions and 214 deletions

View File

@@ -18,6 +18,7 @@ pub mut:
config GitRepoConfig // Repository-specific configuration
last_load int // Epoch timestamp of the last load from reality
deploysshkey string // to use with git
has_changes bool
}
// this is the status we want, we need to work towards off
@@ -77,7 +78,7 @@ pub fn (mut repo GitRepo) commit(msg string) ! {
if msg == '' {
return error('Commit message is empty.')
}
repo_path := repo.get_path()!
repo_path := repo.path()
repo.exec('git add . -A') or {
return error('Cannot add to repo: ${repo_path}. Error: ${err}')
}
@@ -121,7 +122,7 @@ pub fn (mut repo GitRepo) pull(args_ PullCheckoutArgs) ! {
}
repo.exec('git pull') or {
return error('Cannot pull repo: ${repo.get_path()!}. Error: ${err}')
return error('Cannot pull repo: ${repo.path()}. Error: ${err}')
}
if args_.submodules {
@@ -139,7 +140,7 @@ pub fn (mut repo GitRepo) checkout() ! {
repo.reset()!
}
if repo.need_commit()! {
return error('Cannot checkout branch due to uncommitted changes in ${repo.get_path()!}.')
return error('Cannot checkout branch due to uncommitted changes in ${repo.path()}.')
}
if repo.status_wanted.tag.len > 0 {
repo.exec('git checkout tags/${repo.status_wanted.tag}')!
@@ -152,14 +153,14 @@ pub fn (mut repo GitRepo) checkout() ! {
// Create a new branch in the repository.
pub fn (mut repo GitRepo) branch_create(branchname string) ! {
repo.exec('git branch -c ${branchname}') or {
return error('Cannot Create branch: ${repo.get_path()!} to ${branchname}\nError: ${err}')
return error('Cannot Create branch: ${repo.path()} to ${branchname}\nError: ${err}')
}
console.print_green('Branch ${branchname} created successfully.')
}
pub fn (mut repo GitRepo) branch_switch(branchname string) ! {
repo.exec('git switch ${branchname}') or {
return error('Cannot switch branch: ${repo.get_path()!} to ${branchname}\nError: ${err}')
return error('Cannot switch branch: ${repo.path()} to ${branchname}\nError: ${err}')
}
console.print_green('Branch ${branchname} switched successfully.')
repo.status_local.branch = branchname
@@ -169,7 +170,7 @@ pub fn (mut repo GitRepo) branch_switch(branchname string) ! {
// Create a new branch in the repository.
pub fn (mut repo GitRepo) tag_create(tagname string) ! {
repo_path := repo.get_path()!
repo_path := repo.path()
repo.exec('git tag ${tagname}') or {
return error('Cannot create tag: ${repo_path}. Error: ${err}')
}
@@ -194,7 +195,7 @@ pub fn (mut repo GitRepo) tag_exists(tag string) !bool {
// Deletes the Git repository
pub fn (mut repo GitRepo) delete() ! {
repo_path := repo.get_path()!
repo_path := repo.path()
repo.cache_delete()!
osal.rm(repo_path)!
repo.load()!
@@ -230,10 +231,7 @@ pub fn (mut gs GitRepo) gitlocation_from_path(path string) !GitLocation {
// Check if repo path exists and validate fields
pub fn (mut repo GitRepo) init() ! {
path_string := repo.get_path()!
if repo.gs.coderoot.path == '' {
return error('Coderoot cannot be empty')
}
path_string := repo.path()
if repo.provider == '' {
return error('Provider cannot be empty')
}
@@ -272,12 +270,12 @@ fn (mut repo GitRepo) set_sshkey(key_name string) ! {
// Removes all changes from the repo; be cautious
pub fn (mut repo GitRepo) remove_changes() ! {
repo.status_update()!
if repo.has_changes()! {
console.print_header('Removing changes in ${repo.get_path()!}')
if repo.has_changes {
console.print_header('Removing changes in ${repo.path()}')
repo.exec('git reset HEAD --hard && git clean -xfd') or {
return error("can't remove changes on repo: ${repo.get_path()!}.\n${err}")
return error("can't remove changes on repo: ${repo.path()}.\n${err}")
// TODO: we can do this fall back later
// console.print_header('Could not remove changes; will re-clone ${repo.get_path()!}')
// console.print_header('Could not remove changes; will re-clone ${repo.path()}')
// mut p := repo.patho()!
// p.delete()! // remove path, this will re-clone the full thing
// repo.load_from_url()!
@@ -294,16 +292,14 @@ pub fn (mut repo GitRepo) reset() ! {
// Update submodules
fn (mut repo GitRepo) update_submodules() ! {
repo.exec('git submodule update --init --recursive') or {
return error('Cannot update submodules for repo: ${repo.get_path()!}. Error: ${err}')
return error('Cannot update submodules for repo: ${repo.path()}. Error: ${err}')
}
}
fn (repo GitRepo) exec(cmd_ string) !string {
repo_path := repo.get_path()!
repo_path := repo.path()
cmd := 'cd ${repo_path} && ${cmd_}'
if repo.gs.config.log {
console.print_green(cmd)
}
//console.print_debug(cmd)
r := os.execute(cmd)
if r.exit_code != 0 {
return error('Repo failed to exec cmd: ${cmd}\n${r.output})')