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 8cb4112c016f7a160299ce404bdc99b7db026c94..d3c5382ca73cc3b8181dba62d47a82b62b2b8c86 100644 --- a/src/de/uni_passau/fim/seibt/gitwrapper/repo/Status.java +++ b/src/de/uni_passau/fim/seibt/gitwrapper/repo/Status.java @@ -8,20 +8,35 @@ import java.util.regex.Pattern; public class Status { private static final Pattern STATUS_ENTRY = Pattern.compile("(.?.) (?:.*? )?(.*?)\0"); - public final String head; + public final String id; public final Map<File, String> changed; public final Map<File, String> unmerged; - private Status(String head, Map<File, String> changed, Map<File, String> unmerged) { - this.head = head; + /** + * @param id the commit id + * @param changed a map of changed files and heir status codes + * @param unmerged a map of unmerged files an their status code. + */ + private Status(String id, Map<File, String> changed, Map<File, String> unmerged) { + this.id = id; this.changed = Collections.unmodifiableMap(changed); this.unmerged = Collections.unmodifiableMap(unmerged); } + /** + * Checks, if <code>this</code> represents a clean repository. + * + * @return <code>true</code>, if the repository state is clean and has uncommitted changes. + */ public boolean isClean() { return changed.isEmpty() && unmerged.isEmpty(); } + /** + * Checks, if <code>this</code> has unmerged files. + * + * @return <code>true</code>, if there are unmerged files + */ public boolean hasConflicts() { return !unmerged.isEmpty(); } @@ -30,7 +45,7 @@ public class Status { public String toString() { String out = ""; if (isClean()) { - out = "Clean working directory on commit " + head + "\n"; + out = "Clean working directory on commit " + id + "\n"; } else { if (!unmerged.isEmpty()) { out = "Unmerged files:"; @@ -47,6 +62,13 @@ public class Status { return out; } + /** + * Parses the output from git into a new object. + * + * @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 + */ static Status parseStatus(Repository repo, String gitOutput) { Map<File, String> changed = new HashMap<>(); Map<File, String> unmerged = new HashMap<>();