Commit 100d3e66 authored by José Millán Soto's avatar José Millán Soto

Support for rebasing

parent 728321cd
......@@ -6,6 +6,7 @@ declare_qt_logging_category(kdevgit_LOG_PART_SRCS
CATEGORY_BASENAME "git"
)
set(kdevgit_PART_SRCS
rebasedialog.cpp
stashmanagerdialog.cpp
stashpatchsource.cpp
gitmessagehighlighter.cpp
......@@ -19,6 +20,7 @@ set(kdevgit_PART_SRCS
)
ki18n_wrap_ui(kdevgit_PART_SRCS stashmanagerdialog.ui)
ki18n_wrap_ui(kdevgit_PART_SRCS gitnameemaildialog.ui)
ki18n_wrap_ui(kdevgit_PART_SRCS rebasedialog.ui)
kdevplatform_add_plugin(kdevgit JSON kdevgit.json SOURCES ${kdevgit_PART_SRCS})
target_link_libraries(kdevgit
KDev::Util
......
......@@ -45,6 +45,7 @@
#include <vcs/widgets/standardvcslocationwidget.h>
#include "gitclonejob.h"
#include <interfaces/iruncontroller.h>
#include "rebasedialog.h"
#include "stashmanagerdialog.h"
#include <KDirWatch>
......@@ -231,12 +232,21 @@ void GitPlugin::additionalMenuEntries(QMenu* menu, const QList<QUrl>& urls)
QDir dir=urlDir(urls);
bool hasSt = hasStashes(dir);
menu->addAction(i18n("Rebase"), this, SLOT(ctxRebase()));
menu->addSeparator()->setText(i18n("Git Stashes"));
menu->addAction(i18n("Stash Manager"), this, SLOT(ctxStashManager()))->setEnabled(hasSt);
menu->addAction(i18n("Push Stash"), this, SLOT(ctxPushStash()));
menu->addAction(i18n("Pop Stash"), this, SLOT(ctxPopStash()))->setEnabled(hasSt);
}
void GitPlugin::ctxRebase()
{
RebaseDialog *dialog = new RebaseDialog(this, m_urls.first(), nullptr);
dialog->setAttribute(Qt::WA_DeleteOnClose);
dialog->open();
}
void GitPlugin::ctxPushStash()
{
VcsJob* job = gitStash(urlDir(m_urls), QStringList(), KDevelop::OutputJob::Verbose);
......@@ -766,6 +776,14 @@ VcsJob* GitPlugin::mergeBranch(const QUrl& repository, const QString& branchName
return job;
}
VcsJob* GitPlugin::rebase(const QUrl& repository, const QString& branchName)
{
DVcsJob* job = new DVcsJob(urlDir(repository), this);
*job << "git" << "rebase" << branchName;
return job;
}
VcsJob* GitPlugin::currentBranch(const QUrl& repository)
{
DVcsJob* job = new DVcsJob(urlDir(repository), this, OutputJob::Silent);
......
......@@ -123,6 +123,7 @@ public:
KDevelop::VcsJob* switchBranch(const QUrl& repository, const QString& branchName) override;
KDevelop::VcsJob* renameBranch(const QUrl& repository, const QString& oldBranchName, const QString& newBranchName) override;
KDevelop::VcsJob* mergeBranch(const QUrl& repository, const QString& branchName) override;
KDevelop::VcsJob* rebase(const QUrl& repository, const QString& branchName);
//graph helpers
QVector<KDevelop::DVcsEvent> allCommits(const QString& repo) override;
......@@ -184,6 +185,7 @@ private Q_SLOTS:
void parseGitBranchOutput(KDevelop::DVcsJob* job);
void parseGitCurrentBranch(KDevelop::DVcsJob* job);
void ctxRebase();
void ctxPushStash();
void ctxPopStash();
void ctxStashManager();
......
/*
* This file is part of KDevelop
* Copyright 2019 José Millán Soto <jmillan@kde-espana.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "rebasedialog.h"
#include "gitplugin.h"
#include "ui_rebasedialog.h"
#include <vcs/models/brancheslistmodel.h>
#include <vcs/dvcs/dvcsjob.h>
#include <interfaces/icore.h>
#include <interfaces/iruncontroller.h>
#include <QDir>
#include <QUrl>
#include <QComboBox>
#include <KLocalizedString>
using namespace KDevelop;
RebaseDialog::RebaseDialog(GitPlugin* plugin, const QUrl &repository, QWidget* parent)
: QDialog(parent), m_plugin(plugin), m_repository(repository)
{
setWindowTitle(i18n("Branch selection"));
m_ui = new Ui::RebaseDialog();
m_ui->setupUi(this);
m_model = new BranchesListModel(this);
m_model->initialize(plugin, repository);
m_ui->branches->setModel(m_model);
connect(m_ui->rebaseButton, &QPushButton::clicked, this, &RebaseDialog::performRebase);
}
RebaseDialog::~RebaseDialog()
{
delete m_ui;
}
void RebaseDialog::performRebase()
{
QString selectedBranch = m_ui->branches->currentText();
VcsJob *job = m_plugin->rebase(m_repository, selectedBranch);
ICore::self()->runController()->registerJob(job);
accept();
}
/*
* This file is part of KDevelop
* Copyright 2019 José Millán Soto <jmillan@kde-espana.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef KDEVPLATFORM_PLUGIN_REBASEDIALOG_H
#define KDEVPLATFORM_PLUGIN_REBASEDIALOG_H
#include <QDialog>
#include <QUrl>
class GitPlugin;
namespace KDevelop { class BranchesListModel; }
namespace Ui { class RebaseDialog; }
class RebaseDialog : public QDialog
{
Q_OBJECT
public:
RebaseDialog(GitPlugin* plugin, const QUrl &repository, QWidget* parent=nullptr);
~RebaseDialog() override;
protected Q_SLOTS:
void performRebase();
private:
GitPlugin *m_plugin;
QUrl m_repository;
KDevelop::BranchesListModel *m_model;
Ui::RebaseDialog *m_ui;
};
#endif // KDEVPLATFORM_PLUGIN_REBASEDIALOG_H
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>RebaseDialog</class>
<widget class="QDialog" name="RebaseDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>535</width>
<height>92</height>
</rect>
</property>
<property name="windowTitle">
<string>Rebase</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Base branch:</string>
</property>
<property name="buddy">
<cstring>branches</cstring>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="branches">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QPushButton" name="rebaseButton">
<property name="text">
<string>Rebase</string>
</property>
</widget>
</item>
<item row="1" column="2">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>1</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="2">
<widget class="QPushButton" name="pushButton_2">
<property name="text">
<string>Cancel</string>
</property>
</widget>
</item>
</layout>
</widget>
<tabstops>
<tabstop>branches</tabstop>
<tabstop>rebaseButton</tabstop>
<tabstop>pushButton_2</tabstop>
</tabstops>
<resources/>
<connections>
<connection>
<sender>pushButton_2</sender>
<signal>clicked()</signal>
<receiver>RebaseDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>461</x>
<y>71</y>
</hint>
<hint type="destinationlabel">
<x>320</x>
<y>71</y>
</hint>
</hints>
</connection>
</connections>
</ui>
......@@ -20,6 +20,7 @@ if (GIT_FOUND)
../gitclonejob.cpp
../stashmanagerdialog.cpp
../stashpatchsource.cpp
../rebasedialog.cpp
../gitjob.cpp
../gitmessagehighlighter.cpp
../gitplugincheckinrepositoryjob.cpp
......
Markdown is supported
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