Git: Continue command after failed merge tool attempt

Change-Id: Ic3b7d4aee51897e226a78979bbecb82f06095b2d
Reviewed-by: Tobias Hunger <tobias.hunger@digia.com>
This commit is contained in:
Orgad Shaneh
2014-03-27 13:40:32 +02:00
committed by Orgad Shaneh
parent fec491a290
commit 187bb36945
3 changed files with 35 additions and 16 deletions

View File

@@ -2782,31 +2782,35 @@ GitClient::CommandInProgress GitClient::checkCommandInProgress(const QString &wo
return NoCommand; return NoCommand;
} }
void GitClient::continueCommandIfNeeded(const QString &workingDirectory) void GitClient::continueCommandIfNeeded(const QString &workingDirectory, bool allowContinue)
{ {
CommandInProgress command = checkCommandInProgress(workingDirectory); CommandInProgress command = checkCommandInProgress(workingDirectory);
ContinueCommandMode continueMode;
if (allowContinue)
continueMode = command == RebaseMerge ? ContinueOnly : SkipIfNoChanges;
else
continueMode = SkipOnly;
switch (command) { switch (command) {
case Rebase: case Rebase:
case RebaseMerge: case RebaseMerge:
continuePreviousGitCommand(workingDirectory, tr("Continue Rebase"), continuePreviousGitCommand(workingDirectory, tr("Continue Rebase"),
tr("Rebase is in progress. What do you want to do?"), tr("Rebase is in progress. What do you want to do?"),
tr("Continue"), QLatin1String("rebase"), tr("Continue"), QLatin1String("rebase"), continueMode);
command != RebaseMerge);
break; break;
case Merge: case Merge:
continuePreviousGitCommand(workingDirectory, tr("Continue Merge"), continuePreviousGitCommand(workingDirectory, tr("Continue Merge"),
tr("You need to commit changes to finish merge.\nCommit now?"), tr("You need to commit changes to finish merge.\nCommit now?"),
tr("Commit"), QLatin1String("merge")); tr("Commit"), QLatin1String("merge"), continueMode);
break; break;
case Revert: case Revert:
continuePreviousGitCommand(workingDirectory, tr("Continue Revert"), continuePreviousGitCommand(workingDirectory, tr("Continue Revert"),
tr("You need to commit changes to finish revert.\nCommit now?"), tr("You need to commit changes to finish revert.\nCommit now?"),
tr("Commit"), QLatin1String("revert")); tr("Commit"), QLatin1String("revert"), continueMode);
break; break;
case CherryPick: case CherryPick:
continuePreviousGitCommand(workingDirectory, tr("Continue Cherry-Picking"), continuePreviousGitCommand(workingDirectory, tr("Continue Cherry-Picking"),
tr("You need to commit changes to finish cherry-picking.\nCommit now?"), tr("You need to commit changes to finish cherry-picking.\nCommit now?"),
tr("Commit"), QLatin1String("cherry-pick")); tr("Commit"), QLatin1String("cherry-pick"), continueMode);
break; break;
default: default:
break; break;
@@ -2816,18 +2820,25 @@ void GitClient::continueCommandIfNeeded(const QString &workingDirectory)
void GitClient::continuePreviousGitCommand(const QString &workingDirectory, void GitClient::continuePreviousGitCommand(const QString &workingDirectory,
const QString &msgBoxTitle, QString msgBoxText, const QString &msgBoxTitle, QString msgBoxText,
const QString &buttonName, const QString &gitCommand, const QString &buttonName, const QString &gitCommand,
bool requireChanges) ContinueCommandMode continueMode)
{ {
bool isRebase = gitCommand == QLatin1String("rebase"); bool isRebase = gitCommand == QLatin1String("rebase");
bool hasChanges; bool hasChanges = false;
if (!requireChanges) { switch (continueMode) {
case ContinueOnly:
hasChanges = true; hasChanges = true;
} else { break;
case SkipIfNoChanges:
hasChanges = gitStatus(workingDirectory, StatusMode(NoUntracked | NoSubmodules)) hasChanges = gitStatus(workingDirectory, StatusMode(NoUntracked | NoSubmodules))
== GitClient::StatusChanged; == GitClient::StatusChanged;
}
if (!hasChanges) if (!hasChanges)
msgBoxText.prepend(tr("No changes found.") + QLatin1Char(' ')); msgBoxText.prepend(tr("No changes found.") + QLatin1Char(' '));
break;
case SkipOnly:
hasChanges = false;
break;
}
QMessageBox msgBox(QMessageBox::Question, msgBoxTitle, msgBoxText, QMessageBox msgBox(QMessageBox::Question, msgBoxTitle, msgBoxText,
QMessageBox::NoButton, Core::ICore::mainWindow()); QMessageBox::NoButton, Core::ICore::mainWindow());
if (hasChanges || isRebase) if (hasChanges || isRebase)

View File

@@ -305,9 +305,7 @@ public:
CommandInProgress checkCommandInProgress(const QString &workingDirectory); CommandInProgress checkCommandInProgress(const QString &workingDirectory);
QString commandInProgressDescription(const QString &workingDirectory); QString commandInProgressDescription(const QString &workingDirectory);
void continueCommandIfNeeded(const QString &workingDirectory); void continueCommandIfNeeded(const QString &workingDirectory, bool allowContinue = true);
void continuePreviousGitCommand(const QString &workingDirectory, const QString &msgBoxTitle, QString msgBoxText,
const QString &buttonName, const QString &gitCommand, bool requireChanges = true);
QString extendedShowDescription(const QString &workingDirectory, const QString &text); QString extendedShowDescription(const QString &workingDirectory, const QString &text);
@@ -405,6 +403,16 @@ private:
const QString &gitBinDirectory); const QString &gitBinDirectory);
bool cleanList(const QString &workingDirectory, const QString &flag, QStringList *files, QString *errorMessage); bool cleanList(const QString &workingDirectory, const QString &flag, QStringList *files, QString *errorMessage);
enum ContinueCommandMode {
ContinueOnly,
SkipOnly,
SkipIfNoChanges
};
void continuePreviousGitCommand(const QString &workingDirectory, const QString &msgBoxTitle,
QString msgBoxText, const QString &buttonName,
const QString &gitCommand, ContinueCommandMode continueMode);
mutable QString m_gitVersionForBinary; mutable QString m_gitVersionForBinary;
mutable unsigned m_cachedGitVersion; mutable unsigned m_cachedGitVersion;

View File

@@ -265,11 +265,11 @@ void MergeTool::done()
int exitCode = m_process->exitCode(); int exitCode = m_process->exitCode();
if (!exitCode) { if (!exitCode) {
outputWindow->appendMessage(tr("Merge tool process finished successfully.")); outputWindow->appendMessage(tr("Merge tool process finished successfully."));
m_gitClient->continueCommandIfNeeded(workingDirectory);
} else { } else {
outputWindow->appendError(tr("Merge tool process terminated with exit code %1") outputWindow->appendError(tr("Merge tool process terminated with exit code %1")
.arg(exitCode)); .arg(exitCode));
} }
m_gitClient->continueCommandIfNeeded(workingDirectory, exitCode == 0);
GitPlugin::instance()->gitVersionControl()->emitRepositoryChanged(workingDirectory); GitPlugin::instance()->gitVersionControl()->emitRepositoryChanged(workingDirectory);
deleteLater(); deleteLater();
} }