watch

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package watch provides repository monitoring and change detection.

This package monitors git repositories for changes including file modifications, branch updates, and remote changes.

Features

  • File system change detection
  • Branch change monitoring
  • Remote update detection
  • Configurable polling intervals

Usage

watcher := watch.NewWatcher(repoPath, watch.Options{
    Interval: 5 * time.Second,
})
events := watcher.Watch(ctx)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event struct {
	// Path is the repository path where the change occurred.
	Path string

	// Type is the type of change detected.
	Type EventType

	// Timestamp is when the event was detected.
	Timestamp time.Time

	// Status is the repository status at the time of detection.
	Status *repository.Status

	// Files are the specific files that changed (if available).
	Files []string
}

Event represents a change detected in a repository.

type EventType

type EventType string

EventType represents the type of change detected.

const (
	// EventTypeModified indicates files were modified (unstaged).
	EventTypeModified EventType = "modified"

	// EventTypeStaged indicates files were staged.
	EventTypeStaged EventType = "staged"

	// EventTypeUntracked indicates new untracked files appeared.
	EventTypeUntracked EventType = "untracked"

	// EventTypeDeleted indicates files were deleted.
	EventTypeDeleted EventType = "deleted"

	// EventTypeCommit indicates a new commit was created.
	EventTypeCommit EventType = "commit"

	// EventTypeBranch indicates branch changed.
	EventTypeBranch EventType = "branch"

	// EventTypeClean indicates the repository became clean.
	EventTypeClean EventType = "clean"
)

func (EventType) String

func (e EventType) String() string

String returns the string representation of the event type.

type Logger

type Logger interface {
	Debug(format string, args ...any)
	Info(format string, args ...any)
	Warn(format string, args ...any)
	Error(format string, args ...any)
}

Logger defines the logging interface for the watch package.

type WatchOptions

type WatchOptions struct {
	// Interval is the polling interval for checking changes.
	// If not specified, defaults to 2 seconds.
	Interval time.Duration

	// IncludeClean indicates whether to send events when repository becomes clean.
	IncludeClean bool

	// DebounceDuration is the minimum time between events for the same path.
	// This prevents duplicate events in rapid succession.
	DebounceDuration time.Duration

	// Logger is the logger to use for watch operations.
	Logger Logger
}

WatchOptions configures the watcher behavior.

type Watcher

type Watcher interface {
	// Start begins monitoring the specified repository paths.
	// It returns immediately and sends events to the event channel.
	Start(ctx context.Context, paths []string) error

	// Events returns the channel for receiving watch events.
	Events() <-chan Event

	// Errors returns the channel for receiving errors.
	Errors() <-chan error

	// Stop stops the watcher and closes all channels.
	Stop() error
}

Watcher monitors Git repositories for changes.

func NewWatcher

func NewWatcher(client repository.Client, options WatchOptions) (Watcher, error)

NewWatcher creates a new repository watcher with the given options.

Example:

watcher, err := watch.NewWatcher(repoClient, watch.WatchOptions{
    Interval:         5 * time.Second,
    IncludeClean:     true,
    DebounceDuration: 500 * time.Millisecond,
})
if err != nil {
    log.Fatal(err)
}
defer watcher.Stop()

Jump to

Keyboard shortcuts

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