git.ts

view source

Declarations
#

27 declarations

git_check_clean_workspace
#

git.ts view source

(options?: SpawnOptions | undefined): Promise<string | null> import {git_check_clean_workspace} from '@fuzdev/fuz_util/git.js';

options?

type SpawnOptions | undefined
optional

returns

Promise<string | null>

an error message if the git workspace has any unstaged or uncommitted changes, or null if it's clean

git_check_fully_staged_workspace
#

git.ts view source

(options?: SpawnOptions | undefined): Promise<string | null> import {git_check_fully_staged_workspace} from '@fuzdev/fuz_util/git.js';

options?

type SpawnOptions | undefined
optional

returns

Promise<string | null>

an error message if the git workspace has any unstaged changes or untracked files, or null if fully staged

git_check_setting_pull_rebase
#

git.ts view source

(options?: SpawnOptions | undefined): Promise<boolean> import {git_check_setting_pull_rebase} from '@fuzdev/fuz_util/git.js';

Returns the global git config setting for pull.rebase.

options?

type SpawnOptions | undefined
optional

returns

Promise<boolean>

git_check_workspace
#

git.ts view source

(options?: SpawnOptions | undefined): Promise<GitWorkspaceStatus> import {git_check_workspace} from '@fuzdev/fuz_util/git.js';

Checks the git workspace status using a single git status --porcelain -z call. The -z format provides more reliable parsing by using NUL separators and avoiding escaping.

options?

type SpawnOptions | undefined
optional

returns

Promise<GitWorkspaceStatus>

git_checkout
#

git.ts view source

(branch: GitBranch, options?: SpawnOptions | undefined): Promise<GitBranch | null> import {git_checkout} from '@fuzdev/fuz_util/git.js';

Calls git checkout.

branch

options?

type SpawnOptions | undefined
optional

returns

Promise<GitBranch | null>

the previous branch name, if it changed

throws

  • Error - if the underlying git command fails

git_clone_locally
#

git.ts view source

(origin: GitOrigin, branch: GitBranch, source_dir: string, target_dir: string, options?: SpawnOptions | undefined): Promise<void> import {git_clone_locally} from '@fuzdev/fuz_util/git.js';

Clones a branch locally to another directory and updates the origin to match the source.

origin

branch

source_dir

type string

target_dir

type string

options?

type SpawnOptions | undefined
optional

returns

Promise<void>

git_current_branch_first_commit_hash
#

git.ts view source

(options?: SpawnOptions | undefined): Promise<string> import {git_current_branch_first_commit_hash} from '@fuzdev/fuz_util/git.js';

Returns the hash of the current branch's first commit.

options?

type SpawnOptions | undefined
optional

returns

Promise<string>

throws

  • Error - if the underlying git command fails

git_current_branch_name
#

git.ts view source

(options?: SpawnOptions | undefined): Promise<GitBranch> import {git_current_branch_name} from '@fuzdev/fuz_util/git.js';

Returns the current git branch name.

options?

type SpawnOptions | undefined
optional

returns

Promise<GitBranch>

throws

  • Error - if the underlying git command fails

git_current_commit_hash
#

git.ts view source

(branch?: string | undefined, options?: SpawnOptions | undefined): Promise<string | null> import {git_current_commit_hash} from '@fuzdev/fuz_util/git.js';

Returns the branch's latest commit hash.

branch?

type string | undefined
optional

options?

type SpawnOptions | undefined
optional

returns

Promise<string | null>

throws

  • Error - if the underlying git command fails

git_delete_local_branch
#

git.ts view source

(branch: GitBranch, options?: SpawnOptions | undefined): Promise<void> import {git_delete_local_branch} from '@fuzdev/fuz_util/git.js';

Deletes a branch locally.

branch

options?

type SpawnOptions | undefined
optional

returns

Promise<void>

throws

  • Error - if the underlying git command fails

git_delete_remote_branch
#

git.ts view source

(origin: GitOrigin, branch: GitBranch, options?: SpawnOptions | undefined): Promise<void> import {git_delete_remote_branch} from '@fuzdev/fuz_util/git.js';

Deletes a branch remotely.

origin

branch

options?

type SpawnOptions | undefined
optional

returns

Promise<void>

throws

  • Error - if the underlying git command fails

git_fetch
#

git.ts view source

(origin?: GitOrigin, branch?: GitBranch | undefined, options?: SpawnOptions | undefined): Promise<void> import {git_fetch} from '@fuzdev/fuz_util/git.js';

Calls git fetch.

origin

default 'origin'

branch?

type GitBranch | undefined
optional

options?

type SpawnOptions | undefined
optional

returns

Promise<void>

throws

  • Error - if the underlying git command fails

git_info_get
#

git.ts view source

(options?: SpawnOptions | undefined): Promise<GitInfo> import {git_info_get} from '@fuzdev/fuz_util/git.js';

Get basic git info (commit hash and branch name) without throwing. Returns null values if git commands fail (e.g., not in a git repo).

options?

type SpawnOptions | undefined
optional

returns

Promise<GitInfo>

git_local_branch_exists
#

