UNPKG

@ts-common/azure-js-dev-tools

Version:

Developer dependencies for TypeScript related projects

890 lines 33.6 kB
/** * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for * license information. */ import { StringMap } from "./common"; import { RunOptions, RunResult } from "./run"; /** * A set of interfaces and types that relate to the Git interface. */ export declare namespace Git { /** * Credentials that will authenticate the current application with a remote endpoint. */ interface Credentials { /** * The user to authenticate with the remote endpoint. */ username: string; /** * The access token that will authenticate this user to the remote endpoint. */ accessToken: string; } /** * The details of the person who authored the changes of the commit. */ interface Author { /** * The name of the commit author. */ name?: string; /** * The e-mail address of the commit author. */ email?: string; } /** * Options that can be passed to a Git implementation's constructor. */ interface ConstructorOptions { /** * The credentials that will be used to interact with remote endpoints. */ credentials?: Credentials; /** * The details of the entity who may make commits. */ author?: Author; } /** * The result of getting the current commit SHA. */ interface CurrentCommitShaResult { /** * The SHA of the current commit. */ currentCommitSha?: string; } /** * Options that can be passed to "git merge". */ interface MergeOptions { /** * Commits, usually other branch heads, to merge into our branch. Specifying more than one * commit will create a merge with more than two parents (affectionately called an Octopus * merge). */ refsToMerge?: string | string[]; /** * Produce the working tree and index state as if a real merge happened (except for the merge * information), but do not actually make a commit, move the HEAD, or record $GIT_DIR/MERGE_HEAD * (to cause the next git commit command to create a merge commit). */ squash?: boolean; /** * Invoke an editor before committing successful mechanical merge to further edit the * auto-generated merge message, so that the user can explain and justify the merge. */ edit?: boolean; /** * The options that will be passed to the merge strategy. */ strategyOptions?: string | string[]; /** * Operate quietly. Implies --no-progress. */ quiet?: boolean; /** * Set the commit messages to be used for the merge commit (in case one is created). */ messages?: string | string[]; } /** * Options that can be passed to "git rebase". */ interface RebaseOptions { /** * Working branch; defaults to HEAD. */ branch?: string; /** * Upstream branch to compare against. May be any valid commit, not just an existing branch * name. Defaults to the configured upstream for the current branch. */ upstream?: string; /** * Starting point at which to create the new commits. If the --onto option is not specified, the * starting point is <upstream>. May be any valid commit, and not just an existing branch name. * As a special case, you may use "A...B" as a shortcut for the merge base of A and B if there * is exactly one merge base. You can leave out at most one of A and B, in which case it * defaults to HEAD. */ newbase?: string; /** * Use the given merge strategy. If there is no -s option git merge-recursive is used instead. * This implies --merge. * Because git rebase replays each commit from the working branch on top of the <upstream> * branch using the given strategy, using the ours strategy simply empties all patches from the * <branch>, which makes little sense. */ strategy?: string; /** * Pass the <strategy-option> through to the merge strategy. This implies --merge and, if no * strategy has been specified, -s recursive. Note the reversal of ours and theirs as noted * above for the -m option. */ strategyOption?: string; /** * Be quiet. Implies --no-stat. */ quiet?: boolean; /** * Be verbose. Implies --stat. */ verbose?: boolean; } /** * Options that can be passed to "git clone". */ interface CloneOptions { /** * Instead of using the remote name "origin" to keep track of the upstream repository, use this value. */ origin?: string; /** * Instead of pointing the newly created HEAD to the branch pointed to by the cloned repository’s * HEAD, point to this value's branch instead. In a non-bare repository, this is the branch that * will be checked out. This value can also take tags and detaches the HEAD at that commit in the * resulting repository. */ branch?: string; /** * Create a shallow clone with a history truncated to the specified number of commits. Implies * "single-branch"=true unless "no-single-branch"=true is given to fetch the histories near the * tips of all branches. If you want to clone submodules shallowly, also use * "shallow-submodules"=true. */ depth?: number; /** * The name of a new directory to clone into. The "humanish" part of the source repository is used * if no directory is explicitly given (repo for /path/to/repo.git and foo for host.xz:foo/.git). * Cloning into an existing directory is only allowed if the directory is empty. */ directory?: string; } /** * Options that can be passed to "git checkout". */ interface CheckoutOptions { /** * The name of the remote repository where the branch should be checked out from. */ remote?: string; /** * The name to use for the local branch. */ localBranchName?: string; /** * Checkout and detached */ detach?: boolean; } /** * The options for determining how pushing the current branch will run. */ interface PushOptions { /** * The name of the branch to push. */ branchName?: string; /** * The credentials that will be used to push the changes. */ credentials?: Credentials; /** * Whether or not to force the remote repository to accept this push's changes. */ force?: boolean; } /** * The options that can be passed to createLocalBranch(). */ interface CreateLocalBranchOptions { /** * The reference point that the new branch will be created from. */ startPoint?: string; } /** * The options for determining how this command will run. */ interface DeleteRemoteBranchOptions { /** * The name of the tracked remote repository. Defaults to "origin". */ remoteName?: string; } /** * Options that can be passed to `git diff`. */ interface DiffOptions { /** * The unique identifier for a commit to compare. If this is specified but commit2 is not * specified, then this commit will be compared against HEAD. */ commit1?: string; /** * The unique identifier for a commit to compare. If this is specified but commit1 is not * specified, then this commit will be compared against HEAD. */ commit2?: string; /** * Show only the names of changed files. */ nameOnly?: boolean; /** * Whether or not to ignore whitespace changes in the diff, and if provided, to what extent should * whitespace changes be ignored. */ ignoreSpace?: "at-eol" | "change" | "all"; /** * Whether or not to show all changes that are staged. */ staged?: boolean; } /** * The result of a "git diff" command. */ interface DiffResult { /** * The files that are reported as being changed by the diff command. */ filesChanged: string[]; } /** * The result of getting the local branches in the repository. */ interface LocalBranchesResult { /** * The local branches in the repository. */ localBranches: string[]; /** * The current branch that is checked out. */ currentBranch: string; } /** * The return type of getting a remote repository's branches. */ interface RemoteBranchesResult { /** * The branches in remote repositories. */ remoteBranches: GitRemoteBranch[]; } /** * The result of getting the status of the current branch. */ interface StatusResult { /** * The current local branch. */ localBranch?: string; /** * The remote tracking branch for the current local branch. */ remoteBranch?: string; /** * Whether or not the current local branch has uncommitted changes. */ hasUncommittedChanges: boolean; /** * Staged, not staged, and untracked files that have either been modified, added, or deleted. */ modifiedFiles: string[]; /** * Files that have been modified and staged. */ stagedModifiedFiles: string[]; /** * Files that have been deleted and staged. */ stagedDeletedFiles: string[]; /** * Files that have been modified but not staged yet. */ notStagedModifiedFiles: string[]; /** * Files that have been deleted but not staged yet. */ notStagedDeletedFiles: string[]; /** * Files that don't currently exist in the repository. */ untrackedFiles: string[]; } /** * The result of getting a git configuration value. */ interface GetConfigurationValueResult { /** * The requested configuration value or undefined if the value was not found. */ configurationValue?: string; } /** * The options that can be passed to a `git commit` operation. */ interface CommitOptions { /** * The details of the person who authored the changes of the commit. */ author?: Author; } /** * The result of listing the remote repositories referenced by this local repository. */ interface ListRemotesResult { /** * The remote repositories referenced by this local repository. */ remotes: StringMap<string>; } interface StashOptions { pop?: boolean; keepIndex?: boolean; all?: boolean; } } /** * An interface for interacting with Git repositories. */ export interface Git { /** * Get the SHA of the currently checked out commit. */ currentCommitSha(): Promise<Git.CurrentCommitShaResult>; /** * Download objects and refs from another repository. */ fetch(): Promise<unknown>; /** * Merge The provided references (branches or tags) into the current branch using the provided * options. * @param options Options that can be passed to "git merge". */ merge(options?: Git.MergeOptions): Promise<unknown>; /** * Reapply commits on top of another base tip. * @param options Options that can be passed to "git rebase". */ rebase(options?: Git.RebaseOptions): Promise<unknown>; /** * Clone the repository with the provided URI. * @param gitUri The repository URI to clone. * @param options The options that can be passed to "git clone". */ clone(gitUri: string, options?: Git.CloneOptions): Promise<unknown>; /** * Checkout the provided git reference (branch, tag, or commit ID) in the repository. * @param refId The git reference to checkout. * @param options The options that can be passed to "git checkout". */ checkout(refId: string, options?: Git.CheckoutOptions): Promise<unknown>; /** * Pull the latest changes for the current branch from the registered remote branch. */ pull(): Promise<unknown>; /** * Push the current branch to the remote tracked repository. * @param options The options for determining how this command will run. */ push(options?: Git.PushOptions): Promise<unknown>; /** * Add/stage the provided files. * @param filePaths The paths to the files to stage. */ add(filePaths: string | string[]): Promise<unknown>; /** * Add/stage all of the current unstaged files. * @param options The options that determine how this command will run. */ addAll(): Promise<unknown>; /** * Commit the currently staged/added changes to the current branch. * @param commitMessages The commit messages to apply to this commit. */ commit(commitMessages: string | string[], options?: Git.CommitOptions): Promise<unknown>; /** * Delete a local branch. * @param branchName The name of the local branch to delete. */ deleteLocalBranch(branchName: string): Promise<unknown>; /** * Create a new local branch with the provided name. * @param branchName The name of the new branch. */ createLocalBranch(branchName: string): Promise<unknown>; /** * Remote the provided branch from the provided tracked remote repository. * @param branchName The name of the remote branch to delete. * @param remoteName The name of the tracked remote repository. * @param options The options for determining how this command will run. */ deleteRemoteBranch(branchName: string, options?: Git.DeleteRemoteBranchOptions): Promise<unknown>; /** * Get the diff between two commits. * @options The options for determining how this command will run. */ diff(options?: Git.DiffOptions): Promise<Git.DiffResult>; /** * Get the branches that are local to this repository. */ localBranches(): Promise<Git.LocalBranchesResult>; /** * Get the branch that the repository is currently on. */ currentBranch(): Promise<string>; /** * Get the remote branches that this repository clone is aware of. */ remoteBranches(): Promise<Git.RemoteBranchesResult>; /** * Run "git status". */ status(): Promise<Git.StatusResult>; /** * Get the configuration value for the provided configuration value name. * @param configurationValueName The name of the configuration value to get. */ getConfigurationValue(configurationValueName: string): Promise<Git.GetConfigurationValueResult>; /** * Get the URL of the current repository. * @param options The options that can configure how the command will run. */ getRepositoryUrl(): Promise<string | undefined>; /** * Unstage all staged files. * @param options The options that can configure how the command will run. */ resetAll(): Promise<unknown>; /** * Add the provided remote URL to this local repository's list of remote repositories using the * provided remoteName. * @param remoteName The name/reference that will be used to refer to the remote repository. * @param remoteUrl The URL of the remote repository. */ addRemote(remoteName: string, remoteUrl: string): Promise<unknown>; /** * Get the URL associated with the provided remote repository. * @param remoteName The name of the remote repository. * @returns The URL associated with the provided remote repository or undefined if the remote name * is not found. */ getRemoteUrl(remoteName: string): Promise<string | undefined>; /** * Set the URL associated with the provided remote repository. * @param remoteName The name of the remote repository. * @param remoteUrl The URL associated with the provided remote repository. */ setRemoteUrl(remoteName: string, remoteUrl: string): Promise<unknown>; /** * Get the remote repositories that are referenced in this local repository. */ listRemotes(): Promise<Git.ListRemotesResult>; stash(options: ExecutableGit.StashOptions): Promise<ExecutableGit.Result>; } /** * A set of interfaces and types that relate to the ExecutableGit class. */ export declare namespace ExecutableGit { /** * A set of optional properties that can be applied to an ExecutableGit operation. */ interface Options extends RunOptions { /** * Whether or not to use a pager in the output of the "git diff" operation. */ usePager?: boolean; /** * The file path to the git executable to use to run commands. This can be either a rooted path * to the executable, or a relative path that will use the environment's PATH variable to * resolve the executable's location. */ gitFilePath?: string; } /** * A set of optional properties that can be applied to the ExecutableGit constructor. */ interface ConstructorOptions extends Options { /** * The authentication section that will be inserted into remote repository URLs. This can be * either a string (the authentication token that will be inserted into every remote * repository's URL), or a StringMap<string> where the entry's key is a scope and the entry's * value is the authentication token that will be inserted into remote repository URLs that * match the scope. The scope can be either the repository's owner or the full repository * name (<owner>/<repository-name>). */ authentication?: string | StringMap<string> | ((scope: string) => Promise<string | undefined>); } /** * The result of running a git operation. */ interface Result extends RunResult { /** * The error that occurred while running the git operation. */ error?: Error; } /** * The result of running `git rev-parse HEAD`. */ interface CurrentCommitShaResult extends Git.CurrentCommitShaResult, Result { } /** * Options that can be passed to `git fetch`. */ interface FetchOptions extends Options { /** * Before fetching, remove any remote-tracking references that no longer exist on the remote. Tags * are not subject to pruning if they are fetched only because of the default tag auto-following * or due to a --tags option. However, if tags are fetched due to an explicit refspec (either on * the command line or in the remote configuration, for example if the remote was cloned with the * --mirror option), then they are also subject to pruning. Supplying --prune-tags is a shorthand * for providing the tag refspec. */ prune?: boolean; /** * Whether or not to fetch branch updates about all known remote repositories. */ all?: boolean; /** * Set depth to 1 to use shallow fetch */ depth?: number; /** * Name of the remote repo to fetch */ remoteName?: string; /** * refspec to be fetched */ refSpec?: string; } interface ResetOptions extends Options { hard?: boolean; soft?: boolean; target?: string; } /** * Options that can be passed to "git merge". */ interface MergeOptions extends Git.MergeOptions, Options { } /** * Options that can be passed to "git rebase". */ interface RebaseOptions extends Git.RebaseOptions, Options { } /** * Options that can be passed to "git clone". */ interface CloneOptions extends Git.CloneOptions, Options { /** * Operate quietly. Progress is not reported to the standard error stream. */ quiet?: boolean; /** * Run verbosely. Does not affect the reporting of progress status to the standard error stream. */ verbose?: boolean; } /** * Options that can be passed to "git checkout". */ interface CheckoutOptions extends Git.CheckoutOptions, Options { } /** * The result of attempting to run `git checkout`. */ interface CheckoutResult extends Result { /** * Get the files that would've been overwritten if this checkout operation had taken place. This * property will only be populated in an error scenario. */ filesThatWouldBeOverwritten?: string[]; } /** * The options for determining how pushing the current branch will run. */ interface PushOptions extends Git.PushOptions, Options { /** * The upstream repository to push to if the current branch doesn't already have an upstream * branch. */ setUpstream?: boolean | string; } /** * Options that modify how a "git commit" operation will run. */ interface CommitOptions extends Options { /** * Whether or not pre-commit checks will be run. */ noVerify?: boolean; } /** * The options that can be passed to createLocalBranch(). */ interface CreateLocalBranchOptions extends Git.CreateLocalBranchOptions, Options { } /** * Options that can be passed to `git push <remote> :<branch-name>`. */ interface DeleteRemoteBranchOptions extends Git.DeleteRemoteBranchOptions, Options { } /** * Options that can be passed to `git diff`. */ interface DiffOptions extends Git.DiffOptions, Options { } /** * The result of a "git diff" command. */ interface DiffResult extends Git.DiffResult, Result { } /** * The result of getting the local branches in the repository. */ interface LocalBranchesResult extends Git.LocalBranchesResult, Result { /** * The current branch that is checked out. */ currentBranch: string; } /** * The return type of getting a remote repository's branches. */ interface RemoteBranchesResult extends Git.RemoteBranchesResult, Result { } /** * The result of getting the status of the current branch. */ interface StatusResult extends Git.StatusResult, Result { } /** * The result of getting a git configuration value. */ interface GetConfigurationValueResult extends Git.GetConfigurationValueResult, Result { } /** * The options that can be passed to a `git commit` operation. */ interface CommitOptions extends Git.CommitOptions, Options { } /** * The result of listing the remote repositories referenced by this local repository. */ interface ListRemotesResult extends Git.ListRemotesResult, Result { } interface StashOptions extends Git.StashOptions, Options { } } /** * An implementation of Git that uses a Git executable to run commands. */ export declare class ExecutableGit implements Git { private readonly options; private authenticationStrings; /** * Create a new ExecutableGit object. * @param gitFilePath The file path to the git executable to use to run commands. This can be * either a rooted path to the executable, or a relative path that will use the environment's PATH * variable to resolve the executable's location. * @param options The optional arguments that will be applied to each operation. */ constructor(options?: ExecutableGit.ConstructorOptions); private maskAuthenticationInLog; private addAuthenticationToURL; /** * Create a new ExecutableGit object that combines this ExecutableGit's options with the provieded * options. * @param options The options to combine with this ExecutableGit's options. */ scope(options: ExecutableGit.ConstructorOptions): ExecutableGit; /** * Run an arbitrary Git command. * @param args The arguments to provide to the Git executable. */ run(args: string[], options?: ExecutableGit.Options): Promise<ExecutableGit.Result>; /** * Get the SHA of the currently checked out commit. */ currentCommitSha(options?: ExecutableGit.Options): Promise<ExecutableGit.CurrentCommitShaResult>; /** * Download objects and refs from another repository. * @param options The options that can be passed to `git fetch`. */ fetch(options?: ExecutableGit.FetchOptions): Promise<ExecutableGit.Result>; merge(options?: ExecutableGit.MergeOptions): Promise<ExecutableGit.Result>; rebase(options?: ExecutableGit.RebaseOptions): Promise<ExecutableGit.Result>; /** * Clone the repository with the provided URI. * @param gitUri The repository URI to clone. * @param options The options that can be passed to "git clone". */ clone(gitUri: string, options?: ExecutableGit.CloneOptions): Promise<ExecutableGit.Result>; /** * Init git repo. * @param options Options */ init(options?: ExecutableGit.Options): Promise<ExecutableGit.Result>; symbolicRef(name: string, ref?: string, options?: ExecutableGit.Options): Promise<ExecutableGit.Result>; /** * Checkout the provided git reference (branch, tag, or commit ID) in the repository. * @param refId The git reference to checkout. */ checkout(refId: string, options?: ExecutableGit.CheckoutOptions): Promise<ExecutableGit.CheckoutResult>; /** * Pull the latest changes for the current branch from the registered remote branch. */ pull(options?: ExecutableGit.Options): Promise<ExecutableGit.Result>; /** * Push the current branch to the remote tracked repository. * @param options The options for determining how this command will run. */ push(options?: ExecutableGit.PushOptions): Promise<ExecutableGit.Result>; /** * Add/stage the provided files. * @param filePaths The paths to the files to stage. * @param options The options for determining how this command will run. */ add(filePaths: string | string[], options?: ExecutableGit.Options): Promise<ExecutableGit.Result>; /** * Add/stage all of the current unstaged files. * @param options The options that determine how this command will run. */ addAll(options?: ExecutableGit.Options): Promise<ExecutableGit.Result>; /** * Commit the currently staged/added changes to the current branch. * @param commitMessages The commit messages to apply to this commit. * @param options The options that determine how this command will run. */ commit(commitMessages: string | string[], options?: ExecutableGit.CommitOptions): Promise<ExecutableGit.Result>; /** * Delete a local branch. * @param branchName The name of the local branch to delete. */ deleteLocalBranch(branchName: string, options?: ExecutableGit.Options): Promise<ExecutableGit.Result>; /** * Create a new local branch with the provided name. * @param branchName The name of the new branch. * @param options The options for determining how this command will run. */ createLocalBranch(branchName: string, options?: ExecutableGit.CreateLocalBranchOptions): Promise<ExecutableGit.Result>; /** * Remote the provided branch from the provided tracked remote repository. * @param branchName The name of the remote branch to delete. * @param remoteName The name of the tracked remote repository. * @param options The options for determining how this command will run. */ deleteRemoteBranch(branchName: string, options?: ExecutableGit.DeleteRemoteBranchOptions): Promise<ExecutableGit.Result>; diff(options?: ExecutableGit.DiffOptions): Promise<ExecutableGit.DiffResult>; /** * Get the branches that are local to this repository. */ localBranches(options?: ExecutableGit.Options): Promise<ExecutableGit.LocalBranchesResult>; /** * Get the branch that the repository is currently on. * @param options The options to run this command with. */ currentBranch(options?: ExecutableGit.Options): Promise<string>; /** * Get the remote branches that this repository clone is aware of. * @param options The options to run this command with. */ remoteBranches(options?: ExecutableGit.Options): Promise<ExecutableGit.RemoteBranchesResult>; stash(options?: ExecutableGit.StashOptions): Promise<ExecutableGit.Result>; /** * Reset a local git repo, possible with existing git data. * Delete all the branches and all the remotes. * Use this function to reuse existing git repo data to accelerate fetching. */ resetRepoFolder(): Promise<void>; /** * Run "git status". */ status(options?: ExecutableGit.Options): Promise<ExecutableGit.StatusResult>; /** * Get the configuration value for the provided configuration value name. * @param configurationValueName The name of the configuration value to get. * @param options The options that can configure how the command will run. */ getConfigurationValue(configurationValueName: string, options?: ExecutableGit.Options): Promise<ExecutableGit.GetConfigurationValueResult>; /** * Get the URL of the current repository. * @param options The options that can configure how the command will run. */ getRepositoryUrl(options?: ExecutableGit.Options): Promise<string | undefined>; /** * Reset all the file. * @param options The options that can configure how the command will run. */ resetAll(options?: ExecutableGit.ResetOptions): Promise<ExecutableGit.Result>; /** * Add the provided remote URL to this local repository's list of remote repositories using the * provided remoteName. * @param remoteName The name/reference that will be used to refer to the remote repository. * @param remoteUrl The URL of the remote repository. * @param options Options that can be used to modify the way that this operation is run. */ addRemote(remoteName: string, remoteUrl: string, options?: ExecutableGit.Options): Promise<ExecutableGit.Result>; /** * Remove git remote repository * @param remoteName The name of the remote repository to be removed * @param options Options */ removeRemote(remoteName: string, options?: ExecutableGit.Options): Promise<ExecutableGit.Result>; /** * Get the URL associated with the provided remote repository. * @param remoteName The name of the remote repository. * @returns The URL associated with the provided remote repository or undefined if the remote name * is not found. */ getRemoteUrl(remoteName: string, options?: ExecutableGit.Options): Promise<string | undefined>; /** * Set the URL associated with the provided remote repository. * @param remoteName The name of the remote repository. * @param remoteUrl The URL associated with the provided remote repository. */ setRemoteUrl(remoteName: string, remoteUrl: string, options?: ExecutableGit.Options): Promise<ExecutableGit.Result>; refreshRemoteAuthentication(): Promise<ExecutableGit.ListRemotesResult>; /** * Get the remote repositories that are referenced in this local repository. */ listRemotes(options?: ExecutableGit.Options): Promise<ExecutableGit.ListRemotesResult>; } /** * Get the files that have changed based on the provided full diff text result. * @param text The text of the full diff. * @param currentFolder The folder that the diff-ed files should be resolved against. */ export declare function getFilesChangedFromFullDiff(text: string | string[], currentFolder?: string): string[]; /** * Get a GitRemoteBranch from the provided label. Labels usually follow the format * "<repository-tracking-name>:<branch-name>", such as "origin:master". * @param label The string or GitRemoteBranch to convert to a GitRemoteBranch. */ export declare function getGitRemoteBranch(label: string | GitRemoteBranch): GitRemoteBranch; /** * A branch from a tracked remote repository. */ export interface GitRemoteBranch { /** * The tracking name of the remote repository, such as "origin". */ repositoryTrackingName: string; /** * The name of the branch. */ branchName: string; } /** * Get the full name of the provided remote branch. * @param remoteBranch The remote branch to get the full name of. */ export declare function getRemoteBranchFullName(remoteBranch: string | GitRemoteBranch): string; //# sourceMappingURL=git.d.ts.map