diff options
author | Jarek Kobus <jaroslaw.kobus@qt.io> | 2022-09-19 09:53:34 +0200 |
---|---|---|
committer | Jarek Kobus <jaroslaw.kobus@qt.io> | 2022-09-20 10:41:06 +0000 |
commit | 012de6b4c3cee7d840a824762bf4c00b535ed187 (patch) | |
tree | 057b8d122952e0be75d4b116bc5fb1d24eea919e /src/plugins/git | |
parent | 85c5edcb6bb0b6e57b90b96a07ddf296da40ab4c (diff) |
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>
Diffstat (limited to 'src/plugins/git')
-rw-r--r-- | src/plugins/git/gitclient.cpp | 62 |
1 files changed, 33 insertions, 29 deletions
diff --git a/src/plugins/git/gitclient.cpp b/src/plugins/git/gitclient.cpp index bc476ed71f..8066adac9b 100644 --- a/src/plugins/git/gitclient.cpp +++ b/src/plugins/git/gitclient.cpp @@ -3263,37 +3263,18 @@ public: nullptr, true, VcsCommand::ShowSuccessMessage); // Make command a parent of this in order to delete this when command is deleted setParent(command); - - connect(command, &VcsCommand::stdErrText, this, [this](const QString &text) { - if (text.contains("non-fast-forward")) { - m_pushFailure = NonFastForward; - } 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) { + connect(command, &VcsCommand::finished, this, [=](bool success) { + QString pushFallbackCommand; + const PushFailure pushFailure = handleError(command->cleanedStdErr(), + &pushFallbackCommand); if (success) { GitPlugin::updateCurrentBranch(); return; } - if (m_pushFailure == Unknown || !m_gitClient) + if (pushFailure == Unknown || !m_gitClient) return; - if (m_pushFailure == NonFastForward) { + if (pushFailure == NonFastForward) { const QColor warnColor = Utils::creatorTheme()->color(Theme::TextColorError); if (QMessageBox::question( Core::ICore::dialogParent(), tr("Force Push"), @@ -3326,9 +3307,9 @@ public: return; } const QStringList fallbackCommandParts = - m_pushFallbackCommand.split(' ', Qt::SkipEmptyParts); + pushFallbackCommand.split(' ', Qt::SkipEmptyParts); 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) { if (success) GitPlugin::updateBranches(workingDir); @@ -3336,9 +3317,32 @@ public: }); } 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; - QString m_pushFallbackCommand; }; void GitClient::push(const FilePath &workingDirectory, const QStringList &pushArgs) |