Skip to content

Fix(watcher): prevent onFilesStaged() from triggering after commit by filtering .git/index updates #12

@D3vanshC

Description

@D3vanshC

Description

Currently, after a user performs a git commit, GhostDev automatically triggers the onFilesStaged() function again.
This behavior is unintended, as the commit action should mark the end of the staging phase.

Additionally, the first git add performed after that commit does not trigger onFilesStaged(), but the next subsequent git add does.
This inconsistent triggering indicates that the file watcher or event listener may not be resetting properly after the commit event.


Proposed Solution

Investigate and update the repository watcher logic to correctly handle .git/index changes.

Focus on the setupRepositoryWatcher() function in extension.ts, which likely monitors file system changes inside the .git directory.
The issue may arise because the watcher reacts to .git/index updates caused by commits, or fails to reinitialize its state afterward.

Hint to resolve:

  • Track the .git/index file specifically.
  • Ensure that onFilesStaged() only fires on actual staging events (git add) and not on commit writes.
  • Consider debouncing or filtering events triggered by Git commit operations.

Expected Outcome

  • onFilesStaged() triggers only when files are explicitly staged via git add.
  • Commits no longer cause an unnecessary retrigger.
  • The watcher remains stable across multiple commit and staging cycles.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomershacktoberfestWelcoming contributions as a part of Hacktoberfest'25

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions