Git Functions
The Git category provides Git repository operations that mirror the functionality of Git nodes.
Available Functions
Repository Operations
Git.init(path)- Initializes a new Git repositoryGit.clone(url, path, options)- Clones a repository from a URLGit.pull(path, remote, branch)- Pulls changes from remote repository
Staging Operations
Git.addFile(path, filePath)- Adds a single file to stagingGit.addFiles(path, filePaths)- Adds multiple files to stagingGit.addFolder(path, folderPath)- Adds a folder to staging
Commit and Push
Git.commit(path, message, author, email)- Creates a commitGit.push(path, remote, branch)- Pushes commits to remote repository
Submodule Operations
Git.submoduleAdd(path, url, submodulePath)- Adds a submoduleGit.submoduleUpdate(path, submodulePath)- Updates a submoduleGit.submoduleSync(path, submodulePath)- Syncs submodule URLGit.submoduleInit(path, submodulePath)- Initializes a submoduleGit.submoduleDeinit(path, submodulePath)- Deinitializes a submodule
Examples
Repository Setup
-- Initialize repository
local result = Git.init("./my-repo")
if result.Success then
Logger.info("Repository initialized")
end
-- Clone repository
local result = Git.clone("https://github.com/user/repo.git", "./repo", {
Branch = "main",
Depth = 1,
IsBare = false,
CheckoutBranch = true
})
if result.Success then
Logger.info("Cloned to: " .. result.RepositoryPath)
end
Working with Files
-- Add files
Git.addFile("./repo", "file.txt")
Git.addFiles("./repo", {"file1.txt", "file2.txt"})
Git.addFolder("./repo", "src/")
-- Commit
local result = Git.commit("./repo", "Initial commit", "John Doe", "john@example.com")
if result.Success then
Logger.info("Committed: " .. result.CommitHash)
end
-- Push
local result = Git.push("./repo", "origin", "main")
if result.Success then
Logger.info("Pushed successfully")
end
Submodules
-- Add submodule
Git.submoduleAdd("./repo", "https://github.com/user/submodule.git", "submodules/lib")
-- Update submodule
Git.submoduleUpdate("./repo", "submodules/lib")
-- Initialize submodule
Git.submoduleInit("./repo", "submodules/lib")
Parameters
path- Path to the Git repositoryurl- Repository URLfilePath- Path to file (relative to repository)filePaths- Array of file pathsfolderPath- Path to folder (relative to repository)message- Commit messageauthor- Author nameemail- Author emailremote- Remote name (e.g., "origin")branch- Branch nameoptions- Table with options (Branch, Depth, IsBare, CheckoutBranch)
Return Values
Most functions return a table with:
Success- Boolean indicating successRepositoryPath- Path to the repository (for clone)CommitHash- Commit hash (for commit operations)