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

documentation for status

parent 7afdc3c0
No related branches found
No related tags found
No related merge requests found
......@@ -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<>();
......
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