Skip to content

feat: add --skip-if-merging option - #91

Open
oschrenk wants to merge 1 commit into
croissong:mainfrom
oschrenk:feat/skip-if-merging
Open

oschrenk wants to merge 1 commit into
croissong:mainfrom
oschrenk:feat/skip-if-merging

Conversation

@oschrenk

@oschrenk oschrenk commented Nov 7, 2026

Copy link
Copy Markdown

Ports the -M (SKIP_IF_MERGING) option of the original gitwatch.sh.

Today, if a git merge stops on conflicts and you save a file while you resolve them, gitwatch stages everything and commits. libgit2's commit() ignores MERGE_HEAD, so the result is a single-parent commit that contains the <<<<<<< conflict markers, and gitwatch does not remove MERGE_HEAD. A stopped rebase or cherry-pick has the same problem.

With --skip-if-merging, gitwatch checks Repository::state() before it stages anything. It skips the commit when the state is not Clean.

Usage

gitwatch watch --skip-if-merging .

Or in gitwatch.yaml:

skip_if_merging: true

Differences from gitwatch.sh

gitwatch.sh only checks for MERGE_HEAD. This PR skips every non-clean state: merge, rebase, cherry-pick, revert, bisect and git am. The check is the same size, and it stops conflict markers from getting into a commit in all of these cases.

Port gitwatch's SKIP_IF_MERGING (-M): while a merge is in progress,
skip the whole stage/commit cycle instead of committing a half-resolved
merge with conflict markers still in the working tree.

The check is wider than the shell script, which only looks for
MERGE_HEAD: any repository state other than RepositoryState::Clean
skips the commit, so a stopped rebase, cherry-pick, revert or bisect
is covered as well.

Configurable via --skip-if-merging or skip_if_merging in gitwatch.yaml.
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