Skip to content
This repository has been archived by the owner on Dec 30, 2024. It is now read-only.

Commit

Permalink
Merge branch 'development_gittools3' into development
Browse files Browse the repository at this point in the history
* development_gittools3: (22 commits)
  feat: Set ssh-key on the repo
  fix tests, readme
  fix: Fix Add/Has changes, commit tests
  fix: Fix branch and tag tests
  fix: Fix clone tests
  fix: Fix do script
  fix: Set the GitStructure cache on the repo loaded from redis
  fix: Fix some bugs
  ...
  ...
  ...
  feat: Remove reload_if_needed method
  broke it probably
  Update the test cases:
  fix: Update the usage of the gittools module
  wip: Refactor the load method
  wip: Working on refactoring the module
  Merge development
  docs: Updated the README file.
  WIP: Wrote some test cases.
  ...

# Conflicts:
#	crystallib/data/doctree/tree_scanner.v
#	crystallib/develop/gittools/gitstructure.v
  • Loading branch information
despiegk committed Oct 29, 2024
2 parents 75afa79 + 95b9dfe commit e5e6eb6
Show file tree
Hide file tree
Showing 69 changed files with 1,987 additions and 2,198 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub fn build(args BuildArgs) ! {

// mut gs := gittools.get()!

// mut gitpath := gittools.code_get(
// mut gitpath := gittools.get_repo(
// url: "https://github.com/xxxx/yyy"
// pull: true
// reset: true
Expand Down
2 changes: 1 addition & 1 deletion cookbook/podman/test.vsh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ c.rust_install()!
c.v_install()!
c.node_install()!

c.code_get(reset:true, url:...)! //see gitstructure path = gs.code_get(reset: reset, pull: pull, url: url)! use herscript underneith to do it
c.get_repo(reset:true, url:...)! //see gitstructure path = gs.get_repo(reset: reset, pull: pull, url: url)! use herscript underneith to do it

c.add(...) //add content

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ fn build() ! {

// console.print_header('build ${args.name}')

// gitpath := gittools.code_get(coderoot: '/tmp/builder', url: url, reset: true, pull: true)!
// gitpath := gittools.get_repo(coderoot: '/tmp/builder', url: url, reset: true, pull: true)!

// cmd := '
// cd ??{gitpath}
Expand Down
3 changes: 2 additions & 1 deletion crystallib/core/herocmds/juggler.v
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,13 @@ fn juggler_code_get(cmd Command) !string {

mut gs := gittools.get(coderoot: coderoot)!
if url.len > 0 {
path = gs.code_get(
mut repo := gs.get_repo(
pull: pull
reset: reset
url: url
reload: true
)!
return repo.get_path()!
}

return path
Expand Down
7 changes: 5 additions & 2 deletions crystallib/core/herocmds/playbook_lib.v
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,14 @@ pub fn plbook_code_get(cmd Command) !string {

mut gs := gittools.get(coderoot: coderoot)!
if url.len > 0 {
path = gs.code_get(
mut repo := gs.get_repo(
pull: pull
reset: reset
url: url
reload: true
)!

path = repo.get_path()!
}

return path
Expand Down Expand Up @@ -174,7 +176,8 @@ fn plbook_edit_sourcetree(cmd Command) !(&playbook.PlayBook, string) {
// repo.sourcetree()!
sourcetree.open(path: path)!
} else if edit {
vscode.open(path: path)!
mut vscode_ := vscode.new(path)
vscode_.open()!
}

return plbook, path
Expand Down
4 changes: 2 additions & 2 deletions crystallib/core/playbook/playbook_add.v
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ pub fn (mut plbook PlayBook) add(args_ PlayBookNewArgs) ! {

if args.git_url.len > 0 {
mut gs := gittools.get()!
args.path = gs.code_get(
mut repo := gs.get_repo(
url: args.git_url
branch: args.git_branch
pull: args.git_pull
reset: args.git_reset
)!
args.path = repo.get_path()!
}

// walk over directory
Expand Down
103 changes: 103 additions & 0 deletions crystallib/data/doctree/tree_scanner.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
module doctree

import freeflowuniverse.crystallib.core.pathlib
import freeflowuniverse.crystallib.data.paramsparser
import freeflowuniverse.crystallib.develop.gittools
import os

@[params]
pub struct TreeScannerArgs {
pub mut:
path string
heal bool = true // healing means we fix images
git_url string
git_reset bool
git_root string
git_pull bool
load bool = true // means we scan automatically the added collection
}

// walk over directory find dirs with .book or .collection inside and add to the tree .
// a path will not be added unless .collection is in the path of a collection dir or .book in a book
// ```
// path string
// heal bool // healing means we fix images, if selected will automatically load, remove stale links
// git_url string
// git_reset bool
// git_root string
// git_pull bool
// ```
pub fn (mut tree Tree) scan(args_ TreeScannerArgs) ! {
// $if debug{console.print_debug(" - collections find recursive: $path.path")}
mut args := args_
if args.git_url.len > 0 {
mut gs := gittools.get(coderoot: args.git_root)!
mut repo := gs.get_repo(
url: args.git_url
pull: args.git_pull
reset: args.git_reset
reload: false
)!
args.path = repo.get_path()!
}

if args.path.len < 3 {
return error('Path needs to be not empty.')
}
mut path := pathlib.get_dir(path: args.path)!
if path.is_dir() {
mut name := path.name()
if path.file_exists('.site') {
// mv .site file to .collection file
collectionfilepath1 := path.extend_file('.site')!
collectionfilepath2 := path.extend_file('.collection')!
os.mv(collectionfilepath1.path, collectionfilepath2.path)!
}
if path.file_exists('.collection') {
mut filepath := path.file_get('.collection')!

// now we found a collection we need to add
content := filepath.read()!
if content.trim_space() != '' {
// means there are params in there
mut params_ := paramsparser.parse(content)!
if params_.exists('name') {
name = params_.get('name')!
}
}
// console.print_debug('new collection: ${path.path} name:${name}')
tree.collection_new(
path: path.path
name: name
heal: args.heal
load: true
)!
}

mut pl := path.list(recursive: false) or {
return error('cannot list: ${path.path} \n${error}')
}

for mut p_in in pl.paths {
if p_in.is_dir() {
if p_in.name().starts_with('.') || p_in.name().starts_with('_') {
continue
}

tree.scan(path: p_in.path, heal: args.heal, load: args.load) or {
msg := 'Cannot process recursive on ${p_in.path}\n${err}'
return error(msg)
}
}
}
}
// if args.heal {
// tree.heal()!
// }
}

// pub fn (mut tree Tree) heal() ! {
// for _, mut collection in tree.collections {
// collection.fix()!
// }
// }
62 changes: 62 additions & 0 deletions crystallib/develop/gittools/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Git Repository Management with Gittools

This project demonstrates the use of the `gittools` and `osal` modules from the `freeflowuniverse/crystallib` library to automate basic Git operations such as cloning a repository, creating branches, committing changes, and pushing them to a remote repository.

Features:

- Cloning or retrieving an existing repository.
- Creating and checking out new branches.
- Detecting file changes, adding them to staging, and committing.
- Pushing changes to a remote repository.
- Pulling changes from a remote repository.

### Example Workflow

The following example workflow is included in the script:

```v
// Initializes the Git structure.
import freeflowuniverse.crystallib.develop.gittools
coderoot := '~/code'
mut gs_default := gittools.new(coderoot: coderoot)!
// Retrieve the repository if exists.
mut repo := gs_default.get_repo(name: 'repo3')!
// in case the repo is a new repo and you want to clone it
mut repo := gs_default.get_repo(url: '<repo_url>')!
// Create a new branch and a V file.
branch_name := "testing_branch"
tag_name := "testing_tag"
file_name := "hello_world.v"
// Create a new branch, checkout, add changes, commit, and push.
repo.branch_create(branch_name)!
repo.branch_switch(branch_name)!
if repo.has_changes() {
repo.commit(msg: "feat: Added ${file_name} file.")!
repo.push()!
}
// Create tag from the base branch
repo.tag_create(tag_name)!
```

## Tests

The project includes several unit tests to ensure that the functionality works correctly.

To run the tests, use the following command in the project root:

```bash
v -enable-globals test crystallib/develop/gittools/tests/
```

This will run all the test cases and provide feedback on whether they pass or fail.

## Notes

- This project is highly dependent on proper configuration of Git in your environment.
- Ensure that SSH keys or access tokens are properly set up for pushing and pulling to/from the remote repository.
127 changes: 0 additions & 127 deletions crystallib/develop/gittools/address.v

This file was deleted.

Loading

0 comments on commit e5e6eb6

Please sign in to comment.