@candriajs/simple-git
Version:
一些常用包以及常用函数进行封装,并打包优化, 此包为simple-git封装
1,395 lines (1,285 loc) • 59.3 kB
TypeScript
import { SpawnOptions } from "child_process";
//#region ../../node_modules/.pnpm/simple-git@3.28.0/node_modules/simple-git/dist/src/lib/tasks/diff-name-status.d.ts
declare enum DiffNameStatus {
ADDED = "A",
COPIED = "C",
DELETED = "D",
MODIFIED = "M",
RENAMED = "R",
CHANGED = "T",
UNMERGED = "U",
UNKNOWN = "X",
BROKEN = "B",
}
//#endregion
//#region ../../node_modules/.pnpm/simple-git@3.28.0/node_modules/simple-git/dist/src/lib/tasks/task.d.ts
declare const EMPTY_COMMANDS: [];
type EmptyTask = {
commands: typeof EMPTY_COMMANDS;
format: 'empty';
parser: EmptyTaskParser;
onError?: undefined;
};
//#endregion
//#region ../../node_modules/.pnpm/simple-git@3.28.0/node_modules/simple-git/dist/src/lib/types/tasks.d.ts
type TaskResponseFormat = Buffer | string;
interface TaskParser<INPUT extends TaskResponseFormat, RESPONSE> {
(stdOut: INPUT, stdErr: INPUT): RESPONSE;
}
interface EmptyTaskParser {
(executor: SimpleGitExecutor): void;
}
interface SimpleGitTaskConfiguration<RESPONSE, FORMAT, INPUT extends TaskResponseFormat> {
commands: string[];
format: FORMAT;
parser: TaskParser<INPUT, RESPONSE>;
onError?: (result: GitExecutorResult, error: Error, done: (result: Buffer | Buffer[]) => void, fail: (error: string | Error) => void) => void;
}
type StringTask<R> = SimpleGitTaskConfiguration<R, 'utf-8', string>;
type BufferTask<R> = SimpleGitTaskConfiguration<R, 'buffer', Buffer>;
type RunnableTask<R> = StringTask<R> | BufferTask<R>;
type SimpleGitTask<R> = RunnableTask<R> | EmptyTask;
//#endregion
//#region ../../node_modules/.pnpm/simple-git@3.28.0/node_modules/simple-git/dist/src/lib/errors/git-error.d.ts
/**
* The `GitError` is thrown when the underlying `git` process throws a
* fatal exception (eg an `ENOENT` exception when attempting to use a
* non-writable directory as the root for your repo), and acts as the
* base class for more specific errors thrown by the parsing of the
* git response or errors in the configuration of the task about to
* be run.
*
* When an exception is thrown, pending tasks in the same instance will
* not be executed. The recommended way to run a series of tasks that
* can independently fail without needing to prevent future tasks from
* running is to catch them individually:
*
* ```typescript
import { gitP, SimpleGit, GitError, PullResult } from 'simple-git';
function catchTask (e: GitError) {
return e.
}
const git = gitP(repoWorkingDir);
const pulled: PullResult | GitError = await git.pull().catch(catchTask);
const pushed: string | GitError = await git.pushTags().catch(catchTask);
```
*/
declare class GitError extends Error {
task?: SimpleGitTask<any> | undefined;
constructor(task?: SimpleGitTask<any> | undefined, message?: string);
}
//#endregion
//#region ../../node_modules/.pnpm/simple-git@3.28.0/node_modules/simple-git/dist/src/lib/types/handlers.d.ts
/**
* The node-style callback to a task accepts either two arguments with the first as a null
* and the second as the data, or just one argument which is an error.
*/
type SimpleGitTaskCallback<T = string, E extends GitError = GitError> = (err: E | null, data: T) => void;
/**
* The event data emitted to the progress handler whenever progress detail is received.
*/
interface SimpleGitProgressEvent {
/** The underlying method called - push, pull etc */
method: string;
/** The type of progress being reported, note that any one task may emit many stages - for example `git clone` emits both `receiving` and `resolving` */
stage: 'compressing' | 'counting' | 'receiving' | 'resolving' | 'unknown' | 'writing' | string;
/** The percent progressed as a number 0 - 100 */
progress: number;
/** The number of items processed so far */
processed: number;
/** The total number of items to be processed */
total: number;
}
//#endregion
//#region ../../node_modules/.pnpm/simple-git@3.28.0/node_modules/simple-git/dist/src/lib/types/index.d.ts
/**
* Most tasks accept custom options as an array of strings as well as the
* options object. Unless the task is explicitly documented as such, the
* tasks will not accept both formats at the same time, preferring whichever
* appears last in the arguments.
*/
type TaskOptions<O extends Options = Options> = string[] | O;
/**
* Options supplied in most tasks as an optional trailing object
*/
type OptionsValues = null | string | number | (string | number)[];
type Options = Record<string, OptionsValues>;
type OptionFlags<FLAGS extends string, VALUE = null> = Partial<Record<FLAGS, VALUE>>;
/**
* A function called by the executor immediately after creating a child
* process. Allows the calling application to implement custom handling of
* the incoming stream of data from the `git`.
*/
type outputHandler = (command: string, stdout: NodeJS.ReadableStream, stderr: NodeJS.ReadableStream, args: string[]) => void;
/**
* Environment variables to be passed into the child process.
*/
type GitExecutorEnv = NodeJS.ProcessEnv | undefined;
/**
* Public interface of the Executor
*/
interface SimpleGitExecutor {
env: GitExecutorEnv;
outputHandler?: outputHandler;
cwd: string;
chain(): SimpleGitExecutor;
push<R>(task: SimpleGitTask<R>): Promise<R>;
}
/**
* The resulting output from running the git child process
*/
interface GitExecutorResult {
stdOut: Buffer[];
stdErr: Buffer[];
exitCode: number;
rejection: Maybe<Error>;
}
interface SimpleGitPluginConfig {
abort: AbortSignal;
/**
* Name of the binary the child processes will spawn - defaults to `git`,
* supply as a tuple to enable the use of platforms that require `git` to be
* called through an alternative binary (eg: `wsl git ...`).
* Note: commands supplied in this way support a restricted set of characters
* and should not be used as a way to supply arbitrary config arguments etc.
*/
binary: string | [string] | [string, string];
/**
* Configures the events that should be used to determine when the unederlying child process has
* been terminated.
*
* Version 2 will default to use `onClose=true, onExit=50` to mean the `close` event will be
* used to immediately treat the child process as closed and start using the data from `stdOut`
* / `stdErr`, whereas the `exit` event will wait `50ms` before treating the child process
* as closed.
*
* This will be changed in version 3 to use `onClose=true, onExit=false` so that only the
* close event is used to determine the termination of the process.
*/
completion: {
onClose?: boolean | number;
onExit?: boolean | number;
};
/**
* Configures the content of errors thrown by the `simple-git` instance for each task
*/
errors(error: Buffer | Error | undefined, result: Omit<GitExecutorResult, 'rejection'>): Buffer | Error | undefined;
/**
* Handler to be called with progress events emitted through the progress plugin
*/
progress(data: SimpleGitProgressEvent): void;
/**
* Configuration for the `timeoutPlugin`
*/
timeout: {
/**
* The number of milliseconds to wait after spawning the process / receiving
* content on the stdOut/stdErr streams before forcibly closing the git process.
*/
block: number;
/**
* Reset timeout plugin after receiving data on `stdErr` - set to `false` to ignore
* `stdErr` content when determining whether to kill the process (defaults to `true`).
*/
stdErr?: boolean;
/**
* Reset timeout plugin after receiving data on `stdOut` - set to `false` to ignore
* `stdOut` content when determining whether to kill the process (defaults to `true`).
*/
stdOut?: boolean;
};
spawnOptions: Pick<SpawnOptions, 'uid' | 'gid'>;
unsafe: {
/**
* Allows potentially unsafe values to be supplied in the `binary` configuration option and
* `git.customBinary()` method call.
*/
allowUnsafeCustomBinary?: boolean;
/**
* By default `simple-git` prevents the use of inline configuration
* options to override the protocols available for the `git` child
* process to prevent accidental security vulnerabilities when
* unsanitised user data is passed directly into operations such as
* `git.addRemote`, `git.clone` or `git.raw`.
*
* Enable this override to use the `ext::` protocol (see examples on
* [git-scm.com](https://git-scm.com/docs/git-remote-ext#_examples)).
*/
allowUnsafeProtocolOverride?: boolean;
/**
* Given the possibility of using `--upload-pack` and `--receive-pack` as
* attack vectors, the use of these in any command (or the shorthand
* `-u` option in a `clone` operation) are blocked by default.
*
* Enable this override to permit the use of these arguments.
*/
allowUnsafePack?: boolean;
};
}
/**
* Optional configuration settings to be passed to the `simpleGit`
* builder.
*/
interface SimpleGitOptions extends Partial<SimpleGitPluginConfig> {
/**
* Base directory for all tasks run through this `simple-git` instance
*/
baseDir: string;
/**
* Limit for the number of child processes that will be spawned concurrently from a `simple-git` instance
*/
maxConcurrentProcesses: number;
/**
* Per-command configuration parameters to be passed with the `-c` switch to `git`
*/
config: string[];
/**
* Enable trimming of trailing white-space in `git.raw`
*/
trimmed: boolean;
}
type Maybe<T> = T | undefined;
//#endregion
//#region ../../node_modules/.pnpm/simple-git@3.28.0/node_modules/simple-git/dist/src/lib/tasks/log.d.ts
interface DefaultLogFields {
hash: string;
date: string;
message: string;
refs: string;
body: string;
author_name: string;
author_email: string;
}
type LogOptions<T = DefaultLogFields> = {
file?: string;
format?: T;
from?: string;
mailMap?: boolean;
maxCount?: number;
multiLine?: boolean;
splitter?: string;
strictDate?: boolean;
symmetric?: boolean;
to?: string;
};
//#endregion
//#region ../../node_modules/.pnpm/simple-git@3.28.0/node_modules/simple-git/dist/typings/response.d.ts
interface BranchSummaryBranch {
current: boolean;
name: string;
commit: string;
label: string;
linkedWorkTree: boolean;
}
interface BranchSummary {
detached: boolean;
current: string;
all: string[];
branches: {
[key: string]: BranchSummaryBranch;
};
}
/**
* Represents the successful deletion of a single branch
*/
interface BranchSingleDeleteSuccess {
branch: string;
hash: string;
success: true;
}
/**
* Represents the failure to delete a single branch
*/
interface BranchSingleDeleteFailure {
branch: string;
hash: null;
success: false;
}
type BranchSingleDeleteResult = BranchSingleDeleteFailure | BranchSingleDeleteSuccess;
/**
* Represents the status of having deleted a batch of branches
*/
interface BranchMultiDeleteResult {
/**
* All branches included in the response
*/
all: BranchSingleDeleteResult[];
/**
* Branches mapped by their branch name
*/
branches: {
[branchName: string]: BranchSingleDeleteResult;
};
/**
* Array of responses that are in error
*/
errors: BranchSingleDeleteResult[];
/**
* Flag showing whether all branches were deleted successfully
*/
readonly success: boolean;
}
interface CleanSummary {
readonly dryRun: boolean;
paths: string[];
files: string[];
folders: string[];
}
interface CommitResult {
author: null | {
email: string;
name: string;
};
branch: string;
commit: string;
root: boolean;
summary: {
changes: number;
insertions: number;
deletions: number;
};
}
/** Represents the response to using `git.getConfig` */
interface ConfigGetResult {
/** The key that was searched for */
key: string;
/** The single value seen by `git` for this key (equivalent to `git config --get key`) */
value: string | null;
/** All possible values for this key no matter the scope (equivalent to `git config --get-all key`) */
values: string[];
/** The file paths from which configuration was read */
paths: string[];
/**
* The full hierarchy of values the property can have had across the
* various scopes that were searched (keys in this Map are the strings
* also found in the `paths` array).
*/
scopes: Map<string, string[]>;
}
/**
* Represents the current git configuration, as defined by the output from `git log`
*/
interface ConfigListSummary {
/**
* All configuration settings, where local/user settings override user/global settings
* the overridden value will appear in this object.
*/
readonly all: ConfigValues;
/**
* The file paths configuration was read from
*/
files: string[];
/**
* The `ConfigValues` for each of the `files`, use this object to determine
* local repo, user and global settings.
*/
values: {
[fileName: string]: ConfigValues;
};
}
/**
* Represents the map of configuration settings
*/
interface ConfigValues {
[key: string]: string | string[];
}
interface DiffResultTextFile {
file: string;
changes: number;
insertions: number;
deletions: number;
binary: false;
}
interface DiffResultBinaryFile {
file: string;
before: number;
after: number;
binary: true;
}
/** `--name-status` argument needed */
interface DiffResultNameStatusFile extends DiffResultTextFile {
status?: DiffNameStatus;
from?: string;
similarity: number;
}
interface DiffResult {
/** The total number of files changed as reported in the summary line */
changed: number;
/** When present in the diff, lists the details of each file changed */
files: Array<DiffResultTextFile | DiffResultBinaryFile | DiffResultNameStatusFile>;
/** The number of files changed with insertions */
insertions: number;
/** The number of files changed with deletions */
deletions: number;
}
interface FetchResult {
raw: string;
remote: string | null;
branches: {
name: string;
tracking: string;
}[];
tags: {
name: string;
tracking: string;
}[];
updated: {
name: string;
tracking: string;
to: string;
from: string;
}[];
deleted: {
tracking: string;
}[];
}
/** Represents the response to git.grep */
interface GrepResult {
paths: Set<string>;
results: Record<string, Array<{
line: number;
path: string;
preview: string;
}>>;
}
/**
* The `InitResult` is returned when (re)initialising a git repo.
*/
interface InitResult {
/**
* Boolean representing whether the `--bare` option was used
*/
readonly bare: boolean;
/**
* Boolean representing whether the repo already existed (re-initialised rather than initialised)
*/
readonly existing: boolean;
/**
* The path used when initialising
*/
readonly path: string;
/**
* The git configuration directory - for a bare repo this is the same as `path`, in non-bare repos
* this will usually be a sub-directory with the name `.git` (or value of the `$GIT_DIR` environment
* variable).
*/
readonly gitDir: string;
}
/**
* A parsed response summary for calls to `git mv`
*/
interface MoveResult {
/**
* Array of files moved
*/
moves: Array<{
from: string;
to: string;
}>;
}
interface PullDetailFileChanges {
[fileName: string]: number;
}
interface PullDetailSummary {
changes: number;
insertions: number;
deletions: number;
}
interface PullDetail {
/** Array of all files that are referenced in the pull */
files: string[];
/** Map of file names to the number of insertions in that file */
insertions: PullDetailFileChanges;
/** Map of file names to the number of deletions in that file */
deletions: PullDetailFileChanges;
summary: PullDetailSummary;
/** Array of file names that have been created */
created: string[];
/** Array of file names that have been deleted */
deleted: string[];
}
interface PullResult extends PullDetail, RemoteMessageResult {}
/**
* Wrapped with the `GitResponseError` as the exception thrown from a `git.pull` task
* to provide additional detail as to what failed.
*/
interface PullFailedResult {
remote: string;
hash: {
local: string;
remote: string;
};
branch: {
local: string;
remote: string;
};
message: string;
}
/**
* Represents file name changes in a StatusResult
*/
interface StatusResultRenamed {
from: string;
to: string;
}
interface FileStatusResult {
/** Original location of the file, when the file has been moved */
from?: string;
/** Path of the file */
path: string;
/** First digit of the status code of the file, e.g. 'M' = modified.
Represents the status of the index if no merge conflicts, otherwise represents
status of one side of the merge. */
index: string;
/** Second digit of the status code of the file. Represents status of the working directory
if no merge conflicts, otherwise represents status of other side of a merge.
See https://git-scm.com/docs/git-status#_short_format for full documentation of possible
values and their meanings. */
working_dir: string;
}
/**
* The StatusResult is returned for calls to `git.status()`, represents the state of the
* working directory.
*/
interface StatusResult {
not_added: string[];
conflicted: string[];
created: string[];
deleted: string[];
/**
* Ignored files are not listed by default, add `--ignored` to the task options in order to see
* this array of ignored files/paths.
*
* Note: ignored files will not be added to the `files` array, and will not be included in the
* `isClean()` calculation.
*/
ignored?: string[];
modified: string[];
renamed: StatusResultRenamed[];
staged: string[];
/**
* All files represented as an array of objects containing the `path` and status in `index` and
* in the `working_dir`.
*/
files: FileStatusResult[];
/**
* Number of commits ahead of the tracked branch
*/
ahead: number;
/**
*Number of commits behind the tracked branch
*/
behind: number;
/**
* Name of the current branch
*/
current: string | null;
/**
* Name of the branch being tracked
*/
tracking: string | null;
/**
* Detached status of the working copy, for more detail of what the working branch
* is detached from use `git.branch()`
*/
detached: boolean;
/**
* Gets whether this represents a clean working branch.
*/
isClean(): boolean;
}
/**
* Response retrieved when using the `git.tags` method
*/
interface TagResult {
/**
* All tag names
*/
all: string[];
/**
* The semver latest tag name or `undefined` when no tags are named in the response
*/
latest: string | undefined;
}
/**
* The ListLogLine represents a single entry in the `git.log`, the properties on the object
* are mixed in depending on the names used in the format (see `DefaultLogFields`), but some
* properties are dependent on the command used.
*/
interface ListLogLine {
/**
* When using a `--stat=4096` or `--shortstat` options in the `git.log` or `git.stashList`,
* each entry in the `ListLogSummary` will also have a `diff` property representing as much
* detail as was given in the response.
*/
diff?: DiffResult;
}
interface LogResult<T = DefaultLogFields> {
all: ReadonlyArray<T & ListLogLine>;
total: number;
latest: (T & ListLogLine) | null;
}
/**
* Where the file was deleted, if there is a modify/delete conflict
*/
interface MergeConflictDeletion {
deleteRef: string;
}
/**
* Represents a single file with conflicts in the MergeSummary
*/
interface MergeConflict {
/**
* Type of conflict
*/
reason: string;
/**
* Path to file
*/
file: string | null;
/**
* Additional detail for the specific type of conflict
*/
meta?: MergeConflictDeletion;
}
type MergeResultStatus = 'success' | string;
interface MergeDetail {
conflicts: MergeConflict[];
merges: string[];
result: MergeResultStatus;
readonly failed: boolean;
}
type MergeResult = PullResult & MergeDetail;
/**
*
*/
interface PushResultPushedItem {
local: string;
remote: string;
readonly deleted: boolean;
readonly tag: boolean;
readonly branch: boolean;
readonly new: boolean;
readonly alreadyUpdated: boolean;
}
interface RemoteMessagesObjectEnumeration {
enumerating: number;
counting: number;
compressing: number;
total: {
count: number;
delta: number;
};
reused: {
count: number;
delta: number;
};
packReused: number;
}
interface RemoteMessages {
all: string[];
objects?: RemoteMessagesObjectEnumeration;
}
interface PushResultRemoteMessages extends RemoteMessages {
pullRequestUrl?: string;
vulnerabilities?: {
count: number;
summary: string;
url: string;
};
}
interface RemoteMessageResult<T extends RemoteMessages = RemoteMessages> {
remoteMessages: T;
}
interface PushResultBranchUpdate {
head: {
local: string;
remote: string;
};
hash: {
from: string;
to: string;
};
}
interface PushDetail {
repo?: string;
ref?: {
local: string;
};
pushed: PushResultPushedItem[];
branch?: {
local: string;
remote: string;
remoteName: string;
};
update?: PushResultBranchUpdate;
}
interface PushResult extends PushDetail, RemoteMessageResult<PushResultRemoteMessages> {}
/**
* @deprecated
* For consistent naming, please use `CommitResult` instead of `CommitSummary`
*/
type CommitSummary = CommitResult;
/**
* @deprecated
* For consistent naming, please use `MergeResult` instead of `MergeSummary`
*/
type MergeSummary = MergeResult;
/**
* @deprecated to aid consistent naming, please use `BranchSingleDeleteResult` instead of `BranchDeletionSummary`.
*/
type BranchDeletionSummary = BranchSingleDeleteResult;
/**
* @deprecated to aid consistent naming, please use `BranchMultiDeleteResult` instead of `BranchDeletionBatchSummary`.
*/
type BranchDeletionBatchSummary = BranchMultiDeleteResult;
type MoveSummary = MoveResult;
/**
* @deprecated to aid consistent naming, please use `LogResult` instead of `ListLogSummary`.
*/
type ListLogSummary<T = DefaultLogFields> = LogResult<T>;
//#endregion
//#region ../../node_modules/.pnpm/simple-git@3.28.0/node_modules/simple-git/dist/src/lib/responses/GetRemoteSummary.d.ts
interface RemoteWithoutRefs {
name: string;
}
interface RemoteWithRefs extends RemoteWithoutRefs {
refs: {
fetch: string;
push: string;
};
}
//#endregion
//#region ../../node_modules/.pnpm/simple-git@3.28.0/node_modules/simple-git/dist/src/lib/args/pathspec.d.ts
declare function pathspec(...paths: string[]): string;
//#endregion
//#region ../../node_modules/.pnpm/simple-git@3.28.0/node_modules/simple-git/dist/src/lib/tasks/apply-patch.d.ts
type ApplyOptions = Options & OptionFlags<'--stat' | '--numstat' | '--summary' | '--check' | '--index' | '--intent-to-add' | '--3way' | '--apply' | '--no-add' | '-R' | '--reverse' | '--allow-binary-replacement' | '--binary' | '--reject' | '-z' | '--inaccurate-eof' | '--recount' | '--cached' | '--ignore-space-change' | '--ignore-whitespace' | '--verbose' | '--unsafe-paths'> & OptionFlags<'--whitespace', 'nowarn' | 'warn' | 'fix' | 'error' | 'error-all'> & OptionFlags<'--build-fake-ancestor' | '--exclude' | '--include' | '--directory', string> & OptionFlags<'-p' | '-C', number>;
//#endregion
//#region ../../node_modules/.pnpm/simple-git@3.28.0/node_modules/simple-git/dist/src/lib/tasks/check-is-repo.d.ts
declare enum CheckRepoActions {
BARE = "bare",
IN_TREE = "tree",
IS_REPO_ROOT = "root",
}
//#endregion
//#region ../../node_modules/.pnpm/simple-git@3.28.0/node_modules/simple-git/dist/src/lib/tasks/clean.d.ts
/**
* All supported option switches available for use in a `git.clean` operation
*/
declare enum CleanOptions {
DRY_RUN = "n",
FORCE = "f",
IGNORED_INCLUDED = "x",
IGNORED_ONLY = "X",
EXCLUDING = "e",
QUIET = "q",
RECURSIVE = "d",
}
/**
* The two modes `git.clean` can run in - one of these must be supplied in order
* for the command to not throw a `TaskConfigurationError`
*/
type CleanMode = CleanOptions.FORCE | CleanOptions.DRY_RUN;
//#endregion
//#region ../../node_modules/.pnpm/simple-git@3.28.0/node_modules/simple-git/dist/src/lib/tasks/clone.d.ts
type CloneOptions = Options & OptionFlags<'--bare' | '--dissociate' | '--mirror' | '--no-checkout' | '--no-remote-submodules' | '--no-shallow-submodules' | '--no-single-branch' | '--no-tags' | '--remote-submodules' | '--single-branch' | '--shallow-submodules' | '--verbose'> & OptionFlags<'--depth' | '-j' | '--jobs', number> & OptionFlags<'--branch' | '--origin' | '--recurse-submodules' | '--separate-git-dir' | '--shallow-exclude' | '--shallow-since' | '--template', string>;
//#endregion
//#region ../../node_modules/.pnpm/simple-git@3.28.0/node_modules/simple-git/dist/src/lib/tasks/config.d.ts
declare enum GitConfigScope {
system = "system",
global = "global",
local = "local",
worktree = "worktree",
}
//#endregion
//#region ../../node_modules/.pnpm/simple-git@3.28.0/node_modules/simple-git/dist/src/lib/tasks/count-objects.d.ts
interface CountObjectsResult {
count: number;
size: number;
inPack: number;
packs: number;
sizePack: number;
prunePackable: number;
garbage: number;
sizeGarbage: number;
}
//#endregion
//#region ../../node_modules/.pnpm/simple-git@3.28.0/node_modules/simple-git/dist/src/lib/tasks/grep.d.ts
interface GitGrepQuery extends Iterable<string> {
/** Adds one or more terms to be grouped as an "and" to any other terms */
and(...and: string[]): this;
/** Adds one or more search terms - git.grep will "or" this to other terms */
param(...param: string[]): this;
}
/**
* Creates a new builder for a `git.grep` query with optional params
*/
declare function grepQueryBuilder(...params: string[]): GitGrepQuery;
//#endregion
//#region ../../node_modules/.pnpm/simple-git@3.28.0/node_modules/simple-git/dist/src/lib/tasks/reset.d.ts
declare enum ResetMode {
MIXED = "mixed",
SOFT = "soft",
HARD = "hard",
MERGE = "merge",
KEEP = "keep",
}
type ResetOptions = Options & OptionFlags<'-q' | '--quiet' | '--no-quiet' | '--pathspec-from-nul'> & OptionFlags<'--pathspec-from-file', string>;
//#endregion
//#region ../../node_modules/.pnpm/simple-git@3.28.0/node_modules/simple-git/dist/src/lib/tasks/version.d.ts
interface VersionResult {
major: number;
minor: number;
patch: number | string;
agent: string;
installed: boolean;
}
//#endregion
//#region ../../node_modules/.pnpm/simple-git@3.28.0/node_modules/simple-git/dist/src/lib/errors/git-construct-error.d.ts
/**
* The `GitConstructError` is thrown when an error occurs in the constructor
* of the `simple-git` instance itself. Most commonly as a result of using
* a `baseDir` option that points to a folder that either does not exist,
* or cannot be read by the user the node script is running as.
*
* Check the `.message` property for more detail including the properties
* passed to the constructor.
*/
declare class GitConstructError extends GitError {
readonly config: SimpleGitOptions;
constructor(config: SimpleGitOptions, message: string);
}
//#endregion
//#region ../../node_modules/.pnpm/simple-git@3.28.0/node_modules/simple-git/dist/src/lib/errors/git-plugin-error.d.ts
declare class GitPluginError extends GitError {
task?: SimpleGitTask<any> | undefined;
readonly plugin?: keyof SimpleGitOptions | undefined;
constructor(task?: SimpleGitTask<any> | undefined, plugin?: keyof SimpleGitOptions | undefined, message?: string);
}
//#endregion
//#region ../../node_modules/.pnpm/simple-git@3.28.0/node_modules/simple-git/dist/src/lib/errors/git-response-error.d.ts
/**
* The `GitResponseError` is the wrapper for a parsed response that is treated as
* a fatal error, for example attempting a `merge` can leave the repo in a corrupted
* state when there are conflicts so the task will reject rather than resolve.
*
* For example, catching the merge conflict exception:
*
* ```typescript
import { gitP, SimpleGit, GitResponseError, MergeSummary } from 'simple-git';
const git = gitP(repoRoot);
const mergeOptions: string[] = ['--no-ff', 'other-branch'];
const mergeSummary: MergeSummary = await git.merge(mergeOptions)
.catch((e: GitResponseError<MergeSummary>) => e.git);
if (mergeSummary.failed) {
// deal with the error
}
```
*/
declare class GitResponseError<T = any> extends GitError {
/**
* `.git` access the parsed response that is treated as being an error
*/
readonly git: T;
constructor(
/**
* `.git` access the parsed response that is treated as being an error
*/
git: T, message?: string);
}
//#endregion
//#region ../../node_modules/.pnpm/simple-git@3.28.0/node_modules/simple-git/dist/src/lib/errors/task-configuration-error.d.ts
/**
* The `TaskConfigurationError` is thrown when a command was incorrectly
* configured. An error of this kind means that no attempt was made to
* run your command through the underlying `git` binary.
*
* Check the `.message` property for more detail on why your configuration
* resulted in an error.
*/
declare class TaskConfigurationError extends GitError {
constructor(message?: string);
}
//#endregion
//#region ../../node_modules/.pnpm/simple-git@3.28.0/node_modules/simple-git/dist/typings/simple-git.d.ts
interface SimpleGitFactory {
(baseDir?: string, options?: Partial<SimpleGitOptions>): SimpleGit;
(baseDir: string): SimpleGit;
(options: Partial<SimpleGitOptions>): SimpleGit;
}
type Response<T> = SimpleGit & Promise<T>;
interface SimpleGitBase {
/**
* Adds one or more files to source control
*/
add(files: string | string[], callback?: SimpleGitTaskCallback<string>): Response<string>;
/**
* Sets the working directory of the subsequent commands.
*/
cwd(directory: {
path: string;
root?: boolean;
}, callback?: SimpleGitTaskCallback<string>): Response<string>;
cwd<path extends string>(directory: path, callback?: SimpleGitTaskCallback<path>): Response<path>;
/**
* Compute object ID from a file
*/
hashObject(path: string, callback?: SimpleGitTaskCallback): Response<string>;
hashObject(path: string, write?: boolean, callback?: SimpleGitTaskCallback): Response<string>;
/**
* Initialize a git repo
*/
init(bare: boolean, options?: TaskOptions, callback?: SimpleGitTaskCallback<InitResult>): Response<InitResult>;
init(bare: boolean, callback?: SimpleGitTaskCallback<InitResult>): Response<InitResult>;
init(options?: TaskOptions, callback?: SimpleGitTaskCallback<InitResult>): Response<InitResult>;
init(callback?: SimpleGitTaskCallback<InitResult>): Response<InitResult>;
/**
* Runs a merge, `options` can be either an array of arguments
* supported by the [`git merge`](https://git-scm.com/docs/git-merge)
* or an options object.
*
* Conflicts during the merge result in an error response,
* the response type whether it was an error or success will be a MergeSummary instance.
* When successful, the MergeSummary has all detail from a the PullSummary
*
* @see https://github.com/steveukx/git-js/blob/master/src/responses/MergeSummary.js
* @see https://github.com/steveukx/git-js/blob/master/src/responses/PullSummary.js
*/
merge(options: TaskOptions, callback?: SimpleGitTaskCallback<MergeResult>): Response<MergeResult>;
/**
* Merges from one branch to another, equivalent to running `git merge ${remote} ${branch}`, the `options` argument can
* either be an array of additional parameters to pass to the command or null / omitted to be ignored.
*/
mergeFromTo<E extends GitError>(remote: string, branch: string, options?: TaskOptions, callback?: SimpleGitTaskCallback<MergeResult, E>): Response<MergeResult>;
mergeFromTo<E extends GitError>(remote: string, branch: string, callback?: SimpleGitTaskCallback<MergeResult, E>): Response<MergeResult>;
/**
* Sets a handler function to be called whenever a new child process is created, the handler function will be called
* with the name of the command being run and the stdout & stderr streams used by the ChildProcess.
*
* @example
* require('simple-git')
* .outputHandler(function (command, stdout, stderr) {
* stdout.pipe(process.stdout);
* })
* .checkout('https://github.com/user/repo.git');
*
* @see https://nodejs.org/api/child_process.html#child_process_class_childprocess
* @see https://nodejs.org/api/stream.html#stream_class_stream_readable
*/
outputHandler(handler: outputHandler | void): this;
/**
* Pushes the current committed changes to a remote, optionally specify the names of the remote and branch to use
* when pushing. Supply multiple options as an array of strings in the first argument - see examples below.
*/
push(remote?: string, branch?: string, options?: TaskOptions, callback?: SimpleGitTaskCallback<PushResult>): Response<PushResult>;
push(options?: TaskOptions, callback?: SimpleGitTaskCallback<PushResult>): Response<PushResult>;
push(callback?: SimpleGitTaskCallback<PushResult>): Response<PushResult>;
/**
* Stash the local repo
*/
stash(options?: TaskOptions, callback?: SimpleGitTaskCallback<string>): Response<string>;
stash(callback?: SimpleGitTaskCallback<string>): Response<string>;
/**
* Show the working tree status.
*/
status(options?: TaskOptions, callback?: SimpleGitTaskCallback<StatusResult>): Response<StatusResult>;
status(callback?: SimpleGitTaskCallback<StatusResult>): Response<StatusResult>;
}
interface SimpleGit extends SimpleGitBase {
/**
* Add an annotated tag to the head of the current branch
*/
addAnnotatedTag(tagName: string, tagMessage: string, callback?: SimpleGitTaskCallback<{
name: string;
}>): Response<{
name: string;
}>;
/**
* Add config to local git instance for the specified `key` (eg: user.name) and value (eg: 'your name').
* Set `append` to true to append to rather than overwrite the key
*/
addConfig(key: string, value: string, append?: boolean, scope?: keyof typeof GitConfigScope, callback?: SimpleGitTaskCallback<string>): Response<string>;
addConfig(key: string, value: string, append?: boolean, callback?: SimpleGitTaskCallback<string>): Response<string>;
addConfig(key: string, value: string, callback?: SimpleGitTaskCallback<string>): Response<string>;
/**
* Applies a patch to the repo
*/
applyPatch(patches: string | string[], options: TaskOptions<ApplyOptions>, callback?: SimpleGitTaskCallback<string>): Response<string>;
applyPatch(patches: string | string[], callback?: SimpleGitTaskCallback<string>): Response<string>;
/**
* Configuration values visible to git in the current working directory
*/
listConfig(scope: keyof typeof GitConfigScope, callback?: SimpleGitTaskCallback<ConfigListSummary>): Response<ConfigListSummary>;
listConfig(callback?: SimpleGitTaskCallback<ConfigListSummary>): Response<ConfigListSummary>;
/**
* Adds a remote to the list of remotes.
*
* - `remoteName` Name of the repository - eg "upstream"
* - `remoteRepo` Fully qualified SSH or HTTP(S) path to the remote repo
* - `options` Optional additional settings permitted by the `git remote add` command, merged into the command prior to the repo name and remote url
*/
addRemote(remoteName: string, remoteRepo: string, options?: TaskOptions, callback?: SimpleGitTaskCallback<string>): Response<string>;
addRemote(remoteName: string, remoteRepo: string, callback?: SimpleGitTaskCallback<string>): Response<string>;
/**
* Add a lightweight tag to the head of the current branch
*/
addTag(name: string, callback?: SimpleGitTaskCallback<{
name: string;
}>): Response<{
name: string;
}>;
/**
* Equivalent to `catFile` but will return the native `Buffer` of content from the git command's stdout.
*/
binaryCatFile(options: string[], callback?: SimpleGitTaskCallback<any>): Response<any>;
/**
* List all branches
*/
branch(options?: TaskOptions, callback?: SimpleGitTaskCallback<BranchSummary>): Response<BranchSummary>;
/**
* List of local branches
*/
branchLocal(callback?: SimpleGitTaskCallback<BranchSummary>): Response<BranchSummary>;
/**
* Returns a list of objects in a tree based on commit hash.
* Passing in an object hash returns the object's content, size, and type.
*
* Passing "-p" will instruct cat-file to determine the object type, and display its formatted contents.
*
* @see https://git-scm.com/docs/git-cat-file
*/
catFile(options: string[], callback?: SimpleGitTaskCallback<string>): Response<string>;
catFile(callback?: SimpleGitTaskCallback<string>): Response<string>;
/**
* Check if a pathname or pathnames are excluded by .gitignore
*
*/
checkIgnore(pathNames: string[], callback?: SimpleGitTaskCallback<string[]>): Response<string[]>;
checkIgnore(path: string, callback?: SimpleGitTaskCallback<string[]>): Response<string[]>;
/**
* Validates that the current working directory is a valid git repo file path.
*
* To make a more specific assertion of the repo, add the `action` argument:
*
* - `bare` to validate that the working directory is inside a bare repo.
* - `root` to validate that the working directory is the root of a repo.
* - `tree` (default value when omitted) to simply validate that the working
* directory is the descendent of a repo
*/
checkIsRepo(action?: CheckRepoActions, callback?: SimpleGitTaskCallback<boolean>): Response<boolean>;
checkIsRepo(callback?: SimpleGitTaskCallback<boolean>): Response<boolean>;
/**
* Checkout a tag or revision, any number of additional arguments can be passed to the `git checkout` command
* by supplying either a string or array of strings as the `what` parameter.
*/
checkout(what: string, options?: TaskOptions, callback?: SimpleGitTaskCallback<string>): Response<string>;
checkout(what: string, callback?: SimpleGitTaskCallback<string>): Response<string>;
checkout(options?: TaskOptions, callback?: SimpleGitTaskCallback<string>): Response<string>;
/**
* Checkout a remote branch - equivalent to `git checkout -b ${branchName} ${startPoint}`
*
* - branchName name of branch.
* - startPoint (e.g origin/development).
*/
checkoutBranch(branchName: string, startPoint: string, callback?: SimpleGitTaskCallback<void>): Response<void>;
checkoutBranch(branchName: string, startPoint: string, options?: TaskOptions, callback?: SimpleGitTaskCallback<void>): Response<void>;
/**
* Internally uses pull and tags to get the list of tags then checks out the latest tag.
*/
checkoutLatestTag(branchName: string, startPoint: string, callback?: SimpleGitTaskCallback<void>): Response<void>;
/**
* Checkout a local branch - equivalent to `git checkout -b ${branchName}`
*/
checkoutLocalBranch(branchName: string, callback?: SimpleGitTaskCallback<void>): Response<void>;
checkoutLocalBranch(branchName: string, options?: TaskOptions, callback?: SimpleGitTaskCallback<void>): Response<void>;
/**
* Deletes unwanted content from the local repo - when supplying the first argument as
* an array of `CleanOptions`, the array must include one of `CleanOptions.FORCE` or
* `CleanOptions.DRY_RUN`.
*
* eg:
*
* ```typescript
await git.clean(CleanOptions.FORCE);
await git.clean(CleanOptions.DRY_RUN + CleanOptions.RECURSIVE);
await git.clean(CleanOptions.FORCE, ['./path']);
await git.clean(CleanOptions.IGNORED + CleanOptions.FORCE, {'./path': null});
* ```
*/
clean(args: CleanOptions[], options?: TaskOptions, callback?: SimpleGitTaskCallback<CleanSummary>): Response<CleanSummary>;
clean(mode: CleanMode | string, options?: TaskOptions, callback?: SimpleGitTaskCallback<CleanSummary>): Response<CleanSummary>;
clean(mode: CleanMode | string, callback?: SimpleGitTaskCallback<CleanSummary>): Response<CleanSummary>;
clean(options?: TaskOptions): Response<CleanSummary>;
clean(callback?: SimpleGitTaskCallback<CleanSummary>): Response<CleanSummary>;
/**
* Clears the queue of pending commands and returns the wrapper instance for chaining.
*/
clearQueue(): this;
/**
* Clone a repository into a new directory.
*
* - repoPath repository url to clone e.g. https://github.com/steveukx/git-js.git
* - localPath local folder path to clone to.
* - options supported by [git](https://git-scm.com/docs/git-clone).
*/
clone(repoPath: string, localPath: string, options?: TaskOptions, callback?: SimpleGitTaskCallback<string>): Response<string>;
clone(repoPath: string, options?: TaskOptions, callback?: SimpleGitTaskCallback<string>): Response<string>;
/**
* Commits changes in the current working directory - when specific file paths are supplied, only changes on those
* files will be committed.
*/
commit(message: string | string[], files?: string | string[], options?: Options, callback?: SimpleGitTaskCallback<CommitResult>): Response<CommitResult>;
commit(message: string | string[], options?: TaskOptions, callback?: SimpleGitTaskCallback<CommitResult>): Response<CommitResult>;
commit(message: string | string[], files?: string | string[], callback?: SimpleGitTaskCallback<CommitResult>): Response<CommitResult>;
commit(message: string | string[], callback?: SimpleGitTaskCallback<CommitResult>): Response<CommitResult>;
/**
* Retrieves `git` disk usage information, see https://git-scm.com/docs/git-count-objects
*/
countObjects(callback?: SimpleGitTaskCallback<VersionResult>): Response<CountObjectsResult>;
/**
* Sets the path to a custom git binary, should either be `git` when there is an installation of git available on
* the system path, or a fully qualified path to the executable.
*/
customBinary(command: Exclude<SimpleGitOptions['binary'], undefined>): this;
/**
* Delete one local branch. Supply the branchName as a string to return a
* single `BranchDeletionSummary` instances.
*
* - branchName name of branch
* - forceDelete (optional, defaults to false) set to true to forcibly delete unmerged branches
*/
deleteLocalBranch(branchName: string, forceDelete?: boolean, callback?: SimpleGitTaskCallback<BranchSingleDeleteResult>): Response<BranchSingleDeleteResult>;
deleteLocalBranch(branchName: string, callback?: SimpleGitTaskCallback<BranchSingleDeleteResult>): Response<BranchSingleDeleteResult>;
/**
* Delete one or more local branches. Supply the branchName as a string to return a
* single `BranchDeletionSummary` or as an array of branch names to return an array of
* `BranchDeletionSummary` instances.
*
* - branchNames name of branch or array of branch names
* - forceDelete (optional, defaults to false) set to true to forcibly delete unmerged branches
*/
deleteLocalBranches(branchNames: string[], forceDelete?: boolean, callback?: SimpleGitTaskCallback<BranchMultiDeleteResult>): Response<BranchMultiDeleteResult>;
/**
* Get the diff of the current repo compared to the last commit with a set of options supplied as a string.
*/
diff(options?: TaskOptions, callback?: SimpleGitTaskCallback<string>): Response<string>;
/**
* Gets a summary of the diff for files in the repo, uses the `git diff --stat` format to calculate changes.
*
* in order to get staged (only): `--cached` or `--staged`.
*/
diffSummary(command: string | number, options: TaskOptions, callback?: SimpleGitTaskCallback<DiffResult>): Response<DiffResult>;
diffSummary(command: string | number, callback?: SimpleGitTaskCallback<DiffResult>): Response<DiffResult>;
diffSummary(options: TaskOptions, callback?: SimpleGitTaskCallback<DiffResult>): Response<DiffResult>;
diffSummary(callback?: SimpleGitTaskCallback<DiffResult>): Response<DiffResult>;
/**
* Sets an environment variable for the spawned child process, either supply both a name and value as strings or
* a single object to entirely replace the current environment variables.
*
* @param {string|Object} name
* @param {string} [value]
*/
env(name: string, value: string): this;
env(env: object): this;
/**
* Calls the supplied `handle` function at the next step in the chain, used to run arbitrary functions synchronously
* before the next task in the git API.
*/
exec(handle: () => void): Response<void>;
/**
* Updates the local working copy database with changes from the default remote repo and branch.
*/
fetch(remote: string, branch: string, options?: TaskOptions, callback?: SimpleGitTaskCallback<FetchResult>): Response<FetchResult>;
fetch(remote: string, branch: string, callback?: SimpleGitTaskCallback<FetchResult>): Response<FetchResult>;
fetch(remote: string, options?: TaskOptions, callback?: SimpleGitTaskCallback<FetchResult>): Response<FetchResult>;
fetch(options?: TaskOptions, callback?: SimpleGitTaskCallback<FetchResult>): Response<FetchResult>;
fetch(callback?: SimpleGitTaskCallback<FetchResult>): Response<FetchResult>;
/**
* Gets the commit hash of the first commit in the repo
*/
firstCommit(callback?: SimpleGitTaskCallback<string>): Response<string>;
/**
* Gets the current value of a configuration property by it key, optionally specify the scope in which
* to run the command (omit / set to `undefined` to check in the complete overlaid configuration visible
* to the `git` process).
*/
getConfig(key: string, scope?: keyof typeof GitConfigScope, callback?: SimpleGitTaskCallback<string>): Response<ConfigGetResult>;
/**
* Gets the currently available remotes, setting the optional verbose argument to true includes additional
* detail on the remotes themselves.
*/
getRemotes(callback?: SimpleGitTaskCallback<RemoteWithoutRefs[]>): Response<RemoteWithoutRefs[]>;
getRemotes(verbose?: false, callback?: SimpleGitTaskCallback<RemoteWithoutRefs[]>): Response<RemoteWithoutRefs[]>;
getRemotes(verbose: true, callback?: SimpleGitTaskCallback<RemoteWithRefs[]>): Response<RemoteWithRefs[]>;
/**
* Search for files matching the supplied search terms
*/
grep(searchTerm: string | GitGrepQuery, callback?: SimpleGitTaskCallback<GrepResult>): Response<GrepResult>;
grep(searchTerm: string | GitGrepQuery, options?: TaskOptions, callback?: SimpleGitTaskCallback<GrepResult>): Response<GrepResult>;
/**
* List remotes by running the `ls-remote` command with any number of arbitrary options
* in either array of object form.
*/
listRemote(args?: TaskOptions, callback?: SimpleGitTaskCallback<string>): Response<string>;
/**
* Show commit logs from `HEAD` to the first commit.
* If provided between `options.from` and `options.to` tags or branch.
*
* You can provide `options.file`, which is the path to a file in your repository. Then only this file will be considered.
*
* To use a custom splitter in the log format, set `options.splitter` to be the string the log should be split on.
*
* By default the following fields will be part of the result:
* `hash`: full commit hash
* `date`: author date, ISO 8601-like format
* `message`: subject + ref names, like the --decorate option of git-log
* `author_name`: author name
* `author_email`: author mail
* You can specify `options.format` to be an mapping from key to a format option like `%H` (for commit hash).
* The fields specified in `options.format` will be the fields in the result.
*
* Options can also be supplied as a standard options object for adding custom properties supported by the git log command.
* For any other set of options, supply options as an array of strings to be appended to the git log command.
*
* @returns Response<ListLogSummary>
*
* @see https://git-scm.com/docs/git-log
*/
log<T = DefaultLogFields>(options?: TaskOptions | LogOptions<T>, callback?: SimpleGitTaskCallback<LogResult<T>>): Response<LogResult<T>>;
/**
* Mirror a git repo
*
* Equivalent to `git.clone(repoPath, localPath, ['--mirror'])`, `clone` allows
* for additional task options.
*/
mirror(repoPath: string, localPath: string, callback?: SimpleGitTaskCallback<string>): Response<string>;
/**
* Moves one or more files to a new destination.
*
* @see https://git-scm.com/docs/git-mv
*/
mv(from: string | string[], to: string, callback?: SimpleGitTaskCallback<MoveSummary>): Response<MoveSummary>;
/**
* Fetch from and integrate with another repository or a local branch. In the case that the `git pull` fails with a
* recognised fatal error, the exception thrown by this function will be a `GitResponseError<PullFailedResult>`.
*/
pull(remote?: string, branch?: string, options?: TaskOptions, callback?: SimpleGitTaskCallback<PullResult>): Response<PullResult>;
pull(options?: TaskOptions, callback?: SimpleGitTaskCallback<PullResult>): Response<PullResult>;
pull(callback?: SimpleGitTaskCallback<PullResult>): Response<PullResult>;
/**
* Pushes the current tag changes to a remote which can be either a URL or named remote. When not specified uses the
* default configured remote spec.
*/
pushTags(remote: string, options?: TaskOptions, callback?: SimpleGitTaskCallback<PushResult>): Response<PushResult>;
pushTags(options?: TaskOptions, callback?: SimpleGitTaskCallback<PushResult>): Response<PushResult>;
pushTags(callback?: SimpleGitTaskCallback<PushResult>): Response<PushResult>;
/**
* Executes any command against the git binary.
*/
raw(commands: string | string[] | TaskOptions, callback?: SimpleGitTaskCallback<string>): Response<string>;
raw(options: TaskOptions, callback?: SimpleGitTaskCallback<string>): Response<string>;
raw(...commands: string[]): Response<string>;
// leading varargs with trailing options/callback
raw(a: string, options: TaskOptions, callback?: SimpleGitTaskCallback<string>): Response<string>;
raw(a: string,