...
This commit is contained in:
@@ -3,8 +3,6 @@ module gittools
|
||||
import freeflowuniverse.herolib.ui as gui
|
||||
import freeflowuniverse.herolib.core.pathlib
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
import freeflowuniverse.herolib.ui.generic
|
||||
import freeflowuniverse.herolib.core.redisclient
|
||||
import os
|
||||
|
||||
pub const gitcmds = 'clone,commit,pull,push,delete,reload,list,edit,sourcetree,cd'
|
||||
|
||||
@@ -11,7 +11,7 @@ module gittools
|
||||
// - Throws an error if the command execution fails.
|
||||
pub fn (repo GitRepo) get_changes_unstaged() ![]string {
|
||||
unstaged_result := repo.exec('git ls-files --other --modified --exclude-standard') or {
|
||||
return error('Failed to check for unstaged changes: ${err}')
|
||||
return error('Failed to check for unstaged changes: ${repo.path()}\n${err}')
|
||||
}
|
||||
|
||||
// Filter out any empty lines from the result.
|
||||
@@ -27,7 +27,7 @@ pub fn (repo GitRepo) get_changes_unstaged() ![]string {
|
||||
// - Throws an error if the command execution fails.
|
||||
pub fn (repo GitRepo) get_changes_staged() ![]string {
|
||||
staged_result := repo.exec('git diff --name-only --staged') or {
|
||||
return error('Failed to check for staged changes: ${err}')
|
||||
return error('Failed to check for staged changes: ${repo.path()}\n${err}')
|
||||
}
|
||||
// Filter out any empty lines from the result.
|
||||
return staged_result.split('\n').filter(it.len > 0)
|
||||
@@ -52,10 +52,10 @@ pub fn (mut repo GitRepo) need_commit() !bool {
|
||||
pub fn (mut repo GitRepo) need_push() !bool {
|
||||
repo.status_update()!
|
||||
last_remote_commit := repo.get_last_remote_commit() or {
|
||||
return error('Failed to get last remote commit: ${err}')
|
||||
return error('Failed to get last remote commit: ${repo.path()}\n${err}')
|
||||
}
|
||||
last_local_commit := repo.get_last_local_commit() or {
|
||||
return error('Failed to get last local commit: ${err}')
|
||||
return error('Failed to get last local commit: ${repo.path()}\n${err}')
|
||||
}
|
||||
// If remote commit is empty, it means the branch doesn't exist remotely yet
|
||||
if last_remote_commit.len == 0 {
|
||||
@@ -69,7 +69,7 @@ pub fn (mut repo GitRepo) need_push() !bool {
|
||||
pub fn (mut repo GitRepo) need_pull() !bool {
|
||||
repo.status_update()!
|
||||
last_remote_commit := repo.get_last_remote_commit() or {
|
||||
return error('Failed to get last remote commit: ${err}')
|
||||
return error('Failed to get last remote commit: ${repo.path()}\n${err}')
|
||||
}
|
||||
// If remote doesn't exist, no need to pull
|
||||
if last_remote_commit.len == 0 {
|
||||
@@ -78,11 +78,11 @@ pub fn (mut repo GitRepo) need_pull() !bool {
|
||||
// Check if the remote commit exists in our local history
|
||||
// If it doesn't exist, we need to pull
|
||||
result := repo.exec('git merge-base --is-ancestor ${last_remote_commit} HEAD') or {
|
||||
if err.msg().contains('exit code: 1') {
|
||||
// Exit code 1 means the remote commit is not in our history
|
||||
// Therefore we need to pull
|
||||
return true
|
||||
}
|
||||
// if err.msg().contains('exit code: 1') {
|
||||
// // Exit code 1 means the remote commit is not in our history
|
||||
// // Therefore we need to pull
|
||||
// return true
|
||||
// }
|
||||
return true
|
||||
// return error('Failed to check merge-base: ${err}')
|
||||
}
|
||||
@@ -116,11 +116,11 @@ fn (mut repo GitRepo) need_checkout() bool {
|
||||
|
||||
fn (mut repo GitRepo) get_remote_default_branchname() !string {
|
||||
if repo.status_remote.ref_default.len == 0 {
|
||||
return error('ref_default cannot be empty for ${repo}')
|
||||
return error('ref_default cannot be empty for ${repo.path()}')
|
||||
}
|
||||
|
||||
return repo.status_remote.branches[repo.status_remote.ref_default] or {
|
||||
return error("can't find ref_default in branches for ${repo}")
|
||||
return error("can't find ref_default in branches for ${repo.path()}")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -56,6 +56,7 @@ fn (mut repo GitRepo) load() ! {
|
||||
|
||||
// Helper to load remote tags
|
||||
fn (mut repo GitRepo) load_branches() ! {
|
||||
println("SDSDSd")
|
||||
tags_result := repo.exec("git for-each-ref --format='%(objectname) %(refname:short)' refs/heads refs/remotes/origin") or {
|
||||
return error('Failed to get branch references: ${err}. Command: git for-each-ref')
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user