Git: Added Merge and Rebase

Added git functions - "Merge" and "Rebase"
They are in the "Branches" dialog:
- Merge - merge selected branch into current one
- Rebase - rebase current branch on selected one

Task-number: QTCREATORBUG-8367

Change-Id: I9ed306c64d5d4b7bd1d58730a5e1009f0bd4ec0e
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
Reviewed-by: Tobias Hunger <tobias.hunger@digia.com>
This commit is contained in:
Petar Perisin
2012-12-21 23:49:29 +01:00
committed by Tobias Hunger
parent 2396f34fda
commit 7df112b687
5 changed files with 156 additions and 47 deletions

View File

@@ -65,6 +65,8 @@ BranchDialog::BranchDialog(QWidget *parent) :
connect(m_ui->removeButton, SIGNAL(clicked()), this, SLOT(remove()));
connect(m_ui->diffButton, SIGNAL(clicked()), this, SLOT(diff()));
connect(m_ui->logButton, SIGNAL(clicked()), this, SLOT(log()));
connect(m_ui->mergeButton, SIGNAL(clicked()), this, SLOT(merge()));
connect(m_ui->rebaseButton, SIGNAL(clicked()), this, SLOT(rebase()));
m_ui->branchView->setModel(m_model);
@@ -102,11 +104,14 @@ void BranchDialog::enableButtons()
const bool currentSelected = hasSelection && idx == m_model->currentBranch();
const bool isLocal = m_model->isLocal(idx);
const bool isLeaf = m_model->isLeaf(idx);
const bool currentLocal = m_model->isLocal(m_model->currentBranch());
m_ui->removeButton->setEnabled(hasSelection && !currentSelected && isLocal && isLeaf);
m_ui->logButton->setEnabled(hasSelection && isLeaf);
m_ui->diffButton->setEnabled(hasSelection && isLeaf);
m_ui->checkoutButton->setEnabled(hasSelection && !currentSelected && isLeaf);
m_ui->rebaseButton->setEnabled(hasSelection && !currentSelected && isLeaf && currentLocal);
m_ui->mergeButton->setEnabled(hasSelection && !currentSelected && isLeaf && currentLocal);
}
void BranchDialog::refresh()
@@ -194,6 +199,40 @@ void BranchDialog::log()
GitPlugin::instance()->gitClient()->graphLog(m_repository, branchName);
}
void BranchDialog::merge()
{
QModelIndex idx = selectedIndex();
QTC_CHECK(m_model->isLocal(m_model->currentBranch())); // otherwise the button would not be enabled!
QTC_CHECK(idx != m_model->currentBranch()); // otherwise the button would not be enabled!
const QString branch = m_model->branchName(idx);
GitClient *gitClient = GitPlugin::instance()->gitClient();
QString stashMessage;
if (gitClient->gitStatus(m_repository, StatusMode(NoUntracked | NoSubmodules)) == GitClient::StatusChanged)
stashMessage = gitClient->synchronousStash(m_repository, QLatin1String("merge"));
if (gitClient->synchronousMerge(m_repository, branch) && (!stashMessage.isEmpty()))
gitClient->stashPop(m_repository);
}
void BranchDialog::rebase()
{
QModelIndex idx = selectedIndex();
QTC_CHECK(m_model->isLocal(m_model->currentBranch())); // otherwise the button would not be enabled!
QTC_CHECK(idx != m_model->currentBranch()); // otherwise the button would not be enabled!
const QString baseBranch = m_model->branchName(idx);
GitClient *gitClient = GitPlugin::instance()->gitClient();
QString stashMessage;
if (gitClient->gitStatus(m_repository, StatusMode(NoUntracked | NoSubmodules)) == GitClient::StatusChanged)
stashMessage = gitClient->synchronousStash(m_repository, QLatin1String("rebase"));
if (gitClient->synchronousRebase(m_repository, baseBranch) && (!stashMessage.isEmpty()))
gitClient->stashPop(m_repository);
}
void BranchDialog::changeEvent(QEvent *e)
{
QDialog::changeEvent(e);