Commit ef04b65e authored by Waqar Ahmed's avatar Waqar Ahmed
Browse files

Implement Unstaging backend/UI

parent b32d8c19
......@@ -31,6 +31,11 @@ public:
return m_nodes[3];
}
const QVector<GitUtils::StatusItem> &stagedFiles() const
{
return m_nodes[0];
}
const QVector<GitUtils::StatusItem> &changedFiles() const
{
return m_nodes[1];
......
......@@ -95,6 +95,33 @@ void GitWidget::stage(const QString &file, bool untracked)
}
}
void GitWidget::unstage(const QString &file)
{
// git reset -q HEAD --
auto args = QStringList{QStringLiteral("reset"), QStringLiteral("-q"), QStringLiteral("HEAD"), QStringLiteral("--")};
// all
if (file.isEmpty()) {
const QVector<GitUtils::StatusItem> &files = m_model->stagedFiles();
args.reserve(args.size() + files.size());
for (const auto &file : files) {
args.append(file.file);
}
} else {
// one file
args.append(file);
}
git.setWorkingDirectory(m_project->baseDir());
git.setProgram(QStringLiteral("git"));
git.setArguments(args);
git.start();
if (git.waitForStarted() && git.waitForFinished(-1)) {
getStatus(m_project->baseDir());
}
}
void GitWidget::gitStatusReady()
{
disconnect(&git, &QProcess::readyRead, this, &GitWidget::gitStatusReady);
......@@ -239,19 +266,25 @@ void GitWidget::treeViewContextMenuEvent(QContextMenuEvent *e)
}
} else if (type == GitStatusModel::NodeFile) {
QMenu menu;
auto stageAct = menu.addAction(i18n("Stage file"));
bool unstaging = idx.internalId() == GitStatusModel::NodeStage;
auto stageAct = unstaging ? menu.addAction(i18n("Unstage file")) : menu.addAction(i18n("Stage file"));
auto act = menu.exec(m_treeView->viewport()->mapToGlobal(e->pos()));
const QString file = QString(m_project->baseDir() + QStringLiteral("/") + idx.data().toString());
if (act == stageAct) {
stage(QString(m_project->baseDir() + QStringLiteral("/") + idx.data().toString()));
if (unstaging) {
return unstage(file);
}
return stage(file);
}
} else if (type == GitStatusModel::NodeStage) {
QMenu menu;
auto stage = menu.addAction(i18n("Unstage All"));
auto act = menu.exec(m_treeView->viewport()->mapToGlobal(e->pos()));
// git reset -q HEAD --
if (act == stage) {
hideEmptyTreeNodes();
unstage(QString());
}
}
}
......@@ -39,6 +39,7 @@ private:
void getStatus(const QString &repo, bool untracked = true, bool submodules = false);
void stage(const QString &file, bool untracked = false);
void unstage(const QString &file);
GitParsedStatus parseStatus(const QByteArray &raw);
void hideEmptyTreeNodes();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment