Skip to content

Commit

Permalink
Merge pull request #133 from tareqhs/nativegit_status_lists
Browse files Browse the repository at this point in the history
Align the native git status lists with standard git
  • Loading branch information
skabashnyuk committed Jun 23, 2015
2 parents 4c316f0 + 793d45d commit 6f2126a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 23 deletions.
Expand Up @@ -259,21 +259,18 @@ public void load() throws GitException {
conflicting = new ArrayList<>();
for (String statusLine : statusOutput) {
//add conflict files AA, UU, any of U
addIfMatches(conflicting, statusLine, 'A', 'A');
addIfMatches(conflicting, statusLine, 'U', '*');
addIfMatches(conflicting, statusLine, '*', 'U');
//add Added files
addIfMatches(added, statusLine, 'A', 'M');
addIfMatches(added, statusLine, 'A', ' ');
//add Changed
addIfMatches(changed, statusLine, 'M', '*');
//add removed
addIfMatches(removed, statusLine, 'D', '*');
addIfMatches(removed, statusLine, ' ', 'D');
//add missing
addIfMatches(missing, statusLine, 'A', 'D');
//add modified
addIfMatches(modified, statusLine, '*', 'M');
if (!(addIfMatches(conflicting, statusLine, 'A', 'A') //
|| addIfMatches(conflicting, statusLine, 'D', 'D') //
|| addIfMatches(conflicting, statusLine, 'U', '*') //
|| addIfMatches(conflicting, statusLine, '*', 'U'))) {
// Add index-based entries
addIfMatches(added, statusLine, 'A', '*');
addIfMatches(removed, statusLine, 'D', '*');
addIfMatches(changed, statusLine, 'M', '*');
// Add working tree - based entries
addIfMatches(missing, statusLine, '*', 'D');
addIfMatches(modified, statusLine, '*', 'M');
}
if (statusLine.endsWith("/")) {
//add untracked folders
addIfMatches(untrackedFolders, statusLine.substring(0, statusLine.length() - 1), '?', '?');
Expand All @@ -297,18 +294,19 @@ public void load() throws GitException {
* @param y
* second template parameter
*/
private void addIfMatches(List<String> container, String statusLine, char x, char y) {
private static boolean addIfMatches(List<String> container, String statusLine, char x, char y) {
if (matches(statusLine, x, y)) {
final String filename = statusLine.substring(3);
if (!container.contains(filename)) {
container.add(filename);
}
return true;
}
return false;
}

private boolean matches(String statusLine, char x, char y) {
return x == '*' && statusLine.charAt(1) == y ||
y == '*' && statusLine.charAt(0) == x ||
x == statusLine.charAt(0) && y == statusLine.charAt(1);
private static boolean matches(String statusLine, char x, char y) {
return (x == '*' || x == statusLine.charAt(0)) &&
(y == '*' || y == statusLine.charAt(1));
}
}
Expand Up @@ -185,7 +185,7 @@ public void testMissing() throws Exception {
final Status status = getConnection().status(SHORT);

assertEquals(status.getMissing(), asList("a"));
assertTrue(status.getAdded().isEmpty());
assertEquals(status.getAdded(), asList("a"));
assertTrue(status.getChanged().isEmpty());
assertTrue(status.getConflicting().isEmpty());
assertTrue(status.getRemoved().isEmpty());
Expand All @@ -206,11 +206,11 @@ public void testRemovedFromFilesSystem() throws Exception {

final Status status = getConnection().status(SHORT);

assertEquals(status.getRemoved(), asList("a"));
assertTrue(status.getRemoved().isEmpty());
assertTrue(status.getAdded().isEmpty());
assertTrue(status.getChanged().isEmpty());
assertTrue(status.getConflicting().isEmpty());
assertTrue(status.getMissing().isEmpty());
assertEquals(status.getMissing(), asList("a"));
assertTrue(status.getUntracked().isEmpty());
assertTrue(status.getUntrackedFolders().isEmpty());
}
Expand Down

0 comments on commit 6f2126a

Please sign in to comment.