Skip to content
Snippets Groups Projects
Commit b3b16374 authored by Florian Heck's avatar Florian Heck
Browse files

added additional check in status parsing

parent a660922c
No related branches found
No related tags found
No related merge requests found
...@@ -552,7 +552,7 @@ public class Repository { ...@@ -552,7 +552,7 @@ public class Repository {
*/ */
public Optional<Status> getStatus() { public Optional<Status> getStatus() {
Optional<ExecRes> output = git.exec(dir, "status", "-z"); Optional<ExecRes> output = git.exec(dir, "status", "-z");
Function<ExecRes, Status> toStatus = execRes -> { Function<ExecRes, Optional<Status>> toStatus = execRes -> {
if (git.failed(execRes)) { if (git.failed(execRes)) {
LOG.warning(() -> String.format("Failed to get status information for repo %s", this)); LOG.warning(() -> String.format("Failed to get status information for repo %s", this));
...@@ -562,7 +562,7 @@ public class Repository { ...@@ -562,7 +562,7 @@ public class Repository {
return Status.parseStatus(this, execRes.stdOut); return Status.parseStatus(this, execRes.stdOut);
}; };
return output.map(toStatus); return output.flatMap(toStatus);
} }
/** /**
......
...@@ -5,6 +5,7 @@ import java.nio.file.Paths; ...@@ -5,6 +5,7 @@ import java.nio.file.Paths;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Optional;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
...@@ -81,9 +82,9 @@ public class Status { ...@@ -81,9 +82,9 @@ public class Status {
* *
* @param repo the repo this status report is from * @param repo the repo this status report is from
* @param gitOutput the status report from git * @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> changed = new HashMap<>();
Map<Path, String> unmerged = new HashMap<>(); Map<Path, String> unmerged = new HashMap<>();
Matcher matcher = STATUS_ENTRY.matcher(gitOutput); Matcher matcher = STATUS_ENTRY.matcher(gitOutput);
...@@ -98,6 +99,6 @@ public class Status { ...@@ -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));
} }
} }
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