Skip to content
Snippets Groups Projects
Commit 698c3f92 authored by Georg Seibt's avatar Georg Seibt :nerd:
Browse files

move copy method to Repository and return new Repository objects representing the copies

parent 7c73b56d
No related branches found
No related tags found
No related merge requests found
......@@ -15,6 +15,7 @@ import java.util.logging.Logger;
import java.util.stream.Collectors;
import de.uni_passau.fim.seibt.gitwrapper.process.ProcessExecutor.ExecRes;
import org.apache.commons.io.FileUtils;
/**
* A git {@link Repository}.
......@@ -195,6 +196,32 @@ public class Repository {
return revParse.map(toHash);
}
/**
* Copies this {@link Repository} to the given <code>destination</code> directory.
*
* @param destination
* the destination directory
* @return a copy of this {@link Repository} at the new location
* @see FileUtils#copyDirectory(File, File)
*/
public Optional<Repository> copy(File destination) {
try {
if (destination.exists() && destination.isDirectory()) {
LOG.warning(() -> String.format("%s already exists. Merging source and destination directories.", destination));
}
FileUtils.copyDirectory(dir, destination);
LOG.fine(() -> String.format("Copied %s to %s.", this, destination));
} catch (IOException e) {
LOG.log(Level.WARNING, e, () -> String.format("Failed to copy %s to %s.", dir, destination));
return Optional.empty();
}
return Optional.of(new Repository(git, url, destination));
}
/**
* Returns the {@link GitWrapper} used by this {@link Repository}.
*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment