This commit is contained in:
2025-05-18 10:58:49 +03:00
parent 761b9e031e
commit cb664b2115
5 changed files with 16 additions and 24 deletions

View File

@@ -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'

View File

@@ -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()}")
}
}

View File

@@ -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')
}

View File

@@ -112,7 +112,6 @@ pub mut:
build_dest []string @[json: 'buildDest']
build_dest_dev []string @[json: 'buildDestDev']
copyright string = 'someone'
to_import []MyImport @[json: 'import']
}
// Footer config structures
@@ -143,13 +142,6 @@ pub mut:
title string = 'Docusaurus'
}
pub struct MyImport {
pub mut:
url string
dest string
visible bool
replace map[string]string
}
// Navbar config structures
pub struct NavbarItem {
@@ -187,6 +179,7 @@ pub mut:
path string
dest string // location in the docs folder of the place where we will build docusaurus
replace map[string]string // will replace ${NAME} in the imported content
visible bool
}
// Export config as JSON files (main.json, navbar.json, footer.json)

View File

@@ -173,7 +173,7 @@ pub fn (mut site DocSite) generate() ! {
mut gs := gittools.new()!
for item in site.config.main.to_import {
for item in site.config.import_sources {
mypath := gs.get_path(
pull: false
reset: false
@@ -184,7 +184,7 @@ pub fn (mut site DocSite) generate() ! {
}
}
fn (mut site DocSite) process_md(mut path pathlib.Path, args MyImport) ! {
fn (mut site DocSite) process_md(mut path pathlib.Path, args ImportSource) ! {
if path.is_dir() {
mut pathlist_images := path.list(
regex: [r'.*\.png$', r'.*\.jpg$', r'.*\.svg$', r'.*\.jpeg$']