forked from qt-creator/qt-creator
Git - stash scope guard in submoduleUpdate
Change-Id: I888d4013e88fdc6977f29ef3e27d243e55a1f1a7 Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
@@ -1237,7 +1237,7 @@ bool GitClient::synchronousCheckout(const QString &workingDirectory,
|
||||
outputWindow()->appendError(msg);
|
||||
return false;
|
||||
}
|
||||
promptSubmoduleUpdate(workingDirectory);
|
||||
updateSubmodulesIfNeeded(workingDirectory, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1951,6 +1951,30 @@ QMap<QString,QString> GitClient::synchronousRemotesList(const QString &workingDi
|
||||
return result;
|
||||
}
|
||||
|
||||
QStringList GitClient::synchronousSubmoduleStatus(const QString &workingDirectory,
|
||||
QString *errorMessage)
|
||||
{
|
||||
QByteArray outputTextData;
|
||||
QByteArray errorText;
|
||||
QStringList arguments;
|
||||
|
||||
// get submodule status
|
||||
arguments << QLatin1String("submodule") << QLatin1String("status");
|
||||
if (!fullySynchronousGit(workingDirectory, arguments, &outputTextData, &errorText)) {
|
||||
QString error = tr("Cannot retrieve submodule status of \"%1\": %2")
|
||||
.arg(QDir::toNativeSeparators(workingDirectory),
|
||||
commandOutputFromLocal8Bit(errorText));
|
||||
|
||||
if (errorMessage)
|
||||
*errorMessage = error;
|
||||
else
|
||||
outputWindow()->append(error);
|
||||
|
||||
return QStringList();
|
||||
}
|
||||
return commandOutputLinesFromLocal8Bit(outputTextData);
|
||||
}
|
||||
|
||||
SubmoduleDataMap GitClient::submoduleList(const QString &workingDirectory)
|
||||
{
|
||||
SubmoduleDataMap result;
|
||||
@@ -2201,23 +2225,63 @@ bool GitClient::fullySynchronousGit(const QString &workingDirectory,
|
||||
flags);
|
||||
}
|
||||
|
||||
void GitClient::submoduleUpdate(const QString &workingDirectory)
|
||||
void GitClient::updateSubmodulesIfNeeded(const QString &workingDirectory, bool prompt)
|
||||
{
|
||||
QStringList arguments;
|
||||
arguments << QLatin1String("submodule") << QLatin1String("update");
|
||||
executeGit(workingDirectory, arguments, 0, true, true);
|
||||
}
|
||||
|
||||
void GitClient::promptSubmoduleUpdate(const QString &workingDirectory)
|
||||
{
|
||||
if (submoduleList(workingDirectory).isEmpty())
|
||||
if (!m_updatedSubmodules.isEmpty() || submoduleList(workingDirectory).isEmpty())
|
||||
return;
|
||||
|
||||
if (QMessageBox::question(Core::ICore::mainWindow(), tr("Submodules Found"),
|
||||
tr("Would you like to update submodules?"),
|
||||
QMessageBox::Yes, QMessageBox::No) == QMessageBox::Yes) {
|
||||
submoduleUpdate(workingDirectory);
|
||||
QStringList submoduleStatus = synchronousSubmoduleStatus(workingDirectory);
|
||||
if (submoduleStatus.isEmpty())
|
||||
return;
|
||||
|
||||
bool updateNeeded = false;
|
||||
foreach (const QString &status, submoduleStatus) {
|
||||
if (status.startsWith(QLatin1Char('+'))) {
|
||||
updateNeeded = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!updateNeeded)
|
||||
return;
|
||||
|
||||
if (prompt && QMessageBox::question(Core::ICore::mainWindow(), tr("Submodules Found"),
|
||||
tr("Would you like to update submodules?"),
|
||||
QMessageBox::Yes | QMessageBox::No) == QMessageBox::No) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (const QString &statusLine, submoduleStatus) {
|
||||
// stash only for lines starting with +
|
||||
// because only they would be updated
|
||||
if (!statusLine.startsWith(QLatin1Char('+')))
|
||||
continue;
|
||||
|
||||
// get submodule name
|
||||
const int nameStart = statusLine.indexOf(QLatin1Char(' '), 2) + 1;
|
||||
const int nameLength = statusLine.indexOf(QLatin1Char(' '), nameStart) - nameStart;
|
||||
const QString submoduleDir = workingDirectory + QLatin1Char('/')
|
||||
+ statusLine.mid(nameStart, nameLength);
|
||||
|
||||
if (beginStashScope(submoduleDir, QLatin1String("SubmoduleUpdate"))) {
|
||||
m_updatedSubmodules.append(submoduleDir);
|
||||
} else {
|
||||
finishSubmoduleUpdate();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
QStringList arguments;
|
||||
arguments << QLatin1String("submodule") << QLatin1String("update");
|
||||
|
||||
VcsBase::Command *cmd = executeGit(workingDirectory, arguments, 0, true, true);
|
||||
connect(cmd, SIGNAL(finished(bool,int,QVariant)), this, SLOT(finishSubmoduleUpdate()));
|
||||
}
|
||||
|
||||
void GitClient::finishSubmoduleUpdate()
|
||||
{
|
||||
foreach (const QString &submoduleDir, m_updatedSubmodules)
|
||||
endStashScope(submoduleDir);
|
||||
m_updatedSubmodules.clear();
|
||||
}
|
||||
|
||||
// Trim a git status file spec: "modified: foo .cpp" -> "modified: foo .cpp"
|
||||
@@ -2852,7 +2916,7 @@ bool GitClient::synchronousPull(const QString &workingDirectory, bool rebase)
|
||||
bool ok = executeAndHandleConflicts(workingDirectory, arguments, abortCommand);
|
||||
|
||||
if (ok)
|
||||
promptSubmoduleUpdate(workingDirectory);
|
||||
updateSubmodulesIfNeeded(workingDirectory, true);
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
@@ -179,8 +179,7 @@ public:
|
||||
bool synchronousCheckout(const QString &workingDirectory, const QString &ref, QString *errorMessage);
|
||||
bool synchronousCheckout(const QString &workingDirectory, const QString &ref)
|
||||
{ return synchronousCheckout(workingDirectory, ref, 0); }
|
||||
void submoduleUpdate(const QString &workingDirectory);
|
||||
void promptSubmoduleUpdate(const QString &workingDirectory);
|
||||
void updateSubmodulesIfNeeded(const QString &workingDirectory, bool prompt);
|
||||
|
||||
// Do a stash and return identier.
|
||||
enum { StashPromptDescription = 0x1, StashImmediateRestore = 0x2, StashIgnoreUnchanged = 0x4 };
|
||||
@@ -208,6 +207,8 @@ public:
|
||||
|
||||
QMap<QString,QString> synchronousRemotesList(const QString &workingDirectory,
|
||||
QString *errorMessage = 0);
|
||||
QStringList synchronousSubmoduleStatus(const QString &workingDirectory,
|
||||
QString *errorMessage = 0);
|
||||
SubmoduleDataMap submoduleList(const QString &workingDirectory);
|
||||
bool synchronousShow(const QString &workingDirectory, const QString &id,
|
||||
QString *output, QString *errorMessage);
|
||||
@@ -324,6 +325,7 @@ private slots:
|
||||
void slotBlameRevisionRequested(const QString &source, QString change, int lineNumber);
|
||||
void appendOutputData(const QByteArray &data) const;
|
||||
void appendOutputDataSilently(const QByteArray &data) const;
|
||||
void finishSubmoduleUpdate();
|
||||
|
||||
private:
|
||||
QTextCodec *getSourceCodec(const QString &file) const;
|
||||
@@ -392,6 +394,7 @@ private:
|
||||
GitSettings *m_settings;
|
||||
QString m_gitQtcEditor;
|
||||
QMap<QString, StashInfo> m_stashInfo;
|
||||
QStringList m_updatedSubmodules;
|
||||
bool m_disableEditor;
|
||||
};
|
||||
|
||||
|
||||
@@ -1237,7 +1237,7 @@ void GitPlugin::updateSubmodules()
|
||||
{
|
||||
const VcsBase::VcsBasePluginState state = currentState();
|
||||
QTC_ASSERT(state.hasTopLevel(), return);
|
||||
m_gitClient->submoduleUpdate(state.topLevel());
|
||||
m_gitClient->updateSubmodulesIfNeeded(state.topLevel(), false);
|
||||
}
|
||||
|
||||
// If the file is modified in an editor, make sure it is saved.
|
||||
|
||||
Reference in New Issue
Block a user