aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/git/gitclient.cpp
diff options
context:
space:
mode:
authorFriedemann Kleint <[email protected]>2008-12-19 11:45:30 +0100
committerFriedemann Kleint <[email protected]>2008-12-19 11:45:30 +0100
commit4db2f99836cdf22a98609631147ebce401ef8a60 (patch)
treea78a71961ca0c6c1a112c01b5c320828bf3f2cfd /src/plugins/git/gitclient.cpp
parentd6fbb1b5730eac0b06ee6bfcbae71075ab6e57bd (diff)
Fixes: Add ensureStashed() method asking user to stash before a change such as pull
Diffstat (limited to 'src/plugins/git/gitclient.cpp')
-rw-r--r--src/plugins/git/gitclient.cpp83
1 files changed, 71 insertions, 12 deletions
diff --git a/src/plugins/git/gitclient.cpp b/src/plugins/git/gitclient.cpp
index f4a0feb33e7..83dafdc1b66 100644
--- a/src/plugins/git/gitclient.cpp
+++ b/src/plugins/git/gitclient.cpp
@@ -379,6 +379,23 @@ bool GitClient::synchronousCheckout(const QString &workingDirectory,
return true;
}
+bool GitClient::synchronousStash(const QString &workingDirectory, QString *errorMessage)
+{
+ if (Git::Constants::debug)
+ qDebug() << Q_FUNC_INFO << workingDirectory;
+ QByteArray outputText;
+ QByteArray errorText;
+ QStringList arguments;
+ arguments << QLatin1String("stash");
+ const bool rc = synchronousGit(workingDirectory, arguments, &outputText, &errorText);
+ if (!rc) {
+ *errorMessage = tr("Unable stash in %1: %2").arg(workingDirectory, QString::fromLocal8Bit(errorText));
+ return false;
+ }
+ return true;
+}
+
+
void GitClient::executeGit(const QString &workingDirectory, const QStringList &arguments,
VCSBase::VCSBaseEditor* editor,
bool outputToWindow)
@@ -467,6 +484,60 @@ bool GitClient::synchronousGit(const QString &workingDirectory,
return process.exitCode() == 0;
}
+static inline int
+ askWithDetailedText(QWidget *parent,
+ const QString &title, const QString &msg,
+ const QString &inf,
+ QMessageBox::StandardButton defaultButton,
+ QMessageBox::StandardButtons buttons = QMessageBox::Yes|QMessageBox::No)
+{
+ QMessageBox msgBox(QMessageBox::Question, title, msg, buttons, parent);
+ msgBox.setDetailedText(inf);
+ msgBox.setDefaultButton(defaultButton);
+ return msgBox.exec();
+}
+
+// Convenience that pops up an msg box.
+GitClient::StashResult GitClient::ensureStash(const QString &workingDirectory)
+{
+ QString errorMessage;
+ const StashResult sr = ensureStash(workingDirectory, &errorMessage);
+ if (sr == StashFailed) {
+ m_plugin->outputWindow()->append(errorMessage);
+ m_plugin->outputWindow()->popup();
+ }
+ return sr;
+}
+
+// Ensure that changed files are stashed before a pull or similar
+GitClient::StashResult GitClient::ensureStash(const QString &workingDirectory, QString *errorMessage)
+{
+ QString statusOutput;
+ switch (gitStatus(workingDirectory, false, &statusOutput, errorMessage)) {
+ case StatusChanged:
+ break;
+ case StatusUnchanged:
+ return StashUnchanged;
+ case StatusFailed:
+ return StashFailed;
+ }
+
+ const int answer = askWithDetailedText(m_core->mainWindow(), tr("Changes"),
+ tr("You have modified files. Would you like to stash your changes?"),
+ statusOutput, QMessageBox::Yes, QMessageBox::Yes|QMessageBox::No|QMessageBox::Cancel);
+ switch (answer) {
+ case QMessageBox::Cancel:
+ return StashCanceled;
+ case QMessageBox::Yes:
+ if (!synchronousStash(workingDirectory, errorMessage))
+ return StashFailed;
+ break;
+ case QMessageBox::No: // At your own risk, so.
+ return NotStashed;
+ }
+
+ return Stashed;
+ }
// Trim a git status file spec: "modified: foo .cpp" -> "modified: foo .cpp"
static inline QString trimFileSpecification(QString fileSpec)
@@ -703,18 +774,6 @@ bool GitClient::addAndCommit(const QString &repositoryDirectory,
return rc;
}
-static inline bool askWithInformativeText(QWidget *parent,
- const QString &title,
- const QString &msg,
- const QString &inf,
- bool defaultValue)
-{
- QMessageBox msgBox(QMessageBox::Question, title, msg, QMessageBox::Yes|QMessageBox::No, parent);
- msgBox.setInformativeText(inf);
- msgBox.setDefaultButton(defaultValue ? QMessageBox::Yes : QMessageBox::No);
- return msgBox.exec() == QMessageBox::Yes;
-}
-
/* Revert: This function can be called with a file list (to revert single
* files) or a single directory (revert all). Qt Creator currently has only
* 'revert single' in its VCS menus, but the code is prepared to deal with