Skip to content

Commit

Permalink
concord-repository: use regular repositories in tests (#616)
Browse files Browse the repository at this point in the history
Avoids an issue with JGit when the provided `initialBranch` is ignored
and the default branch from `~/.gitconfig` is used.
  • Loading branch information
ibodrov authored Aug 10, 2022
1 parent c47bb31 commit 177797b
Showing 1 changed file with 15 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,32 +42,28 @@ public static Path createBareRepository(Path data) throws Exception {
Path repo = tmp.resolve("test");
Files.createDirectories(repo);

Git.init().setInitialBranch("master").setBare(true).setDirectory(repo.toFile()).call();
try (Git git = Git.init()
.setInitialBranch("master")
.setDirectory(repo.toFile())
.call()) {

// clone the repository into a new directory
Path workdir = Files.createTempDirectory("workDir");
Git git = Git.cloneRepository()
.setDirectory(workdir.toFile())
.setURI("file://" + repo.toString())
.call();

// copy our files into the repository
IOUtils.copy(data, workdir);
// copy our files into the repository
IOUtils.copy(data, repo);

// add, commit, and push copied files
git.add().addFilepattern(".").call();
git.commit().setSign(false).setMessage("init from: " + data).call();
git.push().call();
// add and commit copied files
git.add().addFilepattern(".").call();
git.commit().setSign(false).setMessage("init from: " + data).call();
}

return repo;
}

public static RevCommit addContent(Path bareRepo, Path file) throws Exception {
try(TemporaryPath tmp = IOUtils.tempDir("repo-tmp");
Git git = Git.cloneRepository()
.setDirectory(tmp.path().toFile())
.setURI(bareRepo.toAbsolutePath().toString())
.call()) {
try (TemporaryPath tmp = IOUtils.tempDir("repo-tmp");
Git git = Git.cloneRepository()
.setDirectory(tmp.path().toFile())
.setURI(bareRepo.toAbsolutePath().toString())
.call()) {

Files.copy(file, tmp.path().resolve(file.getFileName()), StandardCopyOption.REPLACE_EXISTING);

Expand Down

0 comments on commit 177797b

Please sign in to comment.