An open API service indexing awesome lists of open source software.

https://github.com/pierredemailly/node-git

Git API for node.js
https://github.com/pierredemailly/node-git

git nodejs

Last synced: 2 months ago
JSON representation

Git API for node.js

Awesome Lists containing this project

README

        

> Simple Git API for Node.js (ESM).

[![All Contributors](https://img.shields.io/badge/all_contributors-2-orange.svg?style=for-the-badge)](#contributors-)
[![npm version](https://img.shields.io/npm/v/@pierred/node-git.svg?style=for-the-badge)](https://npmjs.com/package/@pierred/node-git)
[![last commit](https://img.shields.io/github/last-commit/pierredemailly/node-git.svg?style=for-the-badge)](https://github.com/PierreDemailly/node-git/commits/main)

## Installation

```
npm i @pierred/node-git
```

## API

### `changesCount()`
Get the count of changes.

It does include changes that have been staged, which haven't.

It does not include changes that are untracked.

```ts
changesCount(): Promise
```

### `stagedCount()`

Get the count of changes that have been staged.

```ts
stagedCount(): Promise
```

### `commit(message[, options])`
Create a commit given one or multiple commit message(s).

```ts
commit(message: string | string[], options?: { skipHooks: boolean }): Promise
```
Example usage:

```ts
await commit("My Commit"); // execute `git commit -m "My Commit"`.
await commit(["My Commit", "My Second Commit"]); // execute `git commit -m "My Commit" -m "My Second Commit"`.
```

### `indexAll(options)`
Add current changes to the git staging area.

```ts
indexAll(options?: IndexAllOptions): Promise
```
### `indexAllCurrentDirectory(options)`
Add current changes of the current working directory to the git staging area.

```ts
indexAllCurrentDirectory(options?: indexAllCurrentDirectoryOptions): Promise
```
This method should not be used with Git V2.x without ignoreRemovals: true, because Git V2.x does include deleted files
by default. Git V1.x side, it doesn't support --ignore-removal flag, deleted files are
omitted as expected behavior.

### `indexFileOrDirectory(fileOrDirectory)`
Add standalone file or directory to the git staging area.

```ts
indexFileOrDirectory(fileOrDirectory: string): Promise
```

### `indexFilesOrDirectories(filesOrDirectories)`
Add multiple files or directories to the git staging area.

```ts
indexFilesOrDirectories(filesOrDirectories: string[]): Promise
```
### `logs()`
Get the list of all commits for the current branch.

```ts
logs(): Promise
```

### `push()`
Push to remote.

```ts
push(): Promise
```

### `restoreFile(file)`
Remove given file from the git staging area.

```ts
restoreFile(file: string): Promise
```

### `currentBranch()`
Retrieve current branch name.

```ts
currentBranch(): Promise
```

### `init()`
Initialize a git repository.
If git is already initialized, it will prompt for a confirmation.

```ts
init(): Promise;
```

### `currentAuthor()`
Get the current author to the format `name ` (based on Git configuration).

```ts
currentAuthor(): Promise;
```

## Types

### IndexAllOptions
```ts
interface IndexAllOptions {
omitNewFiles: boolean;
}
```
Whether omit to index new files.
Setting it to true will execute git add -u.

### indexAllCurrentDirectoryOptions
```ts
interface indexAllCurrentDirectoryOptions {
ignoreRemovals: boolean;
}
```
Whether omit to index deleted files.
Setting it to true will execute git add . --ignore-removal.

### CommitMergeResult
```ts
interface CommitMergeResult {
from: string;
to: string;
}
```
Represents the result of a merge commit.

### CommitAuthor
```ts
interface CommitAuthor {
name: string;
email: string;
}
```
Represents a commit author: name & email.

### Commit
```ts
interface Commit {
commit: string,
merged: null | CommitMergeResult,
author: CommitAuthor,
date: string,
message: string[]
}
```
Represent a commit.

## Contributors ✨

Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):



PierreD
PierreD

💻 ⚠️
Yefis
Yefis

💻 👀

This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!