Skip to content

Commit 0c549c7

Browse files
committed
Make CommitList display: Working tree clean
1 parent 04991eb commit 0c549c7

File tree

1 file changed

+25
-12
lines changed

1 file changed

+25
-12
lines changed

src/ui/CommitList.cpp

+25-12
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,17 @@ class CommitModel : public QAbstractListModel {
150150
resetWalker();
151151
}
152152

153+
bool is_working_tree_clean(void) const {
154+
if (mStatus.isRunning()) {
155+
return false;
156+
}
157+
git::Diff stat = status();
158+
if (!stat.isValid()) {
159+
return true;
160+
}
161+
return stat.count() == 0;
162+
}
163+
153164
void suppressResetWalker(bool suppress) { mSuppressResetWalker = suppress; }
154165

155166
bool isResetWalkerSuppressed() { return mSuppressResetWalker; }
@@ -186,8 +197,8 @@ class CommitModel : public QAbstractListModel {
186197

187198
// Update status row.
188199
bool head = (!mRef.isValid() || mRef.isHead());
189-
bool valid = (!mStatus.isFinished() || status().isValid());
190-
if (mShowCleanStatus && head && valid && mPathspec.isEmpty()) {
200+
if (mShowCleanStatus && head && mStatus.isFinished() &&
201+
mPathspec.isEmpty()) {
191202
QVector<Column> row;
192203
if (mGraphVisible && mRef.isValid() && mStatus.isFinished()) {
193204
row.append({Segment(Bottom, kTaintedColor), Segment(Dot, QColor())});
@@ -322,17 +333,19 @@ class CommitModel : public QAbstractListModel {
322333

323334
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const {
324335
const Row &row = mRows.at(index.row());
325-
bool status = !row.commit.isValid();
336+
bool commit_is_valid = row.commit.isValid();
337+
326338
switch (role) {
327339
case Qt::DisplayRole:
328-
if (!status)
340+
if (commit_is_valid)
329341
return QVariant();
330-
331-
return mStatus.isFinished() ? tr("Uncommitted changes")
332-
: tr("Checking for uncommitted changes");
342+
if (!mStatus.isFinished())
343+
return tr("Checking for uncommitted changes");
344+
return is_working_tree_clean() ? tr("Working tree clean")
345+
: tr("Uncommitted changes");
333346

334347
case Qt::FontRole: {
335-
if (!status)
348+
if (commit_is_valid)
336349
return QVariant();
337350

338351
QFont font = static_cast<QWidget *>(QObject::parent())->font();
@@ -341,19 +354,19 @@ class CommitModel : public QAbstractListModel {
341354
}
342355

343356
case Qt::TextAlignmentRole:
344-
if (!status)
357+
if (commit_is_valid)
345358
return QVariant();
346359

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

349362
case Qt::DecorationRole:
350-
if (!status)
363+
if (commit_is_valid)
351364
return QVariant();
352365

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

355368
case CommitList::Role::DiffRole: {
356-
if (status)
369+
if (!commit_is_valid)
357370
return QVariant::fromValue(this->status());
358371

359372
bool ignoreWhitespace = Settings::instance()->isWhitespaceIgnored();
@@ -363,7 +376,7 @@ class CommitModel : public QAbstractListModel {
363376
}
364377

365378
case CommitList::Role::CommitRole:
366-
return status ? QVariant() : QVariant::fromValue(row.commit);
379+
return commit_is_valid ? QVariant::fromValue(row.commit) : QVariant();
367380

368381
case CommitList::Role::GraphRole: {
369382
QVariantList columns;

0 commit comments

Comments
 (0)