diff options
author | Petar Perisin <petar.perisin@gmail.com> | 2012-12-21 23:49:29 +0100 |
---|---|---|
committer | Tobias Hunger <tobias.hunger@digia.com> | 2013-01-07 15:26:47 +0100 |
commit | 7df112b687c8694153ef3a5938921104b6e75115 (patch) | |
tree | 3e44371f51f6170989b737a4e694ba5ea64fa4d6 /src/plugins/git/branchdialog.cpp | |
parent | 2396f34fda5f2b57a0294f1bfa6639a2ef2a322d (diff) | |
download | qt-creator-7df112b687c8694153ef3a5938921104b6e75115.tar.gz |
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>
Diffstat (limited to 'src/plugins/git/branchdialog.cpp')
-rw-r--r-- | src/plugins/git/branchdialog.cpp | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/plugins/git/branchdialog.cpp b/src/plugins/git/branchdialog.cpp index 59eaa1ec7e..b39adce43c 100644 --- a/src/plugins/git/branchdialog.cpp +++ b/src/plugins/git/branchdialog.cpp @@ -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); |