Skip to content

Commit 30ab3d8

Browse files
committed
Adapt remote branch listing test to CLI git 2.48.0 (#1242)
* Adapt GitAPITest for CLI git 2.48.0 Fetch from CLI git 2.48.0 and later return origin/HEAD https://github.blog/open-source/git/highlights-from-git-2-48/ says: > With Git 2.48, if the remote has a default branch but refs/remotes/origin/HEAD > is missing locally, then a fetch will update it. This test was unintentionally testing the behavior of CLI git before 2.48.0. Other tests in GitClientFetchTest were testing that origin/HEAD was reported as a branch. * Show names/sha1 of detected branches on failure When the assertion fails, show the details of the set of branches so that the test failure has more information about the failure conditions. Thanks to @darinpope for the question that prompted the improvement * Remove unused cliGitCommand from GitAPITest
1 parent 7af0df8 commit 30ab3d8

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

src/test/java/org/jenkinsci/plugins/gitclient/GitAPITest.java

+20-3
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ public class GitAPITest {
8787

8888
private GitClient testGitClient;
8989
private File testGitDir;
90-
private CliGitCommand cliGitCommand;
9190

9291
public GitAPITest(final String gitImplName) {
9392
this.gitImplName = gitImplName;
@@ -167,7 +166,6 @@ public void setUpRepositories() throws Exception {
167166

168167
testGitClient = workspace.getGitClient();
169168
testGitDir = workspace.getGitFileDir();
170-
cliGitCommand = workspace.getCliGitCommand();
171169
workspace.initializeWorkspace();
172170
}
173171

@@ -760,7 +758,26 @@ public void testListRemoteBranches() throws Exception {
760758
workspace.launchCommand("git", "fetch", "origin");
761759
Set<Branch> branches = testGitClient.getRemoteBranches();
762760
assertBranchesExist(branches, "origin/" + defaultBranchName, "origin/test", "origin/another");
763-
assertEquals(3, branches.size());
761+
int branchCount = 3;
762+
if (workspace.cgit().isAtLeastVersion(2, 48, 0, 0)) {
763+
/* Fetch from CLI git 2.48.0 and later return origin/HEAD
764+
*
765+
* https://github.blog/open-source/git/highlights-from-git-2-48/ says:
766+
*
767+
* With Git 2.48, if the remote has a default branch but refs/remotes/origin/HEAD
768+
* is missing locally, then a fetch will update it.
769+
*
770+
* This test was unintentionally testing the behavior of CLI git before
771+
* 2.48.0. Other tests in GitClientFetchTest were testing that origin/HEAD
772+
* was reported as a branch.
773+
*/
774+
assertBranchesExist(branches, "origin/HEAD");
775+
branchCount = 4;
776+
}
777+
assertEquals(
778+
"Wrong branch count, found " + branches.size() + " branches: " + branches,
779+
branchCount,
780+
branches.size());
764781
}
765782

766783
@Test

0 commit comments

Comments
 (0)