Skip to content

Instantly share code, notes, and snippets.

@devinrhode2
Last active January 24, 2022 17:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devinrhode2/bba939bfcefea231f50e558503f3cc2e to your computer and use it in GitHub Desktop.
Save devinrhode2/bba939bfcefea231f50e558503f3cc2e to your computer and use it in GitHub Desktop.
post-rewrite git hook - validate every commit?

Something tells me it wouldn't be insurmountable to help facilitate running quality checks on each commit. While it would be nice for git rebase --continue to simply run the normal git hooks when running pick 12498y feature bug fix (i.e. - treat it like an edit plus undo+redo commit. while also maybe preserving date+author information) - OR maybe there's a good argument to add new hooks around rebase-continue.....

What could absolutely be done, I believe without modifications to git core, would be a pre-push hook that basically creates a worktree in the background, steps though each commit, running the quality checks on each commit. However, if a commit has an issue, you'll have to rebase -> edit that commit anyway.

So, here's something I would consider implementing: 1. pre-push check requires clean git status (seems pretty reasonable to me) 2. pre-push hook will somehow automatically rebase whole branch... but run the commit hooks for each commit for you. It's possible some simple checks could be invoked with rebase exec keyword (sibling of pick, squash, and reword). But I think it would be best to run this cycle:

  1. git pull origin $pr_target_branch --rebase. 2. Edit git-rebase-todo file - replace all pick with edit. 3. git rebase --continue. 4. undo last commit (git reset --soft HEAD^1 iirc), 5. re-run last commit (so all hooks at that point run as they normally do). Repeat 3-5 for all commits. If any commit fails, developer will have to fix pre-commit checks on that commit.

could also restore "Suggested reviewers"

@devinrhode2
Copy link
Author

devinrhode2 commented Dec 30, 2021

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