From fd3bd4f8aa2dc6dafaedd9bcbe78b5f23f3dc17d Mon Sep 17 00:00:00 2001 From: Ryan Jensen Date: Tue, 5 Mar 2024 00:28:18 -0600 Subject: [PATCH] Make CommitList display: Working tree clean --- src/ui/CommitList.cpp | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/src/ui/CommitList.cpp b/src/ui/CommitList.cpp index a126c7479..03989940a 100644 --- a/src/ui/CommitList.cpp +++ b/src/ui/CommitList.cpp @@ -150,6 +150,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; } @@ -186,8 +197,8 @@ class CommitModel : public QAbstractListModel { // Update status row. bool head = (!mRef.isValid() || mRef.isHead()); - bool valid = (!mStatus.isFinished() || status().isValid()); - if (mShowCleanStatus && head && valid && mPathspec.isEmpty()) { + if (mShowCleanStatus && head && mStatus.isFinished() && + mPathspec.isEmpty()) { QVector row; if (mGraphVisible && mRef.isValid() && mStatus.isFinished()) { row.append({Segment(Bottom, kTaintedColor), Segment(Dot, QColor())}); @@ -322,17 +333,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(QObject::parent())->font(); @@ -341,19 +354,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(); @@ -363,7 +376,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;