Documentation
¶
Index ¶
- func EnsureLogDir(logDir string) error
- func ShouldBeLogged(gitCmd *githelpers.GitCommand) bool
- func ToggleLine(file *os.File, lineNumber int) error
- type Entry
- type EntryType
- type GitHelper
- type Logger
- func (l *Logger) CountConsecutiveUndoneCommands(refArg ...Ref) (int, error)
- func (l *Logger) Dump(w io.Writer) error
- func (l *Logger) GetLastCheckoutSwitchEntry(refArg ...Ref) (*Entry, error)
- func (l *Logger) GetLastCheckoutSwitchEntryForToggle(refArg ...Ref) (*Entry, error)
- func (l *Logger) GetLastEntry(refArg ...Ref) (*Entry, error)
- func (l *Logger) GetLastRegularEntry(refArg ...Ref) (*Entry, error)
- func (l *Logger) GetLastUndoedEntry(refArg ...Ref) (*Entry, error)
- func (l *Logger) GetLogPath() string
- func (l *Logger) IsNavigationCommand(command string) bool
- func (l *Logger) LogCommand(strGitCommand string) error
- func (l *Logger) ProcessLogFile(processor func(line string) bool) error
- func (l *Logger) ToggleEntry(entryIdentifier string) error
- func (l *Logger) TruncateToCurrentBranch(refArg ...Ref) error
- type Ref
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EnsureLogDir ¶
EnsureLogDir ensures the git-undo log directory exists.
func ShouldBeLogged ¶ added in v0.2.0
func ShouldBeLogged(gitCmd *githelpers.GitCommand) bool
ShouldBeLogged returns true if the command should be logged.
Types ¶
type Entry ¶
type Entry struct { // Timestamp is parsed timestamp of the entry. Timestamp time.Time // Ref is reference (branch/tag/commit) where the command was executed. Ref Ref // Command is just the command part. Command string // Undoed is true if the entry is undoed. Undoed bool IsNavigation bool }
Entry represents a logged git command with its full identifier.
func ParseLogLine ¶ added in v0.2.0
ParseLogLine parses a log line into an Entry.
func (*Entry) GetIdentifier ¶
GetIdentifier uses String() representation as the identifier itself But without prefix sign (so undoed command are still found).
func (*Entry) MarshalText ¶
func (*Entry) String ¶
String returns a human-readable representation of the entry. This representation goes into the log file as well.
func (*Entry) UnmarshalText ¶
type EntryType ¶
type EntryType int
EntryType specifies whether to look for regular or undoed entries.
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger manages git command logging operations.
func (*Logger) CountConsecutiveUndoneCommands ¶ added in v0.2.0
CountConsecutiveUndoneCommands counts consecutive undone mutation commands from the top of the log. It ignores navigation commands (N prefixed) and only counts mutation commands.
func (*Logger) Dump ¶
Dump reads the log file content and writes it directly to the provided writer.
func (*Logger) GetLastCheckoutSwitchEntry ¶ added in v0.2.0
GetLastCheckoutSwitchEntry returns the last checkout or switch command entry for the given ref (or current ref if not specified). This method finds NON-UNDOED navigation commands for git-back.
func (*Logger) GetLastCheckoutSwitchEntryForToggle ¶ added in v0.2.0
GetLastCheckoutSwitchEntryForToggle returns the last checkout or switch command entry for git-back, including undoed entries. This allows git-back to toggle back and forth. This method finds ANY navigation command (including undoed ones) for toggle behavior.
func (*Logger) GetLastEntry ¶
GetLastEntry returns last entry for the given ref (or current ref if not specified) regarding of the entry type (undoed or regular). This handles both navigation commands (N prefixed) and mutation commands.
func (*Logger) GetLastRegularEntry ¶ added in v0.0.2
GetLastRegularEntry returns last regular entry (ignoring undoed ones) for the given ref (or current ref if not specified). For git-undo, this skips navigation commands (N prefixed).
func (*Logger) GetLastUndoedEntry ¶ added in v0.2.0
GetLastUndoedEntry returns the last undoed entry for the given ref (or current ref if not specified). This is used for redo functionality to find the most recent undoed command to re-execute. For git-undo, this skips navigation commands (N prefixed).
func (*Logger) GetLogPath ¶
GetLogPath returns the path to the log file.
func (*Logger) IsNavigationCommand ¶ added in v0.2.0
IsNavigationCommand checks if a command is a navigation command (checkout, switch, etc.).
func (*Logger) LogCommand ¶
LogCommand logs a git command with timestamp and handles branch-aware logging.
func (*Logger) ProcessLogFile ¶ added in v0.2.0
ProcessLogFile reads the log file line by line and calls the processor function for each line. This is more efficient than reading the entire file at once, especially when only the first few lines are needed.
func (*Logger) ToggleEntry ¶
ToggleEntry toggles the undo state of an entry by adding or removing the "#" prefix. The entryIdentifier should be in the format "TIMESTAMP|REF|COMMAND" (without the # prefix). Returns true if the entry was marked as undoed, false if it was unmarked.
func (*Logger) TruncateToCurrentBranch ¶ added in v0.2.0
TruncateToCurrentBranch removes undone mutation commands from the log while preserving all navigation commands. This implements the branch-aware behavior.
type Ref ¶ added in v0.2.0
type Ref string
const ( // RefAny means when the ref (branch/tag/commit) of the line is not respected (any). RefAny Ref = "__ANY__" // RefCurrent means when the ref (branch/tag/commit) is the current one. RefCurrent Ref = "__CURRENT__" // RefUnknown means when the ref couldn't be determined. (Non-happy path). RefUnknown Ref = "__UNKNOWN__" // RefMain represents the main branch (used for convenience). RefMain Ref = "main" )