Skip to content

Commit

Permalink
Allow automated tests from shallow clones
Browse files Browse the repository at this point in the history
Do not attempt to use the local repository as a reference repository
when the local repository is a shallow clone.  A shallow clone
repository has no content to offer as a reference.

Fixes 64 test failures when the test repository is a shallow clone.

jenkinsci/bom#1613 describes the experiment to
run the plugin compatibility tests with shallow clones.

jenkinsci/git-plugin#1365 implemented a similar
change in the git plugin so that shallow cloned repositories will not
fail the tests in that plugin.

Will make a few tests in a shallow repository a little slower because
they will require a full clone of the git client plugin repository
rather than reusing the existing clone in the test workspace.  Doubtful
that the performance difference will be detectable within the general
variability of CI test jobs.
  • Loading branch information
MarkEWaite committed Dec 5, 2022
1 parent 788eeda commit 325ef0a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,11 @@ public void setUp() throws Exception {
w = new WorkingArea();
}

private boolean isShallow() {
File shallowMarker = new File(".git", "shallow");
return shallowMarker.isFile();
}

/**
* Populate the local mirror of the git client plugin repository. Returns
* path to the local mirror directory.
Expand All @@ -372,7 +377,13 @@ protected String localMirror() throws IOException, InterruptedException {
* the final destination directory.
*/
Path tempClonePath = Files.createTempDirectory(targetDir.toPath(), "clone-");
w.launchCommand("git", "clone", "--reference", f.getCanonicalPath(), "--mirror", "https://github.com/jenkinsci/git-client-plugin", tempClonePath.toFile().getAbsolutePath());
String repoUrl = "https://github.com/jenkinsci/git-client-plugin.git";
String destination = tempClonePath.toFile().getAbsolutePath();
if (isShallow()) {
w.launchCommand("git", "clone", "--mirror", repoUrl, destination);
} else {
w.launchCommand("git", "clone", "--reference", f.getCanonicalPath(), "--mirror", repoUrl, destination);
}
if (!clone.exists()) { // Still a race condition, but a narrow race handled by Files.move()
renameAndDeleteDir(tempClonePath, cloneDirName);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ private void renameAndDeleteDir(Path srcDir, String destDirName) {
}
}


private boolean isShallow() {
File shallowMarker = new File(".git", "shallow");
return shallowMarker.isFile();
}


/**
* Populate the local mirror of the git client plugin repository.
* Returns path to the local mirror directory.
Expand All @@ -92,7 +99,12 @@ String localMirror() throws IOException, InterruptedException {
* the final destination directory.
*/
Path tempClonePath = Files.createTempDirectory(targetDir.toPath(), "clone-");
cliGitCommand.run("clone", "--reference", f.getCanonicalPath(), "--mirror", repoURL, tempClonePath.toFile().getAbsolutePath());
String destination = tempClonePath.toFile().getAbsolutePath();
if (isShallow()) {
cliGitCommand.run("clone", "--mirror", repoURL, destination);
} else {
cliGitCommand.run("clone", "--reference", f.getCanonicalPath(), "--mirror", repoURL, destination);
}
if (!clone.exists()) { // Still a race condition, but a narrow race handled by Files.move()
renameAndDeleteDir(tempClonePath, cloneDirName);
} else {
Expand Down

0 comments on commit 325ef0a

Please sign in to comment.