Skip to content

Commit

Permalink
refactor: throw exception when hash is not long enough (#227)
Browse files Browse the repository at this point in the history
  • Loading branch information
algomaster99 authored May 2, 2023
1 parent 17a0fec commit 31bb9b5
Showing 1 changed file with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@
public class GitToLocal {
public static Pair<Revision, Revision> getRevisions(Path project, String leftHash, String rightHash)
throws IOException, InterruptedException {
String hashMix = leftHash.substring(0, 7) + "_" + rightHash.substring(0, 7) + "_";
String prefix = project.getFileName().toString() + "_" + hashMix;
Path tempDirectory = Files.createTempDirectory(prefix);

return new Pair<>(
copy(project, tempDirectory.resolve("left"), leftHash),
copy(project, tempDirectory.resolve("right"), rightHash));
try {
String hashMix = leftHash.substring(0, 7) + "_" + rightHash.substring(0, 7) + "_";
String prefix = project.getFileName().toString() + "_" + hashMix;
Path tempDirectory = Files.createTempDirectory(prefix);
return new Pair<>(
copy(project, tempDirectory.resolve("left"), leftHash),
copy(project, tempDirectory.resolve("right"), rightHash));
} catch (StringIndexOutOfBoundsException e) {
throw new RuntimeException("Hash should be at least 7 characters long.");
}
}

private static int checkout(Path cwd, String commit) throws IOException, InterruptedException {
Expand Down

0 comments on commit 31bb9b5

Please sign in to comment.