diff --git a/src/de/uni_passau/fim/seibt/gitwrapper/repo/Repository.java b/src/de/uni_passau/fim/seibt/gitwrapper/repo/Repository.java index 03b525fa1712d3ce17ee93e989d0f68c90ef05b6..5642588a621ba915a98ae67d1c5cfce2a2d4a66d 100644 --- a/src/de/uni_passau/fim/seibt/gitwrapper/repo/Repository.java +++ b/src/de/uni_passau/fim/seibt/gitwrapper/repo/Repository.java @@ -552,7 +552,7 @@ public class Repository { */ public Optional<Status> getStatus() { Optional<ExecRes> output = git.exec(dir, "status", "-z"); - Function<ExecRes, Status> toStatus = execRes -> { + Function<ExecRes, Optional<Status>> toStatus = execRes -> { if (git.failed(execRes)) { LOG.warning(() -> String.format("Failed to get status information for repo %s", this)); @@ -562,7 +562,7 @@ public class Repository { return Status.parseStatus(this, execRes.stdOut); }; - return output.map(toStatus); + return output.flatMap(toStatus); } /** diff --git a/src/de/uni_passau/fim/seibt/gitwrapper/repo/Status.java b/src/de/uni_passau/fim/seibt/gitwrapper/repo/Status.java index 1249a8111bd7a7bbe7eaa83c2e42fae1586bdfc2..04d8087b986c1fa35967a3fa4c4826f3f408f33c 100644 --- a/src/de/uni_passau/fim/seibt/gitwrapper/repo/Status.java +++ b/src/de/uni_passau/fim/seibt/gitwrapper/repo/Status.java @@ -5,6 +5,7 @@ import java.nio.file.Paths; import java.util.Collections; import java.util.HashMap; import java.util.Map; +import java.util.Optional; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -81,9 +82,9 @@ public class Status { * * @param repo the repo this status report is from * @param gitOutput the status report from git - * @return a {@link Status} object, representing the status read from the git output + * @return optionally a {@link Status} object, representing the status read from the git output */ - static Status parseStatus(Repository repo, String gitOutput) { + static Optional<Status> parseStatus(Repository repo, String gitOutput) { Map<Path, String> changed = new HashMap<>(); Map<Path, String> unmerged = new HashMap<>(); Matcher matcher = STATUS_ENTRY.matcher(gitOutput); @@ -98,6 +99,6 @@ public class Status { } } - return new Status(repo.getCurrentHEAD().get().getId(), changed, unmerged); + return repo.getCurrentHEAD().map(head -> new Status(head.id, changed, unmerged)); } }