Skip to content

oneRepo API: git

Special handlers for managing complex queries and manipulation of the git repository’s state.

new StagingWorkflow(options): StagingWorkflow

Parameters:

ParameterTypeDescription
optionsObject-
options.graphGraphThe repository Graph
options.loggerLoggerLogger instance to use for all actions

Returns: StagingWorkflow
Source: modules/git/src/workflow.ts

restoreUnstaged(): Promise<void>

Restores the unstaged changes previously backed up by saveUnstaged().

This command will go through a series of attempts to ressurect upon failure, eventually throwing an error if unstaged changes cannot be reapplied.

Returns: Promise<void>
Source: modules/git/src/workflow.ts

saveUnstaged(): Promise<void>

Backup any unstaged changes, whether that’s full files or parts of files. This will result in the git status only including what was already in the stage. All other changes will be backed up to:

  1. A patch file in the .git/ directory
  2. A git stash

To restore the unstaged changes, call restoreUnstaged().

Returns: Promise<void>
Source: modules/git/src/workflow.ts

type ModifiedFromThrough: {
from: string;
staged: false;
through: string;
};
optional from: string;

Git ref for start (exclusive) to get list of modified files

optional staged: false;

Cannot include staged files when using from/through refs.

optional through: string;

Git ref for end (inclusive) to get list of modified files

Source: modules/git/src/index.ts


type ModifiedStaged: {
from: never;
staged: true;
through: never;
};
optional from: never;

Disallowed when staged: true

staged: true;

Get staged modified files only

optional through: never;

Disallowed when staged: true

Source: modules/git/src/index.ts


type Options: {
step: LogStep;
};

Generic options passed to all Git operations.

optional step: LogStep;

Avoid creating a new step in output for each function. Pass a Logger Step to pipe all logs and output to that instead.

Source: modules/git/src/index.ts


type UpdateIndexOptions: Options & {
immediately: boolean;
};
optional immediately: boolean;

Set whether to immediately add to the git index or defer until process shutdown

Default: false
Source: modules/git/src/index.ts

flushUpdateIndex(options?): Promise<void>

Write all pending files added using updateIndex() to the git index.

await git.flushUpdateIndex();

Parameters:

ParameterType
options?Options

Returns: Promise<void>
Source: modules/git/src/index.ts


getBranch(options?): Promise<string>

Get the name of the current branch. Equivalent to git rev-parse --abbrev-ref HEAD.

const currentBranch = await git.getBranch();

Parameters:

ParameterType
options?Options

Returns: Promise<string>
Source: modules/git/src/index.ts


getCurrentSha(options?): Promise<string>

Get the current sha ref. This is equivalent to git rev-parse HEAD.

const sha = await git.getCurrentSha();

Parameters:

ParameterType
options?Options

Returns: Promise<string>
Source: modules/git/src/index.ts


getMergeBase(options?): Promise<string>

Determine the git ref for merging the current working branch, sha, or ref, whichever that is. This function does a bunch of internal checks to determine the where the most likely point of forking happened.

const mergeBase = await getMergeBase();

Parameters:

ParameterType
options?Options

Returns: Promise<string>
Source: modules/git/src/index.ts


getModifiedFiles(modified?, options?): Promise<string[]>

Get a map of the currently modified files based on their status. If from and through are not provided, this will current merge-base determination to best get the change to the working tree using git diff and git diff-tree.

const changesSinceMergeBase = await git.getModifiedFiles();
const betweenRefs = await git.getModifiedFiles('v1.2.3', 'v2.0.0');

Parameters:

ParameterType
modified?ModifiedStaged | ModifiedFromThrough
options?Options

Returns: Promise<string[]>
Source: modules/git/src/index.ts


isClean(options?): Promise<boolean>

Check if the current git working state is clean.

const isClean = await git.isClean();
if (!isClean) {
// There are local modifications that have not yet been committed.
}

Parameters:

ParameterType
options?Options

Returns: Promise<boolean>
Source: modules/git/src/index.ts


updateIndex(paths, options?): Promise<string | undefined>

Add filepaths to the git index. Equivalent to git add [...files]. By default, this method will track the files that need to be added to the git index. It will only add files immediately if given the immediately option.

Use flushUpdateIndex() to write all tracked files the git index. This method is automatically called during the oneRepo command shutdown process, so you may not ever need to call this.

It is best to avoid immediately adding items to the git index to avoid race conditions which can drop git into a bad state, requiring users to manually delete their .git/index.lock file before continuing.

await git.updateIndex(['tacos.ts']);

Parameters:

ParameterType
pathsstring | string[]
options?UpdateIndexOptions

Returns: Promise<string | undefined>
Source: modules/git/src/index.ts