Skip to content
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

Support local-to-remote mirroring #717

Merged
merged 14 commits into from
Oct 27, 2022
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.junit.jupiter.api.io.TempDir;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;

Expand All @@ -63,7 +64,6 @@
import com.linecorp.centraldogma.server.MirrorException;
import com.linecorp.centraldogma.server.MirroringService;
import com.linecorp.centraldogma.server.storage.project.Project;
import com.linecorp.centraldogma.testing.internal.TemporaryFolderExtension;
import com.linecorp.centraldogma.testing.internal.TestUtil;
import com.linecorp.centraldogma.testing.junit.CentralDogmaExtension;

Expand Down Expand Up @@ -93,14 +93,8 @@ static void init() {
mirroringService = dogma.mirroringService();
}

@RegisterExtension
final TemporaryFolderExtension gitRepoDir = new TemporaryFolderExtension() {
@Override
protected boolean runForEachTest() {
return true;
}
};

@TempDir
File gitRepoDir;
private Git git;
private File gitWorkTree;
private String gitUri;
Expand All @@ -110,7 +104,7 @@ protected boolean runForEachTest() {
@BeforeEach
void initGitRepo(TestInfo testInfo) throws Exception {
final String repoName = TestUtil.normalizedDisplayName(testInfo);
gitWorkTree = new File(gitRepoDir.getRoot().toFile(), repoName).getAbsoluteFile();
gitWorkTree = new File(gitRepoDir, repoName).getAbsoluteFile();
final Repository gitRepo = new FileRepositoryBuilder().setWorkTree(gitWorkTree).build();
createGitRepo(gitRepo);

Expand Down Expand Up @@ -334,7 +328,7 @@ void remoteToLocal_submodule(TestInfo testInfo) throws Exception {
// Create a new repository for a submodule.
final String submoduleName = TestUtil.normalizedDisplayName(testInfo) + ".submodule";
final File gitSubmoduleWorkTree =
new File(gitRepoDir.getRoot().toFile(), submoduleName).getAbsoluteFile();
new File(gitRepoDir, submoduleName).getAbsoluteFile();
final Repository gitSubmoduleRepo =
new FileRepositoryBuilder().setWorkTree(gitSubmoduleWorkTree).build();
createGitRepo(gitSubmoduleRepo);
Expand Down Expand Up @@ -453,8 +447,8 @@ private void addToGitIndex(String path, String content) throws IOException, GitA
addToGitIndex(git, gitWorkTree, path, content);
}

private static void addToGitIndex(Git git, File gitWorkTree,
String path, String content) throws IOException, GitAPIException {
static void addToGitIndex(Git git, File gitWorkTree,
String path, String content) throws IOException, GitAPIException {
final File file = Paths.get(gitWorkTree.getAbsolutePath(), path.split("/")).toFile();
file.getParentFile().mkdirs();
Files.asCharSink(file, StandardCharsets.UTF_8).write(content);
Expand Down
Loading