Git: My aliases

Every time you start a new assignment on a new computer all your aliases are gone. I’ll put them here for easy access, and if someone likes them they can use them too 🙂

git config --global alias.co checkout
git config --global alias.ci commit
git config --global alias.st status
git config --global alias.last 'log -1 HEAD'

Tested with Git v 2.24.3 on OSX and Linux

Spring Boot: Create a “RunAllTests” test class with JUnit 5

I like having an easy way to run all tests in a specific package path. I will here show an example of how to create a “RunAllTests” class to use in Spring Boot 2 and JUnit 5 (Jupiter):

package com.niklasottosson.myapp;

import org.junit.platform.runner.JUnitPlatform;
import org.junit.platform.suite.api.SelectPackages;
import org.junit.runner.RunWith;

/**
 * Test class to run all unit tests.
 */
@RunWith(JUnitPlatform.class)
@SelectPackages("com.niklasottosson.myapp.tests")
public class RunAllTests {
}

This will tell JUnit to search the files in the package described (and below) in the @SelectPackages annotation for tests to run

For Spring Boot 2.3.8 the normal “spring-boot-starter-test” dependency was not enough to get the JUnitPlatform into my app (for the @RunWith annotation), so I had to add the following dependency to my pom.xml:

        <dependency>
            <groupId>org.junit.platform</groupId>
            <artifactId>junit-platform-runner</artifactId>
            <version>1.2.0</version>
            <scope>test</scope>
        </dependency>

After all is in place I can run the RunAllUnitTests class and all selected tests runs

Tested on Spring Boot v2.3.8, IntelliJ v2020.3 and JUnit v5 with JUnitPlattform v1.2.0

Git: “You can only push your own commits in this repository” – when there actually is a problem

I ran into this recently by creating a new Bitbucket repository when having a spelling error in my mail address in settings. I got this error:

remote: You can only push your own commits in this repository
remote: Commit 85eb7acbf42a14b9 was committed by Niklas Ottosson (username) <niklas@worldwideweeb.com>

In the commit 85eb7acbf42a14b9 (initial commit of the new repository) my mail was niklas@worldwideweeb.com when it should have been niklas@worldwideweb.com (only one ‘e’ in ‘web’)

To fix this we need to make sure we have the correct mail address in global settings:

git config --global user.email niklas@worldwideweb.com

and then reset the author of the initial commit

git commit --amend --reset-author --no-edit

This will now replace the previous author with me, and since I now have the correct spelling the commit will be “fixed”

Tested with Git 2.24.3