forked from qt-creator/qt-creator
PushHandler: Use cleanedStdErr()
Instead of connecting to stdErrText() signal. Change-Id: Ib9fb94ca3fb0b5cbf4871e0ea3b06a047c31d272 Reviewed-by: Orgad Shaneh <orgads@gmail.com> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
@@ -3263,37 +3263,18 @@ public:
|
|||||||
nullptr, true, VcsCommand::ShowSuccessMessage);
|
nullptr, true, VcsCommand::ShowSuccessMessage);
|
||||||
// Make command a parent of this in order to delete this when command is deleted
|
// Make command a parent of this in order to delete this when command is deleted
|
||||||
setParent(command);
|
setParent(command);
|
||||||
|
connect(command, &VcsCommand::finished, this, [=](bool success) {
|
||||||
connect(command, &VcsCommand::stdErrText, this, [this](const QString &text) {
|
QString pushFallbackCommand;
|
||||||
if (text.contains("non-fast-forward")) {
|
const PushFailure pushFailure = handleError(command->cleanedStdErr(),
|
||||||
m_pushFailure = NonFastForward;
|
&pushFallbackCommand);
|
||||||
} else if (text.contains("has no upstream branch")) {
|
|
||||||
m_pushFailure = NoRemoteBranch;
|
|
||||||
const QStringList lines = text.split('\n', Qt::SkipEmptyParts);
|
|
||||||
for (const QString &line : lines) {
|
|
||||||
/* Extract the suggested command from the git output which
|
|
||||||
* should be similar to the following:
|
|
||||||
*
|
|
||||||
* git push --set-upstream origin add_set_upstream_dialog
|
|
||||||
*/
|
|
||||||
const QString trimmedLine = line.trimmed();
|
|
||||||
if (trimmedLine.startsWith("git push")) {
|
|
||||||
m_pushFallbackCommand = trimmedLine;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
connect(command, &VcsCommand::finished, this, [this, workingDir, pushArgs](bool success) {
|
|
||||||
if (success) {
|
if (success) {
|
||||||
GitPlugin::updateCurrentBranch();
|
GitPlugin::updateCurrentBranch();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (m_pushFailure == Unknown || !m_gitClient)
|
if (pushFailure == Unknown || !m_gitClient)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (m_pushFailure == NonFastForward) {
|
if (pushFailure == NonFastForward) {
|
||||||
const QColor warnColor = Utils::creatorTheme()->color(Theme::TextColorError);
|
const QColor warnColor = Utils::creatorTheme()->color(Theme::TextColorError);
|
||||||
if (QMessageBox::question(
|
if (QMessageBox::question(
|
||||||
Core::ICore::dialogParent(), tr("Force Push"),
|
Core::ICore::dialogParent(), tr("Force Push"),
|
||||||
@@ -3326,9 +3307,9 @@ public:
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const QStringList fallbackCommandParts =
|
const QStringList fallbackCommandParts =
|
||||||
m_pushFallbackCommand.split(' ', Qt::SkipEmptyParts);
|
pushFallbackCommand.split(' ', Qt::SkipEmptyParts);
|
||||||
VcsCommand *rePushCommand = m_gitClient->vcsExec(workingDir,
|
VcsCommand *rePushCommand = m_gitClient->vcsExec(workingDir,
|
||||||
fallbackCommandParts.mid(1), nullptr, true, VcsCommand::ShowSuccessMessage);
|
fallbackCommandParts.mid(1), nullptr, true, VcsCommand::ShowSuccessMessage);
|
||||||
connect(rePushCommand, &VcsCommand::finished, this, [workingDir](bool success) {
|
connect(rePushCommand, &VcsCommand::finished, this, [workingDir](bool success) {
|
||||||
if (success)
|
if (success)
|
||||||
GitPlugin::updateBranches(workingDir);
|
GitPlugin::updateBranches(workingDir);
|
||||||
@@ -3336,9 +3317,32 @@ public:
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
enum PushFailure { Unknown, NonFastForward, NoRemoteBranch } m_pushFailure = Unknown;
|
enum PushFailure { Unknown, NonFastForward, NoRemoteBranch };
|
||||||
|
|
||||||
|
PushFailure handleError(const QString &text, QString *pushFallbackCommand) const {
|
||||||
|
if (text.contains("non-fast-forward"))
|
||||||
|
return NonFastForward;
|
||||||
|
|
||||||
|
if (text.contains("has no upstream branch")) {
|
||||||
|
const QStringList lines = text.split('\n', Qt::SkipEmptyParts);
|
||||||
|
for (const QString &line : lines) {
|
||||||
|
/* Extract the suggested command from the git output which
|
||||||
|
* should be similar to the following:
|
||||||
|
*
|
||||||
|
* git push --set-upstream origin add_set_upstream_dialog
|
||||||
|
*/
|
||||||
|
const QString trimmedLine = line.trimmed();
|
||||||
|
if (trimmedLine.startsWith("git push")) {
|
||||||
|
*pushFallbackCommand = trimmedLine;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return NoRemoteBranch;
|
||||||
|
}
|
||||||
|
return Unknown;
|
||||||
|
};
|
||||||
|
|
||||||
QPointer<GitClient> m_gitClient;
|
QPointer<GitClient> m_gitClient;
|
||||||
QString m_pushFallbackCommand;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void GitClient::push(const FilePath &workingDirectory, const QStringList &pushArgs)
|
void GitClient::push(const FilePath &workingDirectory, const QStringList &pushArgs)
|
||||||
|
Reference in New Issue
Block a user