This commit is contained in:
2025-04-04 21:51:31 +02:00
parent 5b006ff328
commit 9f33c94020
19 changed files with 1221 additions and 88 deletions

113
src/docs/rhai/git.md Normal file
View File

@@ -0,0 +1,113 @@
# Git Module for Rhai
This module provides Rhai wrappers for the Git functionality in SAL.
## Basic Git Operations
### Clone a Repository
```rhai
// Clone a repository to a standardized location in the user's home directory
let repo_path = git_clone("https://github.com/username/repo.git");
print(`Repository cloned to: ${repo_path}`);
```
### List Repositories
```rhai
// List all git repositories in the user's ~/code directory
let repos = git_list();
print("Found repositories:");
for repo in repos {
print(` - ${repo}`);
}
```
### Find Repositories
```rhai
// Find repositories matching a pattern
// Use a wildcard (*) suffix to find multiple matches
let matching_repos = find_matching_repos("my-project*");
print("Matching repositories:");
for repo in matching_repos {
print(` - ${repo}`);
}
// Find a specific repository (must match exactly one)
let specific_repo = find_matching_repos("unique-project")[0];
print(`Found specific repository: ${specific_repo}`);
```
### Check for Changes
```rhai
// Check if a repository has uncommitted changes
let repo_path = "/path/to/repo";
if git_has_changes(repo_path) {
print("Repository has uncommitted changes");
} else {
print("Repository is clean");
}
```
## Repository Updates
### Update a Repository
```rhai
// Update a repository by pulling the latest changes
// This will fail if there are uncommitted changes
let result = git_update("my-project");
print(result);
```
### Force Update a Repository
```rhai
// Force update a repository by discarding local changes and pulling the latest changes
let result = git_update_force("my-project");
print(result);
```
### Commit and Update
```rhai
// Commit changes in a repository and then update it by pulling the latest changes
let result = git_update_commit("my-project", "Fix bug in login form");
print(result);
```
### Commit and Push
```rhai
// Commit changes in a repository and push them to the remote
let result = git_update_commit_push("my-project", "Add new feature");
print(result);
```
## Complete Example
```rhai
// Clone a repository
let repo_url = "https://github.com/username/example-repo.git";
let repo_path = git_clone(repo_url);
print(`Cloned repository to: ${repo_path}`);
// Make some changes (using OS module functions)
let file_path = `${repo_path}/README.md`;
let content = "# Example Repository\n\nThis is an example repository.";
write_file(file_path, content);
// Commit and push the changes
let commit_message = "Update README.md";
let result = git_update_commit_push(repo_path, commit_message);
print(result);
// List all repositories
let repos = git_list();
print("All repositories:");
for repo in repos {
print(` - ${repo}`);
}