/*! * Copyright (c) Microsoft Corporation and contributors. All rights reserved. * Licensed under the MIT License. */ import type { Package } from "@fluidframework/build-tools"; import { type SimpleGit, type SimpleGitOptions } from "simple-git"; import type { SetRequired } from "type-fest"; import type { IReleaseGroup } from "@fluid-tools/build-infrastructure"; import type { CommandLogger } from "../logging.js"; import type { ReleaseGroup } from "../releaseGroups.js"; import { type Context, type VersionDetails } from "./context.js"; /** * Get all the versions for a release group. This function only considers the tags in the repo. * * @param git - The git repository. * @param releaseGroup - The release group to get versions for. * @returns List of version details, or undefined if one could not be found. */ export declare function getVersionsFromTags(git: Readonly, releaseGroup: IReleaseGroup, tags?: string[]): Promise; /** * A type of string used to denote a GitHub repo by owner and repo name. */ export type GitHubRepoShortString = `${string}/${string}`; /** * Context object with metadata about the local Git repository. This is used by CLI commands that need access to * relevant metadata that can't be queried from Git itself, such as the `upstreamRemotePartialUrl`. */ export interface GitContext { /** * A string of the form "OWNER/REPO" that is a substring of the full URL to an upstream remote repository on GitHub. * If a remote is found that partially matches this string, it will be considered the upstream remote. */ upstreamRemotePartialUrl: Readonly; /** * The branch name when the Git context was initialized. */ originalBranchName: Readonly; /** * New branches created since this context was initialized. */ newBranches: string[]; } /** * A small wrapper around a git repo to provide API access to it. * * @remarks * * Eventually this should replace the legacy GitRepo class in build-tools. That class exec's git commands directly, * while this class uses a library wrapper around git where possible instead. Note that git is still called "directly" via the `raw` API. * * @internal */ export declare class Repository implements GitContext { readonly upstreamRemotePartialUrl: GitHubRepoShortString; protected readonly log?: CommandLogger | undefined; private readonly git; /** * A git client for the repository that can be used to call git directly. */ get gitClient(): SimpleGit; readonly originalBranchName: string; readonly newBranches: string[]; constructor(gitOptions: SetRequired, "baseDir">, upstreamRemotePartialUrl: GitHubRepoShortString, log?: CommandLogger | undefined); /** * Returns the SHA hash for a branch. If a remote is provided, the SHA for the remote ref is returned. */ getShaForBranch(branch: string, remote?: string): Promise; /** * Get the remote based on the partial Url. It will match the first remote that contains the partialUrl case * insensitively. * * @param partialUrl - partial url to match case insensitively */ getRemote(partialUrl: string): Promise; /** * Get the merge base between the current HEAD and the remote branch. * * @param branch - The branch to compare against. * @param remote - The remote to compare against. * @param localRef - The local ref to compare against. Defaults to HEAD. * @returns The ref of the merge base between the current HEAD and the remote branch. */ getMergeBaseRemote(branch: string, remote: string, localRef?: string): Promise; /** * Get the merge base between two refs. * * @param ref1 - The first ref to compare. * @param ref2 - The ref to compare against. * @returns The ref of the merge base between the two refs. */ getMergeBase(ref1: string, ref2: string): Promise; private getChangedFilesSinceRef; private getChangedDirectoriesSinceRef; /** * Gets the changed files, directories, release groups, and packages since the given ref. * * @param ref - The ref to compare against. * @param remote - The remote to compare against. * @param context - The Context. * @returns An object containing the changed files, directories, release groups, and packages. The groups may overlap. * That is, if a single package in a release group is changed, the releaseGroups value will contain that group, and * the packages value will contain only the single package. Also, if two packages are changed, one within a release * group and one independent, the packages value will contain both packages. */ getChangedSinceRef(ref: string, remote: string, context: Context): Promise<{ files: string[]; dirs: string[]; releaseGroups: ReleaseGroup[]; packages: Package[]; }>; /** * Calls `git rev-list` to get all commits between the base and head commits. * * @param baseCommit - The base commit. * @param headCommit - The head commit. Defaults to HEAD. * @returns An array of all commits between the base and head commits. */ revList(baseCommit: string, headCommit?: string): Promise; canMergeWithoutConflicts(commit: string): Promise; /** * Returns an array containing repo repo-relative paths to all the files in the provided directory. * A given path will only be included once in the array; that is, there will be no duplicate paths. * Note that this function excludes files that are deleted locally whether the deletion is staged or not. * * @param directory - A directory to filter the results by. Only files under this directory will be returned. To * return all files in the repo use the value `"."`. */ getFiles(directory: string): Promise; /** * Map of release group/package name to all the git tags for the group/package. */ private readonly _tags; /** * Returns an array of all the git tags associated with a release group. * * @param releaseGroupOrPackage - The release group or independent package to get tags for. * @returns An array of all all the tags for the release group or package. */ getTagsForReleaseGroup(releaseGroupOrPackage: string): Promise; private readonly _versions; /** * Gets all the versions for a release group or independent package. This function only considers the tags in the * repo to determine releases and dates. * * @param releaseGroupOrPackage - The release group or independent package to get versions for. * @returns An array of {@link VersionDetails} containing the version and date for each version. */ getAllVersions(releaseGroupOrPackage: string): Promise; /** * Create a branch with the specified name. Throw an error if the branch already exists. */ createBranch(branchName: string): Promise; getCurrentSha(): Promise; /** * Get the current git branch name */ getCurrentBranchName(): Promise; isBranchUpToDate(branch: string, remote: string): Promise; /** * Fetch branch */ fetchBranch(remote: string, branchName: string): Promise; } /** * Finds the current branch of a Git repository synchronously. * * This function uses `git rev-parse --abbrev-ref HEAD` command to find the current branch name. It executes the command * synchronously using `child_process.execFileSync`. If the current directory is not part of a Git repository, it throws * an error. * * @param cwd - The directory from which we should try to get the current Git branch. * @returns The name of the current branch. * @throws Error If `cwd` is not part of a Git repository. */ export declare function getCurrentBranchNameSync(cwd?: string): string; //# sourceMappingURL=git.d.ts.map