Skip to content

🐌 feat: skip auto-commit while a manual commit is in progress - #4

Open
sdougbrown wants to merge 1 commit into
mainfrom
feat/skip-commit-in-progress
Open

🐌 feat: skip auto-commit while a manual commit is in progress#4
sdougbrown wants to merge 1 commit into
mainfrom
feat/skip-commit-in-progress

Conversation

@sdougbrown

Copy link
Copy Markdown
Owner

In read-write mode the daemon stages and auto-commits on its interval. When a manual git commit was mid-composition in an editor, the daemon could commit the same staged content with a generated message and push, tending the repo out from under the user. Git holds no lock during the editor phase, so this change detects an in-progress commit via a fresh .git/COMMIT_EDITMSG and backs off.

  • internal/git: add GitDir, ActiveLocks, CommitEditRecent, ClearCommitEditMsg.
  • internal/sync: skip auto-commit in read-write mode while any .git/*.lock is present; when in_progress_window is set, also skip while COMMIT_EDITMSG is fresh; clear COMMIT_EDITMSG after git-tend's own auto-commit so it does not back off against itself.
  • internal/config: add commit.in_progress_window (TOML string duration, validated).
  • README.md: document the new option and its trade-off.

Behavior is opt-in and off by default; existing read-write behavior is unchanged unless in_progress_window is set.

Validation:

  • go build ./... — ok
  • go test ./internal/git/ ./internal/sync/ ./internal/config/ — pass
  • go test ./... — pass; one pre-existing failure in cmd/git-tend (TestRunStatusEmptyRepos) also fails on main, unrelated to this change

Known limitation: because git leaves COMMIT_EDITMSG around after a finished commit, enabling this also leaves a quiet window after a manual commit before auto-commit resumes. The window length is user-controlled.

Read-write mode could commit a repo while the user was composing a commit
message in an editor, tending it out from under them. Git holds no lock
during the editor phase, so detect an in-progress commit via a fresh
.git/COMMIT_EDITMSG and back off for a configurable window.

Add commit.in_progress_window (opt-in, off by default). Always back off in
read-write mode while any .git/*.lock is present. Clear COMMIT_EDITMSG
after git-tend's own auto-commit so it does not back off against itself.

@umpire-bot umpire-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is marked... SAFE! 🙌

Must fix

  • [confidence: 95] internal/git/git_test.go - ClearCommitEditMsg is not tested, leaving its behavior for both existing and non-existing COMMIT_EDITMSG files unverified.
  • [confidence: 90] internal/sync/sync_test.go - syncReadWrite does not test the case where git.ActiveLocks returns true, failing to verify the new integration branch that skips synchronization when a git lock is detected.

Should fix

  • [confidence: 75] internal/git/git_test.go - GitDir error paths (e.g., when the underlying git command fails) are not explicitly tested.

Must fix

  • [confidence: 95] internal/git/git_test.go: ClearCommitEditMsg is not tested. This function is used in the core sync loop to clean up the COMMIT_EDITMSG sentinel after an auto-commit; its behavior in both successful removal and non-existent file scenarios is unverified.
  • [confidence: 90] internal/sync/sync_test.go: The branch in syncReadWrite that handles git.ActiveLocks returning true is not covered. A test should be added to verify that Sync returns skipped when a .lock file is detected in the repository's .git directory.

Should fix

  • [confidence: 75] internal/git/git_test.go: GitDir is not tested in isolation. As an exported function, its error paths (e.g. when the underlying git command fails) should be explicitly exercised.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant