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

changed status to contain path to changed/unmerged files

parent 0369df0b
No related branches found
No related tags found
No related merge requests found
package de.uni_passau.fim.seibt.gitwrapper.repo; package de.uni_passau.fim.seibt.gitwrapper.repo;
import java.io.File; import java.nio.file.Path;
import java.util.*; import java.nio.file.Paths;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
...@@ -9,15 +12,15 @@ public class Status { ...@@ -9,15 +12,15 @@ public class Status {
private static final Pattern STATUS_ENTRY = Pattern.compile("(.?.) (?:.*? )?(.*?)\0"); private static final Pattern STATUS_ENTRY = Pattern.compile("(.?.) (?:.*? )?(.*?)\0");
public final String id; public final String id;
public final Map<File, String> changed; public final Map<Path, String> changed;
public final Map<File, String> unmerged; public final Map<Path, String> unmerged;
/** /**
* @param id the commit id * @param id the commit id
* @param changed a map of changed files and heir status codes * @param changed a map of changed files and heir status codes
* @param unmerged a map of unmerged files an their status code. * @param unmerged a map of unmerged files an their status code.
*/ */
private Status(String id, Map<File, String> changed, Map<File, String> unmerged) { private Status(String id, Map<Path, String> changed, Map<Path, String> unmerged) {
this.id = id; this.id = id;
this.changed = Collections.unmodifiableMap(changed); this.changed = Collections.unmodifiableMap(changed);
this.unmerged = Collections.unmodifiableMap(unmerged); this.unmerged = Collections.unmodifiableMap(unmerged);
...@@ -49,12 +52,12 @@ public class Status { ...@@ -49,12 +52,12 @@ public class Status {
} else { } else {
if (!unmerged.isEmpty()) { if (!unmerged.isEmpty()) {
out = "Unmerged files:"; out = "Unmerged files:";
out += unmerged.keySet().stream().map(File::getPath).reduce("", (list, file) -> String.join("\n", list, file)); out += unmerged.keySet().stream().map(Path::toString).reduce("", (list, file) -> String.join("\n", list, file));
out += "\n"; out += "\n";
} }
if (!changed.isEmpty()) { if (!changed.isEmpty()) {
out += "Changed files:"; out += "Changed files:";
out += changed.keySet().stream().map(File::getPath).reduce("", (list, file) -> String.join("\n", list, file)); out += changed.keySet().stream().map(Path::toString).reduce("", (list, file) -> String.join("\n", list, file));
out += "\n"; out += "\n";
} }
} }
...@@ -70,12 +73,12 @@ public class Status { ...@@ -70,12 +73,12 @@ public class Status {
* @return a {@link Status} object, representing the status read from the git output * @return a {@link Status} object, representing the status read from the git output
*/ */
static Status parseStatus(Repository repo, String gitOutput) { static Status parseStatus(Repository repo, String gitOutput) {
Map<File, String> changed = new HashMap<>(); Map<Path, String> changed = new HashMap<>();
Map<File, String> unmerged = new HashMap<>(); Map<Path, String> unmerged = new HashMap<>();
Matcher matcher = STATUS_ENTRY.matcher(gitOutput); Matcher matcher = STATUS_ENTRY.matcher(gitOutput);
while (matcher.find()) { while (matcher.find()) {
// used new path, if file was moved // used new path, if file was moved
File file = new File(matcher.group(2)); Path file = Paths.get(matcher.group(2));
String code = matcher.group(1).toUpperCase(); String code = matcher.group(1).toUpperCase();
if (code.contains("U")) { if (code.contains("U")) {
unmerged.put(file, code); unmerged.put(file, code);
......
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