https://github.com/cyansalt/git9
Utilities for Git
https://github.com/cyansalt/git9
Last synced: 4 months ago
JSON representation
Utilities for Git
- Host: GitHub
- URL: https://github.com/cyansalt/git9
- Owner: CyanSalt
- License: isc
- Created: 2024-06-06T02:36:19.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2025-11-28T02:29:39.000Z (8 months ago)
- Last Synced: 2025-11-29T08:46:01.112Z (8 months ago)
- Language: TypeScript
- Size: 302 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# git9
[](https://www.npmjs.com/package/git9)

Utilities (How many letters?) for Git.
## Installation
```shell
npm install --save git9
```
## Usage
```js
import {
getCommit,
getCurrentCommit,
hasCommit,
isMerging,
hasConflicts,
getBranch,
getCurrentBranch,
getRootDirectory,
getConfig,
getRemoteURL,
getRemoteCommit,
getDifferences,
getChangedFiles,
downloadFile,
} from 'git9'
```
This module is implemented with [quansync](https://github.com/quansync-dev/quansync), so all of these functions have both asynchronous and synchronous versions, and even _uncollapsed quantum_ versions. Therefore, you can use them in any of the following ways:
```ts
// 1. Simple asynchronous version
const commit = await getCommit('HEAD')
// 2. Explicit asynchronous version
const commit = await getCommit.async('HEAD')
// 3. Synchronous version
const commit = getCommit.sync('HEAD')
// 4. Uncollapsed quantum version
const fn = quansync(function* () {
const commit = yield* getCommit('HEAD')
})
```
By default, all functions execute based on `process.cwd()`. If you want to execute based on a different directory, you can use `this` binding as follows:
```ts
// Use any of the following versions
const commit = await getCommit.call({ cwd: anotherPath }, 'HEAD')
const commit = await getCommit.async.call({ cwd: anotherPath }, 'HEAD')
const commit = getCommit.sync.call({ cwd: anotherPath }, 'HEAD')
```
### `getCommit`
```ts
function getCommit(committish: string): Promise
```
Get commit hash with a commit-ish string.
### `getCurrentCommit`
```ts
function getCurrentCommit(): Promise
```
Get commit hash of the current branch.
### `hasCommit`
```ts
function hasCommit(committish: string): Promise
```
Check whether a specified branch or pointer exists.
### `isMerging`
```ts
function isMerging(): Promise
```
Check whether the working repository is in the merging state. Equivalent to `hasCommit('MERGE_HEAD')`.
### `hasConflicts`
```ts
function hasConflicts(subpath?: string): Promise
```
Check whether the working repository has conflicts.
### `getBranch`
```ts
function getBranch(committish: string): Promise
```
Get the branch name of a commit-ish.
### `getCurrentBranch`
```ts
function getCurrentBranch(): Promise
```
Get the current branch name. Equivalent to `getBranch('HEAD')`.
### `getRootDirectory`
```ts
function getRootDirectory(): Promise
```
Get the root directory of the repository.
### `getConfig`
```ts
function getConfig(config: string): Promise
```
Get specified config value of the repository.
### `getRemoteURL`
```ts
function getRemoteURL(name: string): Promise
```
Get remote repository URL with specified name.
### `getRemoteCommit`
```ts
function getRemoteCommit(url: string, committish: string): Promise
```
Get commit hash with a commit-ish string from remote.
### `getDifferences`
```ts
function getDifferences(committish: string): Promise<{
name: string;
status: string;
}[]>
```
Get differences between the current branch and the specified commit-ish.
> Possible status letters are:
> - A: addition of a file
> - C: copy of a file into a new one
> - D: deletion of a file
> - M: modification of the contents or mode of a file
> - R: renaming of a file
> - T: change in the type of the file (regular file, symbolic link or submodule)
> - U: file is unmerged (you must complete the merge before it can be committed)
> - X: "unknown" change type (most probably a bug, please report it)
See [git-diff](https://git-scm.com/docs/git-diff).
### `getChangedFiles`
```ts
function getChangedFiles(committish: string): Promise
```
Get changed files in current branch from the specified commit-ish.
### `downloadFile`
```ts
function downloadFile(url: string, committish: string, file: string): Promise
```
Download specified file with a commit-ish string from remote using git-archive protocol.
> [!NOTE]
> GitHub does not support git-archive protocol.