git.ts view source

(branch: GitBranch, options?: SpawnOptions | undefined): Promise<boolean> import {git_local_branch_exists} from '@fuzdev/fuz_util/git.js';

Checks if a local git branch exists.

branch

options?

type SpawnOptions | undefined
optional

returns

Promise<boolean>

git_parse_workspace_status
#

git.ts view source

(stdout: string | null): GitWorkspaceStatus import {git_parse_workspace_status} from '@fuzdev/fuz_util/git.js';

Parses the output of git status --porcelain -z (v1 format) into a status object. This is a pure function that can be tested independently.

Format: XY path\0 where:

  • X = staged status (index)
  • Y = unstaged status (work tree)
  • path = file path (unescaped with -z)

Supported status codes:

  • M = modified
  • A = added
  • D = deleted
  • R = renamed
  • C = copied
  • T = type changed (regular file, symbolic link or submodule)
  • U = unmerged
  • ? = untracked
  • ! = ignored

For renames/copies: XY new\0old\0 (two NUL-separated paths)

Note: This implementation treats submodules the same as regular files. Submodule-specific status codes (lowercase m, ?) are interpreted as changes.

stdout

the raw output from git status --porcelain -z

type string | null

returns

GitWorkspaceStatus

git_pull
#

git.ts view source

(origin?: GitOrigin, branch?: GitBranch | undefined, options?: SpawnOptions | undefined): Promise<void> import {git_pull} from '@fuzdev/fuz_util/git.js';

Calls git pull.

origin

default 'origin'

branch?

type GitBranch | undefined
optional

options?

type SpawnOptions | undefined
optional

returns

Promise<void>

throws

  • Error - if the underlying git command fails

git_push
#

git.ts view source

(origin: GitOrigin, branch?: GitBranch | undefined, options?: SpawnOptions | undefined, set_upstream?: boolean): Promise<void> import {git_push} from '@fuzdev/fuz_util/git.js';

Calls git push.

origin

branch?

type GitBranch | undefined
optional

options?

type SpawnOptions | undefined
optional

set_upstream

type boolean
default false

returns

Promise<void>

throws

  • Error - if the underlying git command fails

git_push_to_create
#

git.ts view source

(origin?: GitOrigin, branch?: GitBranch | undefined, options?: SpawnOptions | undefined): Promise<void> import {git_push_to_create} from '@fuzdev/fuz_util/git.js';

Calls git push, setting upstream if the remote branch does not yet exist.

origin

default 'origin'

branch?

type GitBranch | undefined
optional

options?

type SpawnOptions | undefined
optional

returns

Promise<void>

throws

  • Error - if the underlying git command fails

git_remote_branch_exists
#

git.ts view source

(origin?: GitOrigin, branch?: GitBranch | undefined, options?: SpawnOptions | undefined): Promise<boolean> import {git_remote_branch_exists} from '@fuzdev/fuz_util/git.js';

Checks if a remote git branch exists.

origin

default 'origin'

branch?

type GitBranch | undefined
optional

options?

type SpawnOptions | undefined
optional

returns

Promise<boolean>

throws

  • Error - if the `git ls-remote` command fails for a reason other than the branch not existing

git_reset_branch_to_first_commit
#

git.ts view source

(origin: GitOrigin, branch: GitBranch, options?: SpawnOptions | undefined): Promise<void> import {git_reset_branch_to_first_commit} from '@fuzdev/fuz_util/git.js';

Resets the target branch back to its first commit both locally and remotely.

origin

branch

options?

type SpawnOptions | undefined
optional

returns

Promise<void>

git_workspace_is_clean
#

git.ts view source

(status: GitWorkspaceStatus): boolean import {git_workspace_is_clean} from '@fuzdev/fuz_util/git.js';

status

returns

boolean

true if the workspace has no changes at all

git_workspace_is_fully_staged
#

git.ts view source

(status: GitWorkspaceStatus): boolean import {git_workspace_is_fully_staged} from '@fuzdev/fuz_util/git.js';

status

returns

boolean

true if the workspace has no unstaged changes and no untracked files (staged changes are OK)

git_workspace_status_message
#

git.ts view source

(status: GitWorkspaceStatus): string import {git_workspace_status_message} from '@fuzdev/fuz_util/git.js';

Converts a workspace status to a human-readable message.

status

returns

string

GitBranch
#

git.ts view source

ZodString import type {GitBranch} from '@fuzdev/fuz_util/git.js';

GitInfo
#

git.ts view source

GitInfo import type {GitInfo} from '@fuzdev/fuz_util/git.js';

Basic git repository info.

commit

type string | null

branch

type string | null

GitOrigin
#

git.ts view source

ZodString import type {GitOrigin} from '@fuzdev/fuz_util/git.js';

GitWorkspaceStatus
#

git.ts view source

GitWorkspaceStatus import type {GitWorkspaceStatus} from '@fuzdev/fuz_util/git.js';

Git workspace status flags indicating which types of changes are present.

unstaged_changes

type boolean

staged_changes

type boolean

untracked_files

type boolean

Depends on
#

Imported by
#