Hands-on with Atomic Commits — Part 4: Divide and Conquer Strategy
This strategy consists of making a pull request for each atomic commit performed. As we’ve made our architecture layered and fully decoupled, it will be very easy to implement atomic commits per package created.
Applying the divide and conquer strategy we will have five atomic commits, one commit for each layer and one more commit for the end to end tests. Then we will have:
- One commit to the database package
- One commit to the repositories package
- One commit to the services package
- One commit to the HTTP package
- One commit to the tests package
If you’ve ever thought about creating all your commits at once, hold your horses buddy, remember that in this strategy we have to create a pull request for each atomic commit, so we’ll need to create the commits as the pull requests are created.
Let’s get our hands dirty from now on. For the first step, we will perform the steps below:
- Create a commit for the database package
- Push to our repository
- Create a pull request
Create a commit for the database package
First things first, you need to create a branch to avoid make a push to the main branch. Let’s create the ac-1-database
branch.
See the figure below and notice that the files staged are those related only to the database package (only three files out of the nineteen).
Also note that the commit message is simple and objective that clearly informs the intent of the commit. If you are using an IDE to create your commits you can commit the staged files (in my IDE I simple type CTRL+ENTER
) but if you want to use the command line you can run the commands in the figure below.
Push to our repository
To push to our repository simply run the command git push
as shown in the figure below.
Create a pull request
Now that we have our commit pushed to the repository, we can open a pull request.
After clicked in the create pull request
button we will have:
Note: I always prefer to squash and merge
instead of only merge
.
Now we need to do the same for the other commits, for the sake of simplicity, I’ll put only the pictures of the steps to be done because you already know that you should follow the way described above.
Create a commit for the repositories package
- Create a new branch
Inside the ac-1-database
branch, create a new branch called ac-2-repositories.
2. Create the atomic commit and push the files to the repository
3. Create a new pull request
Important Note: This new pull request should target the ac-1-database
branch so that the list of modified files is just the one you pushed and doesn’t stack with previous commits.
Create a commit for the services package
- Create a new branch
Inside the ac-2-repositories
branch, create a new branch called ac-3-services
.
2. Create the atomic commit and push the files to the repository
3. Create a new pull request
Important Note: This new pull request should target the ac-2-repositories
branch so that the list of modified files is just the one you pushed and doesn’t stack with previous commits.
Create a commit for the HTTP package
- Create a new branch
Inside the ac-3-services
branch, create a new branch called ac-4-http
.
2. Create the atomic commit and push the files to the repository
3. Create a new pull request
Important Note: This new pull request should target the ac-3-services
branch so that the list of modified files is just the one you pushed and doesn’t stack with previous commits.
Create a commit for the Tests package
- Create a new branch
Inside the ac-4-http
branch, create a new branch called ac-5-tests
.
2. Create the atomic commit and push the files to the repository
3. Create a new pull request
Important Note: This new pull request should target the ac-4-http
branch so that the list of modified files is just the one you pushed and doesn’t stack with previous commits.
At this point we should have five pull requests open as shown in the figure below.
But wait a minute, as you can see in the figure below, we still have uncommitted files in our repository. And yes, if you followed the entire series you know that in the All In One Strategy we made eight commits.
My bad, I forgot these three… and, yeah, the real world hurts sometimes, what should we do fix this mess? What would you do?
Breath and take a cup of coffee. We will fix this mess in the next part.
The repository used in this article can be found here.
Next: Hands-on with Atomic Commits — Part 5: Clean up!
Previous: Hands-on with Atomic Commits — Part 3: All In One Strategy