Skip to content

Commit

Permalink
Fix tests on older CLI git versions
Browse files Browse the repository at this point in the history
The `git branch -m master` fails on a repository created with command
line git versions 2.25, 2.20, 2.17, and 1.8.  It works with git versions
2.30 and later.

Setting was added in July 2022 for systems that have their default
branch name configured as something other than `master`.
  • Loading branch information
MarkEWaite committed Sep 3, 2022
1 parent 3c11517 commit 234187b
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/test/java/jenkins/plugins/git/GitSampleRepoRule.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,12 @@ public void init() throws Exception {
run(true, tmp.getRoot(), "git", "version");
checkGlobalConfig();
git("init", "--template="); // initialize without copying the installation defaults to ensure a vanilla repo that behaves the same everywhere
git("branch", "-m", "master");
if (gitVersionAtLeast(2, 30)) {
// Force branch name to master even if system default is not master
// Fails on git 2.25, 2.20, 2.17, and 1.8
// Works on git 2.30 and later
git("branch", "-m", "master");
}
write("file", "");
git("add", "file");
git("config", "user.name", "Git SampleRepoRule");
Expand Down

0 comments on commit 234187b

Please sign in to comment.