oneRepo API: git
Special handlers for managing complex queries and manipulation of the git repositoryâs state.
Classes
Section titled ClassesStagingWorkflow
Section titled StagingWorkflowConstructors
Section titled Constructorsnew StagingWorkflow()
Section titled new StagingWorkflow()Parameters:
Parameter | Type | Description |
---|---|---|
options | { graph : Graph ; logger : Logger ; } | - |
options.graph | Graph | The repository Graph |
options.logger | Logger | Logger instance to use for all actions |
Returns: StagingWorkflow
Defined in: modules/git/src/workflow.ts
Methods
Section titled MethodsrestoreUnstaged()
Section titled restoreUnstaged()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
>
Defined in: modules/git/src/workflow.ts
saveUnstaged()
Section titled saveUnstaged()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:
- A patch file in the
.git/
directory - A git stash
To restore the unstaged changes, call `restoreUnstaged()`.
Returns: Promise
<void
>
Defined in: modules/git/src/workflow.ts
Type Aliases
Section titled Type AliasesModifiedBaseOptions<ByStatus>
Section titled ModifiedBaseOptions<ByStatus>Type Parameters
Section titled Type ParametersType Parameter | Default type |
---|---|
ByStatus extends boolean | false |
Type declaration
Section titled Type declarationallStatus?
Section titled allStatus?By default, this function will not return deleted
and unmerged
files unless either allStatus
or byStatus
is set to true
byStatus?
Section titled byStatus?Return modified files categorized by the type of modification (added, deleted, modified, etc)
Defined in: modules/git/src/index.ts
ModifiedByStatus
Section titled ModifiedByStatusThis type defines the different statuses of files when running a git-diff. More information around the file statuses can be found in the official git documentation for git-diff.
Type declaration
Section titled Type declarationadded
Section titled addedGit status A
: addition of a file
copied
Section titled copiedGit status C
: copy of a file into a new one
deleted
Section titled deletedGit status D
: deletion of a file
fileTypeChanged
Section titled fileTypeChangedGit status T
: change in the type of the file (regular file, symbolic link or submodule)
modified
Section titled modifiedGit status M
: modification of the contents or mode of a file
renamed
Section titled renamedGit status R
: renaming of a file
unknown
Section titled unknownGit status X
: addition of a file
unmerged
Section titled unmergedGit status U
: âunknownâ change type (most probably a bug, please report it)
Defined in: modules/git/src/index.ts
ModifiedFromThrough<ByStatus>
Section titled ModifiedFromThrough<ByStatus>Type declaration
Section titled Type declarationfrom?
Section titled from?Git ref for start (exclusive) to get list of modified files
staged?
Section titled staged?Cannot include staged
files when using from/through refs.
through?
Section titled through?Git ref for end (inclusive) to get list of modified files
Type Parameters
Section titled Type ParametersType Parameter |
---|
ByStatus extends boolean |
Defined in: modules/git/src/index.ts
ModifiedStaged<ByStatus>
Section titled ModifiedStaged<ByStatus>Type declaration
Section titled Type declarationfrom?
Section titled from?Disallowed when staged: true
staged
Section titled stagedGet staged modified files only
through?
Section titled through?Disallowed when staged: true
Type Parameters
Section titled Type ParametersType Parameter |
---|
ByStatus extends boolean |
Defined in: modules/git/src/index.ts
Options
Section titled OptionsGeneric options passed to all Git operations.
Type declaration
Section titled Type declarationstep?
Section titled step?Avoid creating a new step in output for each function. Pass a Logger Step to pipe all logs and output to that instead.
Defined in: modules/git/src/index.ts
UpdateIndexOptions
Section titled UpdateIndexOptionsType declaration
Section titled Type declarationimmediately?
Section titled immediately?Set whether to immediately add to the git index or defer until process shutdown
Default: false
Defined in: modules/git/src/index.ts
Functions
Section titled FunctionsflushUpdateIndex()
Section titled flushUpdateIndex()Write all pending files added using `updateIndex()` to the git index.
Parameters:
Parameter | Type |
---|---|
options ? | Options |
Returns: Promise
<void
>
Defined in: modules/git/src/index.ts
getBranch()
Section titled getBranch()Get the name of the current branch. Equivalent to git rev-parse --abbrev-ref HEAD
.
Parameters:
Parameter | Type |
---|---|
options ? | Options |
Returns: Promise
<string
>
Defined in: modules/git/src/index.ts
getCurrentSha()
Section titled getCurrentSha()Get the current sha ref. This is equivalent to git rev-parse HEAD
.
Parameters:
Parameter | Type |
---|---|
options ? | Options |
Returns: Promise
<string
>
Defined in: modules/git/src/index.ts
getMergeBase()
Section titled getMergeBase()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.
Parameters:
Parameter | Type |
---|---|
options ? | Options |
Returns: Promise
<string
>
Defined in: modules/git/src/index.ts
getModifiedFiles()
Section titled getModifiedFiles()Get a map of the currently modified files based on their status. If from
and through
are not provided, this will use merge-base determination to get the changes to the working tree using git diff
and git diff-tree
.
By default, this function will not return deleted
and unmerged
files. If you wish to include files with those statuses, set the option allStatus: true
or get a map of all files by status using byStatus: true
.
Get modified files categorized by modification type:
Will result in allChanges
equal to an object containing arrays of strings:
Type Parameters
Section titled Type ParametersType Parameter | Default type |
---|---|
ByStatus extends boolean | false |
Parameters:
Parameter | Type |
---|---|
modified ? | ModifiedStaged <ByStatus > | ModifiedFromThrough <ByStatus > |
options ? | Options |
Returns: Promise
<ByStatus
extends true
? ModifiedByStatus
: string
[]>
Defined in: modules/git/src/index.ts
isClean()
Section titled isClean()Check if the current git working state is clean.
Parameters:
Parameter | Type |
---|---|
options ? | Options |
Returns: Promise
<boolean
>
Defined in: modules/git/src/index.ts
updateIndex()
Section titled updateIndex()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.
Parameters:
Parameter | Type |
---|---|
paths | string | string [] |
options ? | UpdateIndexOptions |
Returns: Promise
<string
| undefined
>
Defined in: modules/git/src/index.ts