gitstate

package
v0.140.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 21, 2026 License: MIT Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RebaseStuck

type RebaseStuck struct {
	Reason RebaseStuckReason
	// StoppedSHA is the commit at which the rebase paused (empty if unknown).
	StoppedSHA string
	// LastDoneOp is the verb of the last entry in `done` ("pick", "edit",
	// "exec", "reword", "break", ...). Empty if `done` is missing or empty.
	LastDoneOp string
	// LastDoneArg is the rest of the last `done` line after the verb — for
	// `pick` this is a short sha + comment, for `exec` it is the command.
	LastDoneArg string
}

RebaseStuck carries the classification plus the signals that drove it, so callers can build a useful message without re-reading the git dir.

func ClassifyRebaseStuck

func ClassifyRebaseStuck(state *State) RebaseStuck

ClassifyRebaseStuck inspects a known rebase-merge/rebase-apply state and returns the reason it is paused. For non-rebase states (or when the rebase is progressing normally) it returns RebaseStuckNone.

The caller is expected to have already confirmed there are zero unmerged paths — this function does not look at the work tree.

type RebaseStuckReason

type RebaseStuckReason int

RebaseStuckReason classifies why a rebase has paused with no merge conflicts.

const (
	// RebaseStuckNone — not stuck, or not a rebase state. Either the rebase is
	// progressing normally or the state isn't RebaseMerge/RebaseApply.
	RebaseStuckNone RebaseStuckReason = iota
	// RebaseStuckEmptyCommit — picked commit produced an empty/redundant patch
	// against the new base. git stops here so the user can decide
	// (--skip vs --continue with --allow-empty).
	RebaseStuckEmptyCommit
	// RebaseStuckEdit — explicit `edit` / `reword` / `break` line in the todo
	// pauses the rebase for amending.
	RebaseStuckEdit
	// RebaseStuckExec — `exec` line failed; rebase pauses until the user fixes
	// the command output and runs --continue.
	RebaseStuckExec
	// RebaseStuckUnknown — rebase is paused with no unmerged paths but the
	// signals don't match a known category (rebase-apply backend, malformed
	// state dir, future git versions, etc.).
	RebaseStuckUnknown
)

func (RebaseStuckReason) String

func (r RebaseStuckReason) String() string

String returns a stable identifier suitable for messages and tests.

type State

type State struct {
	Kind      StateKind
	GitDir    string // 일반 git dir (.git)
	CommonDir string // common dir (worktree 대응)

	// Rebase-specific fields (only populated for StateRebaseMerge/RebaseApply)
	HeadName string // original branch (e.g. "refs/heads/feat/x")
	Onto     string // target ref
	OrigHead string // HEAD sha before rebase started
	Current  int    // current step (1-based)
	Total    int    // total step count
}

State carries details about the in-progress operation.

func Detect

func Detect(ctx context.Context, workDir string) (*State, error)

Detect inspects the current working tree's git directory and returns State. If workDir == "", uses current working directory. Returns StateNone when no operation is in progress.

func DetectFromGitDir

func DetectFromGitDir(commonDir string) (*State, error)

DetectFromGitDir performs the same inspection given a known git dir. Useful for tests — skips `git rev-parse` call.

type StateKind

type StateKind int

StateKind represents which in-progress operation git is currently performing.

const (
	StateNone        StateKind = iota
	StateRebaseMerge           // interactive rebase / merge backend (.git/rebase-merge)
	StateRebaseApply           // am / patch-based rebase (.git/rebase-apply)
	StateMerge                 // merge conflict (.git/MERGE_HEAD)
	StateCherryPick            // cherry-pick in progress (.git/CHERRY_PICK_HEAD)
	StateRevert                // revert in progress (.git/REVERT_HEAD)
	StateBisect                // bisect in progress (.git/BISECT_LOG)
)

func (StateKind) String

func (k StateKind) String() string

String returns a human-readable name for the StateKind.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL