Skip to content

Commit dec9fca

Browse files
committed
fix: fire PrePush/PostPush/PostPull hooks in watch mode
Watch mode was only firing operation-level hooks during initial sync. Now fires PrePush before debounced pushes, PostPush after successful pushes, and PostPull after each file receive in the ongoing sync loop.
1 parent e205533 commit dec9fca

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

internal/cmd/watch.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,15 @@ func (c *WatchCmd) receiveLoop(ctx context.Context, sc *sync.Client, key []byte,
502502
plainPath, _ := crypto.DecodePath(key, msg.Path, c.encVer)
503503
u.Out().Infof("Deleted: %s", plainPath)
504504
}
505+
506+
if fc > 0 || dc > 0 {
507+
if err := c.hookRunner.Fire(ctx, hooks.Event{
508+
Event: hooks.PostPull,
509+
Stats: &hooks.OperationStats{FilesSynced: fc, FilesDeleted: dc},
510+
}); err != nil {
511+
slog.Warn("post-pull hook failed", "error", err)
512+
}
513+
}
505514
}
506515
}
507516

@@ -559,6 +568,14 @@ func (c *WatchCmd) watchLoop(ctx context.Context, watcher *fsnotify.Watcher, sc
559568
}
560569
pending = false
561570

571+
if err := c.hookRunner.Fire(ctx, hooks.Event{Event: hooks.PrePush}); err != nil {
572+
var blocked *hooks.BlockedError
573+
if errors.As(err, &blocked) {
574+
slog.Warn("pre-push hook blocked push", "error", err)
575+
continue
576+
}
577+
}
578+
562579
pushCount, delCount, err := c.pushLocalChanges(ctx, sc, key, state)
563580
if err != nil {
564581
return fmt.Errorf("push local changes: %w", err)
@@ -569,6 +586,13 @@ func (c *WatchCmd) watchLoop(ctx context.Context, watcher *fsnotify.Watcher, sc
569586
slog.Warn("failed to save state", "error", err)
570587
}
571588
u.Out().Infof("Pushed %d files, deleted %d", pushCount, delCount)
589+
590+
if err := c.hookRunner.Fire(ctx, hooks.Event{
591+
Event: hooks.PostPush,
592+
Stats: &hooks.OperationStats{FilesSynced: pushCount, FilesDeleted: delCount},
593+
}); err != nil {
594+
slog.Warn("post-push hook failed", "error", err)
595+
}
572596
}
573597
}
574598
}

0 commit comments

Comments
 (0)