What do you think about the following? It removes the branch string and the += performed on it which creates an unneeded extra string.

string.append(' ');

string.append('[', StyledString.DECORATIONS_STYLER);

string.append(repository.getBranch(), StyledString.DECORATIONS_STYLER);

RepositoryState state = repository.getRepositoryState();

if (state != RepositoryState.SAFE) {

string.append(" - ", StyledString.DECORATIONS_STYLER);

string.append(state.getDescription(), StyledString.DECORATIONS_STYLER);

}

string.append(']', StyledString.DECORATIONS_STYLER);