Commit 4a5af14b authored by Orgad Shaneh's avatar Orgad Shaneh Committed by Orgad Shaneh
Browse files

Git: Enable choosing non-fast-forward merge

Change-Id: I5972489d06637616953bd0d93a3b65c4d9918377
Reviewed-by: default avatarLeena Miettinen <>
Reviewed-by: default avatarTobias Hunger <>
Reviewed-by: default avatarPetar Perisin <>
parent 0c0c1cd5
......@@ -38,11 +38,14 @@
#include "stashdialog.h" // Label helpers
#include <utils/qtcassert.h>
#include <utils/execmenu.h>
#include <vcsbase/vcsbaseoutputwindow.h>
#include <QAction>
#include <QItemSelectionModel>
#include <QMessageBox>
#include <QList>
#include <QMenu>
#include <QDebug>
......@@ -321,8 +324,18 @@ void BranchDialog::merge()
const QString branch = m_model->fullName(idx, true);
GitClient *client = GitPlugin::instance()->gitClient();
bool allowFastForward = true;
if (client->isFastForwardMerge(m_repository, branch)) {
QMenu popup;
QAction *fastForward = popup.addAction(tr("Fast-Forward"));
popup.addAction(tr("No Fast-Forward"));
QAction *chosen = Utils::execMenuAtWidget(&popup, m_ui->mergeButton);
if (!chosen)
allowFastForward = (chosen == fastForward);
if (client->beginStashScope(m_repository, QLatin1String("merge"), AllowUnstashed))
client->synchronousMerge(m_repository, branch);
client->synchronousMerge(m_repository, branch, allowFastForward);
void BranchDialog::rebase()
......@@ -2106,6 +2106,17 @@ bool GitClient::isRemoteCommit(const QString &workingDirectory, const QString &c
return !outputText.isEmpty();
bool GitClient::isFastForwardMerge(const QString &workingDirectory, const QString &branch)
QStringList arguments;
QByteArray outputText;
arguments << QLatin1String("merge-base") << QLatin1String(HEAD) << branch;
fullySynchronousGit(workingDirectory, arguments, &outputText, 0,
return commandOutputFromLocal8Bit(outputText).trimmed()
== synchronousTopRevision(workingDirectory);
// Format an entry in a one-liner for selection list using git log.
QString GitClient::synchronousShortDescription(const QString &workingDirectory, const QString &revision,
const QString &format)
......@@ -3485,12 +3496,15 @@ void GitClient::push(const QString &workingDirectory, const QStringList &pushArg
executeGit(workingDirectory, arguments, 0, true);
bool GitClient::synchronousMerge(const QString &workingDirectory, const QString &branch)
bool GitClient::synchronousMerge(const QString &workingDirectory, const QString &branch,
bool allowFastForward)
QString command = QLatin1String("merge");
QStringList arguments;
QStringList arguments(command);
arguments << command << branch;
if (!allowFastForward)
arguments << QLatin1String("--no-ff");
arguments << branch;
return executeAndHandleConflicts(workingDirectory, arguments, command);
......@@ -244,13 +244,15 @@ public:
QStringList synchronousBranchesForCommit(const QString &workingDirectory,
const QString &revision);
bool isRemoteCommit(const QString &workingDirectory, const QString &commit);
bool isFastForwardMerge(const QString &workingDirectory, const QString &branch);
bool cloneRepository(const QString &directory, const QByteArray &url);
QString vcsGetRepositoryURL(const QString &directory);
void fetch(const QString &workingDirectory, const QString &remote);
bool synchronousPull(const QString &workingDirectory, bool rebase);
void push(const QString &workingDirectory, const QStringList &pushArgs = QStringList());
bool synchronousMerge(const QString &workingDirectory, const QString &branch);
bool synchronousMerge(const QString &workingDirectory, const QString &branch,
bool allowFastForward = true);
bool canRebase(const QString &workingDirectory) const;
void rebase(const QString &workingDirectory, const QString &baseBranch);
bool synchronousRevert(const QString &workingDirectory, const QString &commit);
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment