Browse Source

Init the new repo from existing repository, avoid creating files then deleting

Shane Kilkelly 7 years ago
parent
commit
6b8101d278

+ 2 - 3
services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/bridge/repo/FSGitRepoStore.java

@@ -79,8 +79,6 @@ public class FSGitRepoStore implements RepoStore {
      public ProjectRepo initRepoFromExisting(
      public ProjectRepo initRepoFromExisting(
              String project, String fromProject
              String project, String fromProject
      ) throws IOException {
      ) throws IOException {
-         GitProjectRepo ret = GitProjectRepo.fromName(project);
-         ret.initRepo(this);
          String repoRoot = getRepoStorePath();
          String repoRoot = getRepoStorePath();
          String sourcePath = repoRoot + "/" + fromProject;
          String sourcePath = repoRoot + "/" + fromProject;
          String destinationPath = repoRoot + "/" + project;
          String destinationPath = repoRoot + "/" + project;
@@ -92,12 +90,13 @@ public class FSGitRepoStore implements RepoStore {
          try {
          try {
              File source = new File(sourcePath);
              File source = new File(sourcePath);
              File destination = new File(destinationPath);
              File destination = new File(destinationPath);
-             FileUtils.deleteDirectory(destination);
              FileUtils.copyDirectory(source, destination);
              FileUtils.copyDirectory(source, destination);
          } catch (Exception e) {
          } catch (Exception e) {
              e.printStackTrace();
              e.printStackTrace();
              throw new IOException("copy failed" + e.getLocalizedMessage());
              throw new IOException("copy failed" + e.getLocalizedMessage());
          }
          }
+         GitProjectRepo ret = GitProjectRepo.fromName(project);
+         ret.useExistingRepository(this);
          return new WalkOverrideGitRepo(
          return new WalkOverrideGitRepo(
                  ret, Optional.of(maxFileSize), Optional.empty());
                  ret, Optional.of(maxFileSize), Optional.empty());
      }
      }