DEV Community

André
André

Posted on • Originally published at andreligne.io on

2 2

Making sure all commits pass the tests

If you’re a bit too pedantic about your git history, like I am, you probably want to make sure that all the commits are passing whatever checks the project has set up before merging it into the main branch.

It turns out there’s a way to automatically run a command for each commit when you’re doing a git-rebase — you can pass the --exec flag (or the shorthand -x flag).

With this flag, git will run the given command after applying each commit onto the new HEAD. If the command returns a non-zero exit code, the rebase will stop on that commit and allow you to update the commit so that it passes.

For example, if you have a Ruby project (using RSpec) and want to check that all commits after the main branch are passing the tests, you can run the following command.

$ git rebase -x “bundle exec rspec” main
Enter fullscreen mode Exit fullscreen mode

Why bother?

There are a few good reasons, other than the warm fuzzy feeling it brings you inside, to make sure that the commits are valid.

My main reason for caring about this is that it helps you keep track that all commits are working. If you have commits that aren’t passing the tests or have incomplete/broken features, it will be more challenging to track down a separate issue using git-bisect. Since you might land on a commit that is not in a working state, it is harder to tell if a commit is good or bad.

It also forces you to think about commits as an atomic piece of completed work, which makes it easier to write a great commit message which summarizes the unit of work.

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read full post →

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more