Last active
December 12, 2024 09:11
-
-
Save davidfowl/f116c515cd977a8c96670abcd1cc2263 to your computer and use it in GitHub Desktop.
Sample schema for git add, clone, commit, clean
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
using System; | |
using System.Collections.Generic; | |
using CliWrap; | |
namespace GitCLIWrapper; | |
public static class Git | |
{ | |
public static Command Clone( | |
string repository, | |
string? directory = null, | |
string? branch = null, | |
int? depth = null) | |
{ | |
var args = new List<string> { "clone", repository }; | |
if (!string.IsNullOrEmpty(directory)) | |
args.Add(directory); | |
if (!string.IsNullOrEmpty(branch)) | |
args.Add($"--branch {branch}"); | |
if (depth.HasValue) | |
args.Add($"--depth {depth}"); | |
return Cli.Wrap("git").WithArguments(string.Join(" ", args)); | |
} | |
public static Command Add( | |
string pathspec, | |
bool update = false, | |
bool verbose = false) | |
{ | |
var args = new List<string> { "add", pathspec }; | |
if (update) | |
args.Add("--update"); | |
if (verbose) | |
args.Add("--verbose"); | |
return Cli.Wrap("git").WithArguments(string.Join(" ", args)); | |
} | |
public static Command Commit( | |
string message, | |
bool all = false, | |
bool amend = false) | |
{ | |
var args = new List<string> { "commit", $"-m \"{message}\"" }; | |
if (all) | |
args.Add("--all"); | |
if (amend) | |
args.Add("--amend"); | |
return Cli.Wrap("git").WithArguments(string.Join(" ", args)); | |
} | |
public static Command Clean( | |
bool dryRun = false, | |
bool force = false, | |
bool directories = false) | |
{ | |
var args = new List<string> { "clean" }; | |
if (dryRun) | |
args.Add("--dry-run"); | |
if (force) | |
args.Add("--force"); | |
if (directories) | |
args.Add("--directories"); | |
return Cli.Wrap("git").WithArguments(string.Join(" ", args)); | |
} | |
} |
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
{ | |
"name": "git", | |
"description": "A distributed version control system.", | |
"commands": { | |
"clone": { | |
"description": "Clone a repository into a new directory.", | |
"arguments": [ | |
{ | |
"name": "repository", | |
"type": "string", | |
"description": "The URL of the repository to clone." | |
}, | |
{ | |
"name": "directory", | |
"type": "string", | |
"description": "The name of a directory to clone into.", | |
"required": false | |
} | |
], | |
"options": [ | |
{ | |
"name": "branch", | |
"type": "string", | |
"short": "b", | |
"description": "Checkout a specific branch after cloning.", | |
"required": false | |
}, | |
{ | |
"name": "depth", | |
"type": "number", | |
"description": "Create a shallow clone with a history truncated to the specified number of commits.", | |
"required": false | |
} | |
] | |
}, | |
"add": { | |
"description": "Add file contents to the index.", | |
"arguments": [ | |
{ | |
"name": "pathspec", | |
"type": "string", | |
"description": "Files to add to the index. Can be a file, directory, or pattern." | |
} | |
], | |
"options": [ | |
{ | |
"name": "update", | |
"type": "boolean", | |
"short": "u", | |
"description": "Only update tracked files." | |
}, | |
{ | |
"name": "verbose", | |
"type": "boolean", | |
"short": "v", | |
"description": "Be verbose." | |
} | |
] | |
}, | |
"commit": { | |
"description": "Record changes to the repository.", | |
"arguments": [], | |
"options": [ | |
{ | |
"name": "message", | |
"type": "string", | |
"short": "m", | |
"description": "Use the given message as the commit message.", | |
"required": true | |
}, | |
{ | |
"name": "all", | |
"type": "boolean", | |
"short": "a", | |
"description": "Stage all modified and deleted files before committing." | |
}, | |
{ | |
"name": "amend", | |
"type": "boolean", | |
"description": "Amend the tip of the current branch." | |
} | |
] | |
}, | |
"clean": { | |
"description": "Remove untracked files from the working directory.", | |
"arguments": [], | |
"options": [ | |
{ | |
"name": "dry-run", | |
"type": "boolean", | |
"short": "n", | |
"description": "Show what would be done without actually doing it." | |
}, | |
{ | |
"name": "force", | |
"type": "boolean", | |
"short": "f", | |
"description": "Force the clean operation." | |
}, | |
{ | |
"name": "directories", | |
"type": "boolean", | |
"short": "d", | |
"description": "Remove untracked directories in addition to untracked files." | |
} | |
] | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment