Skip to content

Commit

Permalink
Make CommitList display: Working tree clean
Browse files Browse the repository at this point in the history
  • Loading branch information
jensenr30 committed Mar 5, 2024
1 parent 5d80918 commit 0d30464
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions src/ui/CommitList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,17 @@ class CommitModel : public QAbstractListModel {
resetWalker();
}

bool is_working_tree_clean(void) const {
if (mStatus.isRunning()) {
return false;
}
git::Diff stat = status();
if (!stat.isValid()) {
return true;
}
return stat.count() == 0;
}

void suppressResetWalker(bool suppress) { mSuppressResetWalker = suppress; }

bool isResetWalkerSuppressed() { return mSuppressResetWalker; }
Expand Down Expand Up @@ -321,17 +332,19 @@ class CommitModel : public QAbstractListModel {

QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const {
const Row &row = mRows.at(index.row());
bool status = !row.commit.isValid();
bool commit_is_valid = row.commit.isValid();

switch (role) {
case Qt::DisplayRole:
if (!status)
if (commit_is_valid)
return QVariant();

return mStatus.isFinished() ? tr("Uncommitted changes")
: tr("Checking for uncommitted changes");
if (!mStatus.isFinished())
return tr("Checking for uncommitted changes");
return is_working_tree_clean() ? tr("Working tree clean")
: tr("Uncommitted changes");

case Qt::FontRole: {
if (!status)
if (commit_is_valid)
return QVariant();

QFont font = static_cast<QWidget *>(QObject::parent())->font();
Expand All @@ -340,19 +353,19 @@ class CommitModel : public QAbstractListModel {
}

case Qt::TextAlignmentRole:
if (!status)
if (commit_is_valid)
return QVariant();

return QVariant(Qt::AlignHCenter | Qt::AlignVCenter);

case Qt::DecorationRole:
if (!status)
if (commit_is_valid)
return QVariant();

return mStatus.isFinished() ? QVariant() : mProgress;

case CommitList::Role::DiffRole: {
if (status)
if (!commit_is_valid)
return QVariant::fromValue(this->status());

bool ignoreWhitespace = Settings::instance()->isWhitespaceIgnored();
Expand All @@ -362,7 +375,7 @@ class CommitModel : public QAbstractListModel {
}

case CommitList::Role::CommitRole:
return status ? QVariant() : QVariant::fromValue(row.commit);
return commit_is_valid ? QVariant::fromValue(row.commit) : QVariant();

case CommitList::Role::GraphRole: {
QVariantList columns;
Expand Down

0 comments on commit 0d30464

Please sign in to comment.