Optimize worktree index refreshing

Improved how the app tracks changes across multiple Git worktrees by reducing unnecessary file system checks and adding security validation for Git references. The app now detects actual head moves more efficiently and prevents potential security issues from crafted file paths.