Skip to content

1512: MirrorBot may get stuck failing to clone repository #1374

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -88,8 +88,17 @@ public Collection<WorkItem> run(Path scratchPath) {
repo = Repository.mirror(from.url(), dir);
} else {
log.info("Found existing scratch directory for " + to.name());
repo = Repository.get(dir).orElseThrow(() -> {
return new RuntimeException("Repository in " + dir + " has vanished");
repo = Repository.get(dir).orElseGet(() -> {
log.info("The existing scratch directory is not a valid repository. Recloning " + from.name());
try {
Files.walk(dir)
.map(Path::toFile)
.sorted(Comparator.reverseOrder())
.forEach(File::delete);
return Repository.mirror(from.url(), dir);
} catch (IOException io) {
throw new RuntimeException(io);
}
});
}

@@ -111,7 +120,6 @@ public Collection<WorkItem> run(Path scratchPath) {
}
}
}

} catch (IOException e) {
throw new UncheckedIOException(e);
}
Original file line number Diff line number Diff line change
@@ -22,6 +22,8 @@
*/
package org.openjdk.skara.bots.mirror;

import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.regex.Pattern;
import org.openjdk.skara.host.*;
import org.openjdk.skara.test.*;
@@ -448,4 +450,45 @@ void mirrorSelectedBranchPattern(TestInfo testInfo) throws IOException {
assertEquals(List.of(new Branch("feature")), toLocalRepo.branches());
}
}

@Test
void mirrorMasterBranchWithExistingCloneDirectory(TestInfo testInfo) throws IOException {
try (var temp = new TemporaryDirectory()) {
var host = TestHost.createNew(List.of(HostUser.create(0, "duke", "J. Duke")));

var fromDir = temp.path().resolve("from.git");
var fromLocalRepo = TestableRepository.init(fromDir, VCS.GIT);
var fromHostedRepo = new TestHostedRepository(host, "test", fromLocalRepo);

var toDir = temp.path().resolve("to.git");
var toLocalRepo = TestableRepository.init(toDir, VCS.GIT);
var gitConfig = toDir.resolve(".git").resolve("config");
Files.write(gitConfig, List.of("[receive]", "denyCurrentBranch = ignore"),
StandardOpenOption.APPEND);
var toHostedRepo = new TestHostedRepository(host, "test-mirror", toLocalRepo);

var newFile = fromDir.resolve("this-file-cannot-exist.txt");
Files.writeString(newFile, "Hello world\n");
fromLocalRepo.add(newFile);
var newHash = fromLocalRepo.commit("An additional commit", "duke", "duke@openjdk.org");
var fromCommits = fromLocalRepo.commits().asList();
assertEquals(1, fromCommits.size());
assertEquals(newHash, fromCommits.get(0).hash());

var toCommits = toLocalRepo.commits().asList();
assertEquals(0, toCommits.size());

var storage = temp.path().resolve("storage");
var sanitizedUrl =
URLEncoder.encode(toHostedRepo.webUrl().toString(), StandardCharsets.UTF_8);
var temporaryDir = storage.resolve(sanitizedUrl);
Files.createDirectories(temporaryDir);
var bot = new MirrorBot(storage, fromHostedRepo, toHostedRepo);
TestBotRunner.runPeriodicItems(bot);

toCommits = toLocalRepo.commits().asList();
assertEquals(1, toCommits.size());
assertEquals(newHash, toCommits.get(0).hash());
}
}
}