...
This commit is contained in:
@@ -22,7 +22,7 @@ if repos.len() > 0 {
|
||||
|
||||
if repo_array.len() > 0 {
|
||||
let repo = repo_array[0];
|
||||
print("\nRepository path: " + get_repo_path(repo));
|
||||
print("\nRepository path: " + path(repo));
|
||||
|
||||
// Check if the repository has changes
|
||||
let has_changes = has_changes(repo);
|
||||
|
||||
@@ -208,11 +208,7 @@ fn cmd_git_execute(cmd Command) ! {
|
||||
coderoot = os.environ()['CODEROOT']
|
||||
}
|
||||
|
||||
mut gs := gittools.get(coderoot: coderoot)!
|
||||
if coderoot.len > 0 {
|
||||
// is a hack for now
|
||||
gs = gittools.new(coderoot: coderoot)!
|
||||
}
|
||||
mut gs := gittools.new(coderoot: coderoot)!
|
||||
|
||||
// create the filter for doing group actions, or action on 1 repo
|
||||
mut filter := cmd.flags.get_string('filter') or { '' }
|
||||
|
||||
@@ -125,7 +125,7 @@ pub fn plbook_code_get(cmd Command) !string {
|
||||
pull := cmd.flags.get_bool('gitpull') or { false }
|
||||
// interactive := !cmd.flags.get_bool('script') or { false }
|
||||
|
||||
mut gs := gittools.get(coderoot: coderoot)!
|
||||
mut gs := gittools.new(coderoot: coderoot)!
|
||||
if url.len > 0 {
|
||||
mut repo := gs.get_repo(
|
||||
pull: pull
|
||||
|
||||
@@ -48,8 +48,8 @@ play_docusaurus.play(mut plbook)! // <-- new line, optional
|
||||
|
||||
| Problem | What to do |
|
||||
|---|---|
|
||||
| **Wrong API name** – the code uses **`gittools.get(gittools.GitStructureArgGet{})`** – there is no `GitStructureArgGet` struct in the git‑tools package. The correct type is **`gittools.GitStructureArgs`** (or the default `gittools.GitStructure` argument). | Replace `GitStructureArgGet` with the correct type (`gittools.GitStructureArgs`). |
|
||||
| **Missing import alias** – the file uses `gittools.get` and `gittools.new` but the import is just `import freeflowuniverse.herolib.develop.gittools`. That is fine, but for clarity rename the import to **`gittools`** (it already is) and use the same alias everywhere. |
|
||||
| **Wrong API name** – the code uses **`gittools.new(gittools.GitStructureArgGet{})`** – there is no `GitStructureArgGet` struct in the git‑tools package. The correct type is **`gittools.GitStructureArgs`** (or the default `gittools.GitStructure` argument). | Replace `GitStructureArgGet` with the correct type (`gittools.GitStructureArgs`). |
|
||||
| **Missing import alias** – the file uses `gittools.new` and `gittools.new` but the import is just `import freeflowuniverse.herolib.develop.gittools`. That is fine, but for clarity rename the import to **`gittools`** (it already is) and use the same alias everywhere. |
|
||||
| **Potential nil `gs`** – after a `git.clone` we do `gs = gittools.new(coderoot: coderoot)!`. This shadows the previous `gs` and loses the original configuration (e.g. `light`, `log`). The intent is to **re‑initialise** the `GitStructure` **only** when a `coderoot` is explicitly given. Keep the current flow but **document** the intention. |
|
||||
| **Unused variable `action_`** – the variable `action_` is used only for iteration. No problem. |
|
||||
| **Missing `gittools.GitCloneArgs`** – check that the struct is actually named `GitCloneArgs` in the git‑tools package. If not, change to the proper name. | Verify and, if needed, replace with the correct struct name (`gittools.GitCloneArgs`). |
|
||||
@@ -82,7 +82,7 @@ fn play_git(mut plbook PlayBook) ! {
|
||||
// ... (same as before)
|
||||
} else {
|
||||
// Default GitStructure (no args)
|
||||
gittools.get(gittools.GitStructureArgs{})!
|
||||
gittools.new(gittools.GitStructureArgs{})!
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------
|
||||
|
||||
@@ -27,12 +27,13 @@ fn play_core(mut plbook PlayBook) ! {
|
||||
mut playrunpath := action.params.get_default('path', '')!
|
||||
if playrunpath.len == 0 {
|
||||
action.name = 'pull'
|
||||
playrunpath = gittools.get_repo_path(
|
||||
mypath:=gittools.path(
|
||||
path: playrunpath
|
||||
git_url: action.params.get_default('git_url', '')!
|
||||
git_reset: action.params.get_default_false('git_reset')
|
||||
git_pull: action.params.get_default_false('git_pull')
|
||||
)!
|
||||
playrunpath = mypath.path
|
||||
}
|
||||
if playrunpath.len == 0 {
|
||||
return error("can't run a heroscript didn't find url or path.")
|
||||
|
||||
@@ -11,11 +11,11 @@ import freeflowuniverse.herolib.ui.console // For verbose error reporting
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
fn play_git(mut plbook PlayBook) ! {
|
||||
// -----------------------------------------------------------
|
||||
// !!git.define – configure the GitStructure
|
||||
// -----------------------------------------------------------
|
||||
|
||||
mut gs:=gittools.new()!
|
||||
|
||||
define_actions := plbook.find(filter: 'git.define')!
|
||||
mut gs := if define_actions.len > 0 {
|
||||
if define_actions.len > 0 {
|
||||
mut p := define_actions[0].params
|
||||
coderoot := p.get_default('coderoot', '')!
|
||||
light := p.get_default_true('light')
|
||||
@@ -25,18 +25,18 @@ fn play_git(mut plbook PlayBook) ! {
|
||||
ssh_key_path := p.get_default('ssh_key_path', '')!
|
||||
reload := p.get_default_false('reload')
|
||||
|
||||
gittools.new(
|
||||
gs=gittools.new(
|
||||
coderoot: coderoot
|
||||
light: light
|
||||
log: log
|
||||
debug: debug
|
||||
offline: offline
|
||||
ssh_key_path: ssh_key_path
|
||||
reload: reload
|
||||
)!
|
||||
} else {
|
||||
// Default GitStructure (no args)
|
||||
gittools.get()!
|
||||
|
||||
if light || ssh_key_path.len > 0 {
|
||||
gs.config_set(light: light, ssh_key_path: ssh_key_path)!
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------
|
||||
|
||||
@@ -80,7 +80,7 @@ pub fn (mut tree Tree) scan(args TreeScannerArgs) ! {
|
||||
pub fn (mut tree Tree) scan_concurrent(args_ TreeScannerArgs) ! {
|
||||
mut args := args_
|
||||
if args.git_url.len > 0 {
|
||||
mut gs := gittools.get(coderoot: args.git_root)!
|
||||
mut gs := gittools.new(coderoot: args.git_root)!
|
||||
mut repo := gs.get_repo(
|
||||
url: args.git_url
|
||||
pull: args.git_pull
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
module gittools
|
||||
|
||||
import os
|
||||
import json
|
||||
|
||||
import freeflowuniverse.herolib.core.pathlib
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
|
||||
@@ -9,37 +9,6 @@ __global (
|
||||
gsinstances map[string]&GitStructure
|
||||
)
|
||||
|
||||
@[params]
|
||||
pub struct GetRepoArgs {
|
||||
pub mut:
|
||||
path string // if used will check if path exists if yes, just return
|
||||
git_url string
|
||||
git_pull bool
|
||||
git_reset bool
|
||||
git_root string
|
||||
}
|
||||
|
||||
// get_repo_path implements the GitUrlResolver interface
|
||||
pub fn get_repo_path(args GetRepoArgs) !string {
|
||||
if args.path!=""{
|
||||
if os.exists(args.path) {
|
||||
return args.path
|
||||
}else{
|
||||
if args.git_url == "" {
|
||||
return error("can't resolve git repo path without url or existing path, ${args.path} does not exist.")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mut gs := get(coderoot:args.git_root)!
|
||||
mut repo := gs.get_repo(
|
||||
url: args.git_url
|
||||
pull: args.git_pull
|
||||
reset: args.git_reset
|
||||
)!
|
||||
return repo.path()
|
||||
}
|
||||
|
||||
pub fn reset() {
|
||||
gsinstances = map[string]&GitStructure{} // they key is the redis_key (hash of coderoot)
|
||||
}
|
||||
@@ -48,13 +17,10 @@ pub fn reset() {
|
||||
pub struct GitStructureArgsNew {
|
||||
pub mut:
|
||||
coderoot string
|
||||
light bool = true // If true, clones only the last history for all branches (clone with only 1 level deep)
|
||||
log bool = true // If true, logs git commands/statements
|
||||
debug bool = true
|
||||
ssh_key_name string // name of ssh key to be used when loading the gitstructure
|
||||
ssh_key_path string
|
||||
reload bool
|
||||
offline bool = false
|
||||
offline bool
|
||||
}
|
||||
|
||||
// Retrieve or create a new GitStructure instance with the given configuration.
|
||||
@@ -63,38 +29,6 @@ pub fn new(args_ GitStructureArgsNew) !&GitStructure {
|
||||
if args.coderoot == '' {
|
||||
args.coderoot = '${os.home_dir()}/code'
|
||||
}
|
||||
mut cfg := GitStructureConfig{
|
||||
coderoot: args.coderoot
|
||||
light: args.light
|
||||
log: args.log
|
||||
debug: args.debug
|
||||
ssh_key_name: args.ssh_key_name
|
||||
ssh_key_path: args.ssh_key_path
|
||||
offline: args.offline
|
||||
}
|
||||
|
||||
return get(coderoot: args.coderoot, reload: args.reload, cfg: cfg)
|
||||
}
|
||||
|
||||
@[params]
|
||||
pub struct GitStructureArgGet {
|
||||
pub mut:
|
||||
coderoot string
|
||||
reload bool
|
||||
cfg ?GitStructureConfig
|
||||
}
|
||||
|
||||
// Retrieve a GitStructure instance based on the given arguments.
|
||||
pub fn get(args_ GitStructureArgGet) !&GitStructure {
|
||||
mut args := args_
|
||||
if args.coderoot == '' {
|
||||
args.coderoot = '${os.home_dir()}/code'
|
||||
}
|
||||
|
||||
// make sure coderoot exists
|
||||
if !os.exists(args.coderoot) {
|
||||
os.mkdir_all(args.coderoot)!
|
||||
}
|
||||
|
||||
rediskey_ := cache_key(args.coderoot)
|
||||
|
||||
@@ -103,7 +37,6 @@ pub fn get(args_ GitStructureArgGet) !&GitStructure {
|
||||
mut gs := gsinstances[rediskey_] or {
|
||||
panic('Unexpected error: key not found in gsinstances')
|
||||
}
|
||||
gs.load(false)!
|
||||
return gs
|
||||
}else{
|
||||
console.print_header("Loading GitStructure for ${args.coderoot}.")
|
||||
@@ -113,32 +46,27 @@ pub fn get(args_ GitStructureArgGet) !&GitStructure {
|
||||
mut gs := GitStructure{
|
||||
key: rediskey_
|
||||
coderoot: pathlib.get_dir(path: args.coderoot, create: true)!
|
||||
log: args.log
|
||||
debug: args.debug
|
||||
offline: args.offline
|
||||
}
|
||||
|
||||
mut cfg := args.cfg or {
|
||||
mut cfg_ := GitStructureConfig{
|
||||
coderoot: 'SKIP'
|
||||
}
|
||||
cfg_
|
||||
}
|
||||
|
||||
if cfg.coderoot != 'SKIP' {
|
||||
gs.config_ = cfg
|
||||
gs.config_save()!
|
||||
// println(gs.config()!)
|
||||
if 'OFFLINE' in os.environ() {
|
||||
gs.offline = true
|
||||
}
|
||||
|
||||
gs.config()! // will load the config, don't remove
|
||||
|
||||
gs.load(false)!
|
||||
|
||||
if gs.repos.keys().len == 0 || args.reload {
|
||||
gs.load(true)!
|
||||
}else{
|
||||
gs.load(false)!
|
||||
}
|
||||
|
||||
gsinstances[rediskey_] = &gs
|
||||
|
||||
return gsinstances[rediskey_] or { panic('bug') }
|
||||
|
||||
}
|
||||
|
||||
@[params]
|
||||
@@ -161,12 +89,19 @@ pub mut:
|
||||
// git_pull bool
|
||||
pub fn path(args_ GitPathGetArgs) !pathlib.Path {
|
||||
mut args := args_
|
||||
if args.path.trim_space() == '' && args.currentdir {
|
||||
args.path = os.getwd()
|
||||
|
||||
if args.path!=""{
|
||||
if os.exists(args.path) {
|
||||
return pathlib.get(args.path)
|
||||
}else{
|
||||
if args.git_url == "" {
|
||||
return error("can't resolve git repo path without url or existing path, ${args.path} does not exist.")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if args.git_url.len > 0 {
|
||||
mut gs := get(coderoot: args.git_root)!
|
||||
mut gs := new(coderoot: args.git_root)!
|
||||
mut repo := gs.get_repo(
|
||||
url: args.git_url
|
||||
pull: args.git_pull
|
||||
@@ -179,3 +114,4 @@ pub fn path(args_ GitPathGetArgs) !pathlib.Path {
|
||||
}
|
||||
return pathlib.get(args.path)
|
||||
}
|
||||
|
||||
|
||||
@@ -2,21 +2,9 @@ module gittools
|
||||
|
||||
import crypto.md5
|
||||
import freeflowuniverse.herolib.core.pathlib
|
||||
import freeflowuniverse.herolib.core.redisclient
|
||||
import os
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
import json
|
||||
|
||||
pub struct GitStructureConfig {
|
||||
pub mut:
|
||||
coderoot string // just to be informative, its not used
|
||||
light bool = true // If true, clones only the last history for all branches (clone with only 1 level deep)
|
||||
log bool = true // If true, logs git commands/statements
|
||||
debug bool = true
|
||||
ssh_key_name string
|
||||
ssh_key_path string
|
||||
offline bool = false
|
||||
}
|
||||
|
||||
// GitStructure holds information about repositories within a specific code root.
|
||||
// This structure keeps track of loaded repositories, their configurations, and their status.
|
||||
@@ -28,6 +16,9 @@ pub mut:
|
||||
key string // Unique key representing the git structure (default is hash of $home/code).
|
||||
repos map[string]&GitRepo // Map of repositories
|
||||
coderoot pathlib.Path
|
||||
log bool = true // If true, logs git commands/statements
|
||||
debug bool = true
|
||||
offline bool
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -134,8 +125,7 @@ fn (mut gitstructure GitStructure) repo_init_from_path_(path string, params Repo
|
||||
// Initialize and return a GitRepo struct.
|
||||
mut r := GitRepo{
|
||||
gs: &gitstructure
|
||||
status_remote: GitRepoStatusRemote{}
|
||||
status_local: GitRepoStatusLocal{}
|
||||
status: GitStatus{}
|
||||
config: GitRepoConfig{}
|
||||
provider: gl.provider
|
||||
account: gl.account
|
||||
@@ -196,34 +186,3 @@ fn (mut self GitStructure) coderoot() !pathlib.Path {
|
||||
mut coderoot := pathlib.get_dir(path: self.coderoot.path, create: true)!
|
||||
return coderoot
|
||||
}
|
||||
|
||||
////// CONFIG
|
||||
|
||||
// Load config from redis
|
||||
pub fn (mut self GitStructure) config() !GitStructureConfig {
|
||||
mut config := self.config_ or {
|
||||
mut redis := redis_get()
|
||||
data := redis.get('${self.cache_key()}:config')!
|
||||
mut c := GitStructureConfig{}
|
||||
if data.len > 0 {
|
||||
c = json.decode(GitStructureConfig, data)!
|
||||
}
|
||||
c
|
||||
}
|
||||
|
||||
return config
|
||||
}
|
||||
|
||||
// Reset the configuration cache for Git structures.
|
||||
pub fn (mut self GitStructure) config_reset() ! {
|
||||
mut redis := redis_get()
|
||||
redis.del('${self.cache_key()}:config')!
|
||||
}
|
||||
|
||||
// save to the cache
|
||||
pub fn (mut self GitStructure) config_save() ! {
|
||||
// Retrieve the configuration from Redis.
|
||||
mut redis := redis_get()
|
||||
datajson := json.encode(self.config()!)
|
||||
redis.set('${self.cache_key()}:config', datajson)!
|
||||
}
|
||||
|
||||
48
lib/develop/gittools/gitstructure_config.v
Normal file
48
lib/develop/gittools/gitstructure_config.v
Normal file
@@ -0,0 +1,48 @@
|
||||
module gittools
|
||||
|
||||
import json
|
||||
|
||||
|
||||
@[params]
|
||||
pub struct GitStructureConfig {
|
||||
pub mut:
|
||||
light bool = true // If true, clones only the last history for all branches (clone with only 1 level deep)
|
||||
ssh_key_name string
|
||||
ssh_key_path string
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Load config from redis
|
||||
pub fn (mut self GitStructure) config() !GitStructureConfig {
|
||||
mut config := self.config_ or {
|
||||
mut redis := redis_get()
|
||||
data := redis.get('${self.cache_key()}:config')!
|
||||
mut c := GitStructureConfig{}
|
||||
if data.len > 0 {
|
||||
c = json.decode(GitStructureConfig, data)!
|
||||
}
|
||||
c
|
||||
}
|
||||
return config
|
||||
}
|
||||
|
||||
|
||||
pub fn (mut self GitStructure) config_set(args GitStructureConfig) ! {
|
||||
mut redis := redis_get()
|
||||
redis.set('${self.cache_key()}:config', json.encode(args))!
|
||||
}
|
||||
|
||||
// Reset the configuration cache for Git structures.
|
||||
fn (mut self GitStructure) config_reset() ! {
|
||||
mut redis := redis_get()
|
||||
redis.del('${self.cache_key()}:config')!
|
||||
}
|
||||
|
||||
// save to the cache
|
||||
fn (mut self GitStructure) config_save() ! {
|
||||
// Retrieve the configuration from Redis.
|
||||
mut redis := redis_get()
|
||||
datajson := json.encode(self.config()!)
|
||||
redis.set('${self.cache_key()}:config', datajson)!
|
||||
}
|
||||
@@ -45,6 +45,8 @@ pub fn (mut gs GitStructure) do(args_ ReposActionsArgs) !string {
|
||||
mut args := args_
|
||||
console.print_debug('git do ${args.cmd}')
|
||||
|
||||
$dbg;
|
||||
|
||||
if args.path == '' && args.url == '' && args.repo == '' && args.account == ''
|
||||
&& args.provider == '' && args.filter == '' {
|
||||
args.path = os.getwd()
|
||||
@@ -84,7 +86,7 @@ pub fn (mut gs GitStructure) do(args_ ReposActionsArgs) !string {
|
||||
// NEW: Update status only for the relevant repos.
|
||||
console.print_header('Updating status for selected repos...')
|
||||
for mut repo in repos {
|
||||
repo.status_update(reload: args.reload || args.cmd == 'reload')!
|
||||
repo.status_update(reset: args.reload || args.cmd == 'reload')!
|
||||
}
|
||||
|
||||
if args.cmd == 'list' {
|
||||
|
||||
@@ -7,22 +7,15 @@ fn get_repo_status(gr GitRepo) !string {
|
||||
mut repo := gr
|
||||
mut statuses := []string{}
|
||||
|
||||
if repo.status_local.error.len > 0 {
|
||||
mut err_msg := repo.status_local.error
|
||||
if repo.status.error.len > 0 {
|
||||
mut err_msg := repo.status.error
|
||||
if err_msg.len > 40 {
|
||||
err_msg = err_msg[0..40] + '...'
|
||||
}
|
||||
statuses << 'ERROR (Local): ${err_msg}'
|
||||
}
|
||||
if repo.status_remote.error.len > 0 {
|
||||
mut err_msg := repo.status_remote.error
|
||||
if err_msg.len > 40 {
|
||||
err_msg = err_msg[0..40] + '...'
|
||||
}
|
||||
statuses << 'ERROR (Remote): ${err_msg}'
|
||||
statuses << 'ERROR: ${err_msg}'
|
||||
}
|
||||
|
||||
if repo.has_changes {
|
||||
if repo.status.has_changes {
|
||||
statuses << 'COMMIT'
|
||||
}
|
||||
|
||||
@@ -41,10 +34,10 @@ fn get_repo_status(gr GitRepo) !string {
|
||||
fn format_repo_info(repo GitRepo) ![]string {
|
||||
status := get_repo_status(repo)!
|
||||
|
||||
tag_or_branch := if repo.status_local.tag.len > 0 {
|
||||
'[[${repo.status_local.tag}]]' // Display tag if it exists
|
||||
tag_or_branch := if repo.status.tag.len > 0 {
|
||||
'[[${repo.status.tag}]]' // Display tag if it exists
|
||||
} else {
|
||||
'[${repo.status_local.branch}]' // Otherwise, display branch
|
||||
'[${repo.status.branch}]' // Otherwise, display branch
|
||||
}
|
||||
|
||||
relative_path := repo.get_human_path()!
|
||||
@@ -64,7 +57,7 @@ pub fn (mut gitstructure GitStructure) repos_print(args ReposGetArgs) ! {
|
||||
console.clear()
|
||||
// console.print_lf(1) // Removed to reduce newlines
|
||||
|
||||
header := 'Repositories: ${gitstructure.config()!.coderoot}'
|
||||
header := 'Repositories: ${gitstructure.coderoot}'
|
||||
console.print_header(header)
|
||||
console.print_lf(1) // Keep one newline after header
|
||||
|
||||
|
||||
@@ -4,51 +4,8 @@ module gittools
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
import freeflowuniverse.herolib.osal.core as osal
|
||||
import os
|
||||
import time
|
||||
import freeflowuniverse.herolib.core.pathlib
|
||||
import freeflowuniverse.herolib.develop.vscode
|
||||
import freeflowuniverse.herolib.develop.sourcetree
|
||||
import freeflowuniverse.herolib.osal.sshagent
|
||||
|
||||
// GitStatus holds the unified status information for a repository.
|
||||
// It reflects the CURRENT state, not a desired state.
|
||||
pub struct GitStatus {
|
||||
pub mut:
|
||||
// Combined local & remote state (from fetch)
|
||||
branches map[string]string // All branch names -> commit hash
|
||||
tags map[string]string // All tag names -> commit hash
|
||||
|
||||
// Current local state
|
||||
branch string // The current checked-out branch.
|
||||
tag string // The current checked-out tag (if any).
|
||||
ahead int // Commits ahead of remote.
|
||||
behind int // Commits behind remote.
|
||||
|
||||
// Combined status
|
||||
has_changes bool // True if there are uncommitted local changes.
|
||||
error string // Error message if any status update fails.
|
||||
}
|
||||
|
||||
pub struct GitRepoConfig {
|
||||
pub mut:
|
||||
remote_check_period int = 300 // seconds, 5 min
|
||||
}
|
||||
|
||||
// GitRepo represents a single git repository.
|
||||
@[heap]
|
||||
pub struct GitRepo {
|
||||
// a git repo is always part of a git structure
|
||||
mut:
|
||||
gs &GitStructure
|
||||
last_load int // epoch when last loaded
|
||||
pub mut:
|
||||
provider string // e.g., github.com
|
||||
account string // Git account name
|
||||
name string // Repository name
|
||||
deploysshkey string // SSH key for git operations
|
||||
config GitRepoConfig
|
||||
status GitStatus
|
||||
}
|
||||
|
||||
// commit stages all changes and commits them with the provided message.
|
||||
pub fn (mut repo GitRepo) commit(msg string) ! {
|
||||
|
||||
@@ -13,7 +13,7 @@ pub fn (mut repo GitRepo) status_update(args StatusUpdateArgs) ! {
|
||||
repo.init()!
|
||||
|
||||
// Skip remote checks if offline.
|
||||
if 'OFFLINE' in os.environ() || (repo.gs.config()!.offline) {
|
||||
if repo.gs.offline {
|
||||
console.print_debug('status update skipped (offline) for ${repo.path()}')
|
||||
return
|
||||
}
|
||||
@@ -79,7 +79,7 @@ fn (mut repo GitRepo) load_internal() ! {
|
||||
// Persist the newly loaded state to the cache.
|
||||
repo.cache_set()!
|
||||
|
||||
println(repo)
|
||||
// println(repo)
|
||||
|
||||
$dbg;
|
||||
}
|
||||
|
||||
@@ -1,69 +1,58 @@
|
||||
module gittools
|
||||
|
||||
// GitRepo holds information about a single Git repository.
|
||||
|
||||
// GitRepo represents a single git repository.
|
||||
@[heap]
|
||||
pub struct GitRepo {
|
||||
// a git repo is always part of a git structure
|
||||
mut:
|
||||
gs &GitStructure
|
||||
last_load int // epoch when last loaded
|
||||
pub mut:
|
||||
gs &GitStructure @[skip; str: skip] // Reference to the parent GitStructure
|
||||
provider string // e.g., github.com, shortened to 'github'
|
||||
provider string // e.g., github.com
|
||||
account string // Git account name
|
||||
name string // Repository name
|
||||
status_remote GitRepoStatusRemote // Remote repository status
|
||||
status_local GitRepoStatusLocal // Local repository status
|
||||
status_wanted GitRepoStatusWanted // what is the status we want?
|
||||
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
|
||||
deploysshkey string // SSH key for git operations
|
||||
config GitRepoConfig
|
||||
status GitStatus
|
||||
}
|
||||
|
||||
// this is the status we want, we need to work towards off
|
||||
pub struct GitRepoStatusWanted {
|
||||
// GitStatus holds the unified status information for a repository.
|
||||
// It reflects the CURRENT state, not a desired state.
|
||||
pub struct GitStatus {
|
||||
pub mut:
|
||||
branch string
|
||||
tag string
|
||||
url string // Remote repository URL, is basically the one we want
|
||||
readonly bool // if read only then we cannot push or commit, all changes will be reset when doing pull
|
||||
// Combined local & remote state (from fetch)
|
||||
branches map[string]string // All branch names -> commit hash
|
||||
tags map[string]string // All tag names -> commit hash
|
||||
|
||||
// Current local state
|
||||
branch string // The current checked-out branch.
|
||||
tag string // The current checked-out tag (if any).
|
||||
ahead int // Commits ahead of remote.
|
||||
behind int // Commits behind remote.
|
||||
|
||||
// Combined status
|
||||
has_changes bool // True if there are uncommitted local changes.
|
||||
error string // Error message if any status update fails.
|
||||
}
|
||||
|
||||
// GitRepoStatusRemote holds remote status information for a repository.
|
||||
pub struct GitRepoStatusRemote {
|
||||
pub mut:
|
||||
ref_default string // is the default branch hash
|
||||
branches map[string]string // Branch name -> commit hash
|
||||
tags map[string]string // Tag name -> commit hash
|
||||
error string // Error message if remote status update fails
|
||||
}
|
||||
|
||||
// GitRepoStatusLocal holds local status information for a repository.
|
||||
pub struct GitRepoStatusLocal {
|
||||
pub mut:
|
||||
branches map[string]string // Branch name -> commit hash
|
||||
branch string // the current branch
|
||||
tag string // If the local branch is not set, the tag may be set
|
||||
ahead int // Commits ahead of remote
|
||||
behind int // Commits behind remote
|
||||
error string // Error message if local status update fails
|
||||
}
|
||||
|
||||
// GitRepoConfig holds repository-specific configuration options.
|
||||
pub struct GitRepoConfig {
|
||||
pub mut:
|
||||
remote_check_period int = 3600 * 24 * 7 // Seconds to wait between remote checks (0 = check every time), default 7 days
|
||||
remote_check_period int = 300 // seconds, 5 min
|
||||
}
|
||||
|
||||
// just some initialization mechanism
|
||||
fn (mut gitstructure GitStructure) repo_new_from_gitlocation(git_location GitLocation) !&GitRepo {
|
||||
mut repo := GitRepo{
|
||||
provider: git_location.provider
|
||||
name: git_location.name
|
||||
account: git_location.account
|
||||
gs: &gitstructure
|
||||
status_remote: GitRepoStatusRemote{}
|
||||
status_local: GitRepoStatusLocal{}
|
||||
status_wanted: GitRepoStatusWanted{}
|
||||
}
|
||||
gitstructure.repos[repo.cache_key()] = &repo
|
||||
// // just some initialization mechanism
|
||||
// fn (mut gitstructure GitStructure) repo_new_from_gitlocation(git_location GitLocation) !&GitRepo {
|
||||
// mut repo := GitRepo{
|
||||
// provider: git_location.provider
|
||||
// name: git_location.name
|
||||
// account: git_location.account
|
||||
// gs: &gitstructure
|
||||
// status_remote: GitRepoStatusRemote{}
|
||||
// status_local: GitRepoStatusLocal{}
|
||||
// status_wanted: GitRepoStatusWanted{}
|
||||
// }
|
||||
// gitstructure.repos[repo.cache_key()] = &repo
|
||||
|
||||
return &repo
|
||||
}
|
||||
// return &repo
|
||||
// }
|
||||
|
||||
@@ -591,7 +591,7 @@ module playcmds
|
||||
// }
|
||||
|
||||
// // if action.name == 'get' {
|
||||
// // mut gs := gittools.get()!
|
||||
// // mut gs := gittools.new()!
|
||||
// // url := action.params.get('url')!
|
||||
// // branch := action.params.get_default('branch', '')!
|
||||
// // reset := action.params.get_default_false('reset')!
|
||||
@@ -1493,7 +1493,7 @@ fn play_core(mut plbook PlayBook) ! {
|
||||
mut playrunpath := action.params.get_default('path', '')!
|
||||
if playrunpath.len == 0 {
|
||||
action.name = 'pull'
|
||||
playrunpath = gittools.get_repo_path(
|
||||
playrunpath = gittools.path(
|
||||
path: action.params.get_default('path', '')!
|
||||
git_url: action.params.get_default('git_url', '')!
|
||||
git_reset: action.params.get_default_false('git_reset')
|
||||
|
||||
@@ -7,7 +7,7 @@ import os
|
||||
|
||||
pub fn configure() ! {
|
||||
mut args := get()!
|
||||
mut gs := gittools.get()!
|
||||
mut gs := gittools.new()!
|
||||
mut repo_path := ''
|
||||
|
||||
set_global_dns()
|
||||
|
||||
@@ -101,7 +101,7 @@ fn build() ! {
|
||||
// install zinit if it was already done will return true
|
||||
console.print_header('build zinit')
|
||||
|
||||
mut gs := gittools.get(coderoot: '/tmp/builder')!
|
||||
mut gs := gittools.new(coderoot: '/tmp/builder')!
|
||||
mut repo := gs.get_repo(
|
||||
url: 'https://github.com/threefoldtech/zinit'
|
||||
reset: true
|
||||
|
||||
@@ -29,7 +29,7 @@ pub fn install(args InstallArgs) ! {
|
||||
vlang.install(reset: args.reset)!
|
||||
vlang.v_analyzer_install(reset: args.reset)!
|
||||
|
||||
mut gs := gittools.get()!
|
||||
mut gs := gittools.new()!
|
||||
gs.config()!.light = true // means we clone depth 1
|
||||
|
||||
mut repo := gs.get_repo(
|
||||
|
||||
@@ -38,7 +38,7 @@ pub fn install(args_ InstallArgs) ! {
|
||||
|
||||
base.develop()!
|
||||
|
||||
mut gs := gittools.get(coderoot: '${os.home_dir()}/_code')!
|
||||
mut gs := gittools.new(coderoot: '${os.home_dir()}/_code')!
|
||||
mut repo := gs.get_repo(
|
||||
pull: true
|
||||
reset: true
|
||||
|
||||
@@ -41,7 +41,7 @@ Peers:
|
||||
if args.reset {
|
||||
golang.install()!
|
||||
console.print_header('install yggdrasil')
|
||||
mut gs := gittools.get(coderoot: '${os.home_dir()}/_code')!
|
||||
mut gs := gittools.new(coderoot: '${os.home_dir()}/_code')!
|
||||
mut repo := gs.get_repo(
|
||||
url: 'https://github.com/yggdrasil-network/yggdrasil-go.git'
|
||||
reset: false
|
||||
|
||||
@@ -26,7 +26,7 @@ pub fn build_(args BuildArgs) ! {
|
||||
// install restic if it was already done will return true
|
||||
console.print_header('build restic')
|
||||
|
||||
mut gs := gittools.get(coderoot: '/tmp/builder')!
|
||||
mut gs := gittools.new(coderoot: '/tmp/builder')!
|
||||
mut repo := gs.get_repo(
|
||||
url: url
|
||||
reset: true
|
||||
|
||||
@@ -25,7 +25,7 @@ pub fn build_(args BuildArgs) ! {
|
||||
|
||||
osal.package_install('libssl-dev,pkg-config')!
|
||||
|
||||
mut gs := gittools.get()!
|
||||
mut gs := gittools.new()!
|
||||
mut repo := gs.get_repo(
|
||||
url: 'https://github.com/leesmet/s3-cas'
|
||||
reset: false
|
||||
|
||||
@@ -48,7 +48,7 @@ pub fn build_() ! {
|
||||
dest_on_os = '/usr/local/bin'
|
||||
}
|
||||
|
||||
mut gs := gittools.get()!
|
||||
mut gs := gittools.new()!
|
||||
mut repo := gs.get_repo(
|
||||
url: 'https://github.com/threefoldtech/tfgrid-sdk-go'
|
||||
reset: true
|
||||
|
||||
@@ -22,7 +22,7 @@ if repos.len() > 0 {
|
||||
|
||||
if repo_array.len() > 0 {
|
||||
let repo = repo_array[0];
|
||||
print("\nRepository path: " + get_repo_path(repo));
|
||||
print("\nRepository path: " + path(repo));
|
||||
|
||||
// Check if the repository has changes
|
||||
let has_changes = has_changes(repo);
|
||||
|
||||
@@ -18,7 +18,7 @@ pub mut:
|
||||
// checkout a code repository on right location
|
||||
pub fn (mut r DockerBuilderRecipe) add_codeget(args_ CodeGetArgs) ! {
|
||||
mut args := args_
|
||||
mut gs := gittools.get(coderoot: '${r.path()}/code')!
|
||||
mut gs := gittools.new(coderoot: '${r.path()}/code')!
|
||||
mut gr := gs.get_repo(url: args.url, pull: args.pull, reset: args.reset)!
|
||||
|
||||
if args.name == '' {
|
||||
|
||||
@@ -29,7 +29,7 @@ pub fn (mut docsite DocSite) import() ! {
|
||||
}
|
||||
|
||||
// Use gittools to get path of what we want to import
|
||||
import_path := gittools.get_repo_path(
|
||||
mut import_path := gittools.path(
|
||||
git_pull: c.reset
|
||||
git_reset: c.reset
|
||||
git_url: importparams.url
|
||||
@@ -37,13 +37,14 @@ pub fn (mut docsite DocSite) import() ! {
|
||||
path: importparams.path
|
||||
)!
|
||||
|
||||
mut import_patho := pathlib.get(import_path)
|
||||
|
||||
if import_path.path == "" {
|
||||
return error("import path not found for url:${importparams.url} and path:${importparams.path}")
|
||||
}
|
||||
if importparams.dest.starts_with("/") {
|
||||
return error("Import path ${importparams.dest} must be relative, will be relative in relation to the build dir.")
|
||||
}
|
||||
|
||||
import_patho.copy(dest: '${c.path_build.path}/${importparams.dest}', delete: false)!
|
||||
import_path.copy(dest: '${c.path_build.path}/${importparams.dest}', delete: false)!
|
||||
|
||||
// println(importparams)
|
||||
// replace: {'NAME': 'MyName', 'URGENCY': 'red'}
|
||||
|
||||
Reference in New Issue
Block a user