This repository has been archived by the owner on Dec 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'development_gittools3' into development
* 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
Showing
69 changed files
with
1,987 additions
and
2,198 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()! | ||
// } | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.