- enhancement: git - branch / switch
This commit is contained in:
parent
1f390d5240
commit
3bff1b46b6
1
NEWS.md
1
NEWS.md
|
@ -12,6 +12,7 @@ Red Panda C++ Version 0.14.3
|
|||
- enhancement: git - add files
|
||||
- enhancement: git - commit
|
||||
- enhancement: git - restore
|
||||
- enhancement: git - branch / switch
|
||||
- fix: compiler set index not correctly saved, when remove compiler sets in options dialog
|
||||
- enhancement: when create a repository in a project, auto add it's files to the repository
|
||||
- enhancement: when add files to project, auto add it to git (if the project has a git repository)
|
||||
|
|
|
@ -91,6 +91,7 @@ SOURCES += \
|
|||
thememanager.cpp \
|
||||
todoparser.cpp \
|
||||
toolsmanager.cpp \
|
||||
vcs/gitbranchdialog.cpp \
|
||||
vcs/gitmanager.cpp \
|
||||
vcs/gitrepository.cpp \
|
||||
vcs/gitutils.cpp \
|
||||
|
@ -223,6 +224,7 @@ HEADERS += \
|
|||
thememanager.h \
|
||||
todoparser.h \
|
||||
toolsmanager.h \
|
||||
vcs/gitbranchdialog.h \
|
||||
vcs/gitmanager.h \
|
||||
vcs/gitrepository.h \
|
||||
vcs/gitutils.h \
|
||||
|
@ -319,6 +321,7 @@ FORMS += \
|
|||
settingsdialog/projectprecompilewidget.ui \
|
||||
settingsdialog/toolsgeneralwidget.ui \
|
||||
settingsdialog/toolsgitwidget.ui \
|
||||
vcs/gitbranchdialog.ui \
|
||||
widgets/aboutdialog.ui \
|
||||
widgets/cpudialog.ui \
|
||||
mainwindow.ui \
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -41,6 +41,7 @@
|
|||
#include "widgets/newheaderdialog.h"
|
||||
#include "vcs/gitmanager.h"
|
||||
#include "vcs/gitrepository.h"
|
||||
#include "vcs/gitbranchdialog.h"
|
||||
|
||||
#include <QCloseEvent>
|
||||
#include <QComboBox>
|
||||
|
@ -3075,10 +3076,12 @@ void MainWindow::onProjectViewContextMenu(const QPoint &pos)
|
|||
if (shouldAdd)
|
||||
vcsMenu.addAction(ui->actionGit_Add_Files);
|
||||
}
|
||||
vcsMenu.addAction(ui->actionGit_Branch);
|
||||
vcsMenu.addAction(ui->actionGit_Commit);
|
||||
vcsMenu.addAction(ui->actionGit_Restore);
|
||||
|
||||
ui->actionGit_Commit->setEnabled(true);
|
||||
ui->actionGit_Branch->setEnabled(true);
|
||||
ui->actionGit_Restore->setEnabled(true);
|
||||
|
||||
// vcsMenu.addAction(ui->actionGit_Reset);
|
||||
|
@ -3184,10 +3187,12 @@ void MainWindow::onFilesViewContextMenu(const QPoint &pos)
|
|||
if (shouldAdd)
|
||||
vcsMenu.addAction(ui->actionGit_Add_Files);
|
||||
}
|
||||
vcsMenu.addAction(ui->actionGit_Branch);
|
||||
vcsMenu.addAction(ui->actionGit_Commit);
|
||||
vcsMenu.addAction(ui->actionGit_Restore);
|
||||
|
||||
ui->actionGit_Commit->setEnabled(true);
|
||||
ui->actionGit_Branch->setEnabled(true);
|
||||
ui->actionGit_Restore->setEnabled(true);
|
||||
|
||||
// vcsMenu.addAction(ui->actionGit_Reset);
|
||||
|
@ -5683,7 +5688,9 @@ void MainWindow::updateVCSActions()
|
|||
}
|
||||
ui->actionGit_Create_Repository->setEnabled(!hasRepository && shouldEnable);
|
||||
ui->actionGit_Commit->setEnabled(hasRepository && shouldEnable);
|
||||
ui->actionGit_Branch->setEnabled(hasRepository && shouldEnable);
|
||||
ui->actionGit_Reset->setEnabled(hasRepository && shouldEnable);
|
||||
ui->actionGit_Restore->setEnabled(hasRepository && shouldEnable);
|
||||
ui->actionGit_Revert->setEnabled(hasRepository && shouldEnable);
|
||||
}
|
||||
|
||||
|
@ -6763,3 +6770,26 @@ void MainWindow::on_actionWebsite_triggered()
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::on_actionGit_Branch_triggered()
|
||||
{
|
||||
QString folder;
|
||||
if (ui->treeFiles->isVisible()) {
|
||||
folder = pSettings->environment().currentFolder();
|
||||
} else if (ui->projectView->isVisible() && mProject) {
|
||||
folder = mProject->folder();
|
||||
}
|
||||
if (folder.isEmpty())
|
||||
return;
|
||||
GitBranchDialog dialog(folder);
|
||||
if (dialog.exec()==QDialog::Accepted) {
|
||||
//update project view
|
||||
if (mProject) {
|
||||
mProject->model()->beginUpdate();
|
||||
mProject->model()->endUpdate();
|
||||
}
|
||||
//update files view
|
||||
setFilesViewRoot(pSettings->environment().currentFolder());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -588,6 +588,8 @@ private slots:
|
|||
|
||||
void on_actionWebsite_triggered();
|
||||
|
||||
void on_actionGit_Branch_triggered();
|
||||
|
||||
private:
|
||||
Ui::MainWindow *ui;
|
||||
EditorList *mEditorList;
|
||||
|
|
|
@ -542,7 +542,7 @@
|
|||
<enum>QTabWidget::South</enum>
|
||||
</property>
|
||||
<property name="currentIndex">
|
||||
<number>1</number>
|
||||
<number>2</number>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
|
@ -576,6 +576,7 @@
|
|||
<widget class="IssuesTable" name="tableIssues">
|
||||
<property name="font">
|
||||
<font>
|
||||
<weight>50</weight>
|
||||
<bold>false</bold>
|
||||
</font>
|
||||
</property>
|
||||
|
@ -1421,7 +1422,7 @@
|
|||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>1114</width>
|
||||
<height>25</height>
|
||||
<height>26</height>
|
||||
</rect>
|
||||
</property>
|
||||
<widget class="QMenu" name="menuFile">
|
||||
|
@ -1602,6 +1603,7 @@
|
|||
</property>
|
||||
<addaction name="actionGit_Create_Repository"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionGit_Branch"/>
|
||||
<addaction name="actionGit_Commit"/>
|
||||
<addaction name="actionGit_Restore"/>
|
||||
</widget>
|
||||
|
@ -2788,6 +2790,11 @@
|
|||
<string>Website</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionGit_Branch">
|
||||
<property name="text">
|
||||
<string>Branch/Switch</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
|
|
|
@ -0,0 +1,83 @@
|
|||
#include "gitbranchdialog.h"
|
||||
#include "ui_gitbranchdialog.h"
|
||||
#include "gitmanager.h"
|
||||
|
||||
GitBranchDialog::GitBranchDialog(const QString& folder, QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::GitBranchDialog),
|
||||
mFolder(folder)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
mManager = new GitManager();
|
||||
int current=-1;
|
||||
QStringList branches =mManager->listBranches(mFolder,current);
|
||||
ui->lstBranches->addItems(branches);
|
||||
ui->lstBranches->setCurrentIndex(current);
|
||||
ui->rbBranch->setChecked(true);
|
||||
ui->rbNonSpecifyTrack->setChecked(true);
|
||||
ui->txtNewBranch->setEnabled(false);
|
||||
if (branches.isEmpty()) {
|
||||
QString currentBranch;
|
||||
if (mManager->hasRepository(mFolder,currentBranch)) {
|
||||
ui->lstBranches->addItem(currentBranch);
|
||||
ui->btnOk->setEnabled(false);
|
||||
}
|
||||
ui->grpOptions->setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
GitBranchDialog::~GitBranchDialog()
|
||||
{
|
||||
delete mManager;
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void GitBranchDialog::on_btnCancel_clicked()
|
||||
{
|
||||
reject();
|
||||
}
|
||||
|
||||
|
||||
void GitBranchDialog::on_btnOk_clicked()
|
||||
{
|
||||
QString branch = ui->lstBranches->currentText();
|
||||
QString text;
|
||||
if (ui->chkCreate->isChecked())
|
||||
text = ui->txtNewBranch->text();
|
||||
else
|
||||
text = ui->lstBranches->currentText();
|
||||
bool result = false;
|
||||
if (!text.isEmpty()) {
|
||||
result = mManager->switchToBranch(
|
||||
mFolder,
|
||||
ui->txtNewBranch->text(),
|
||||
ui->chkCreate->isChecked(),
|
||||
ui->chkForce->isChecked(),
|
||||
ui->chkMerge->isChecked(),
|
||||
ui->rbForceTrack->isChecked(),
|
||||
ui->rbForceNoTrack->isChecked(),
|
||||
ui->chkForceCreation->isChecked());
|
||||
}
|
||||
if (result)
|
||||
accept();
|
||||
else
|
||||
reject();
|
||||
}
|
||||
|
||||
|
||||
void GitBranchDialog::on_lstBranches_currentIndexChanged(int /*index*/)
|
||||
{
|
||||
ui->txtNewBranch->setText("branch_"+ui->lstBranches->currentText());
|
||||
}
|
||||
|
||||
|
||||
void GitBranchDialog::on_chkCreate_stateChanged(int /*arg1*/)
|
||||
{
|
||||
ui->txtNewBranch->setEnabled(ui->chkCreate->isChecked());
|
||||
}
|
||||
|
||||
void GitBranchDialog::closeEvent(QCloseEvent */* event */)
|
||||
{
|
||||
reject();
|
||||
}
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
#ifndef GITBRANCHDIALOG_H
|
||||
#define GITBRANCHDIALOG_H
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
namespace Ui {
|
||||
class GitBranchDialog;
|
||||
}
|
||||
|
||||
class GitManager;
|
||||
class GitBranchDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit GitBranchDialog(const QString& folder, QWidget *parent = nullptr);
|
||||
~GitBranchDialog();
|
||||
|
||||
private slots:
|
||||
void on_btnCancel_clicked();
|
||||
|
||||
void on_btnOk_clicked();
|
||||
|
||||
void on_lstBranches_currentIndexChanged(int index);
|
||||
|
||||
void on_chkCreate_stateChanged(int arg1);
|
||||
|
||||
private:
|
||||
Ui::GitBranchDialog *ui;
|
||||
GitManager *mManager;
|
||||
QString mFolder;
|
||||
|
||||
// QWidget interface
|
||||
protected:
|
||||
void closeEvent(QCloseEvent *event) override;
|
||||
};
|
||||
|
||||
#endif // GITBRANCHDIALOG_H
|
|
@ -0,0 +1,178 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>GitBranchDialog</class>
|
||||
<widget class="QDialog" name="GitBranchDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>705</width>
|
||||
<height>506</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Branch/Switch</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<property name="title">
|
||||
<string>Switch To</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="0" column="0">
|
||||
<widget class="QRadioButton" name="rbBranch">
|
||||
<property name="text">
|
||||
<string>Branch</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QComboBox" name="lstBranches">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="grpOptions">
|
||||
<property name="title">
|
||||
<string>Options</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="1" column="0" colspan="2">
|
||||
<widget class="QCheckBox" name="chkForce">
|
||||
<property name="text">
|
||||
<string>Overwrite working tree changed(force)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0" colspan="2">
|
||||
<widget class="QGroupBox" name="groupBox_3">
|
||||
<property name="title">
|
||||
<string>Track</string>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QRadioButton" name="rbForceTrack">
|
||||
<property name="toolTip">
|
||||
<string>Pass --track to git</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Force Track</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QRadioButton" name="rbForceNoTrack">
|
||||
<property name="toolTip">
|
||||
<string>Pass --no-track to git</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Force No Track</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QRadioButton" name="rbNonSpecifyTrack">
|
||||
<property name="toolTip">
|
||||
<string>Neither --track nor --no-track is passed to git</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Not Specifiied</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLineEdit" name="txtNewBranch"/>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QCheckBox" name="chkCreate">
|
||||
<property name="text">
|
||||
<string>Create New Branch</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0" colspan="2">
|
||||
<widget class="QCheckBox" name="chkMerge">
|
||||
<property name="toolTip">
|
||||
<string>Merge between original branch, working tree contents and the branch to switch to</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Merge</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0" colspan="2">
|
||||
<widget class="QCheckBox" name="chkForceCreation">
|
||||
<property name="toolTip">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Force Creation (Reset branch if exists)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QWidget" name="widget" native="true">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btnOk">
|
||||
<property name="text">
|
||||
<string>Ok</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btnCancel">
|
||||
<property name="text">
|
||||
<string>Cancel</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
|
@ -150,6 +150,47 @@ QStringList GitManager::listChangedFiles(const QString &folder)
|
|||
return textToLines(runGit(folder,args));
|
||||
}
|
||||
|
||||
QStringList GitManager::listBranches(const QString &folder, int ¤t)
|
||||
{
|
||||
QStringList args;
|
||||
args.append("branch");
|
||||
args.append("-a");
|
||||
args.append("-l");
|
||||
QStringList temp = textToLines(runGit(folder,args));
|
||||
current = -1;
|
||||
for (int i=0;i<temp.length();i++) {
|
||||
QString s = temp[i];
|
||||
if (s.startsWith('*')) {
|
||||
current = i;
|
||||
temp[i] = s.mid(1).trimmed();
|
||||
} else if (s.startsWith('+')) {
|
||||
temp[i] = s.mid(1).trimmed();
|
||||
}
|
||||
}
|
||||
return temp;
|
||||
}
|
||||
|
||||
bool GitManager::switchToBranch(const QString &folder, const QString &branch, bool create, bool force, bool merge, bool track, bool noTrack, bool forceCreation)
|
||||
{
|
||||
QStringList args;
|
||||
args.append("switch");
|
||||
if (forceCreation)
|
||||
args.append("-C");
|
||||
else if (create)
|
||||
args.append("-c");
|
||||
if (merge)
|
||||
args.append("-m");
|
||||
if (force)
|
||||
args.append("-f");
|
||||
if (track)
|
||||
args.append("--track");
|
||||
else if (noTrack)
|
||||
args.append("--no-track");
|
||||
args.append(branch);
|
||||
QString output = runGit(folder,args);
|
||||
return !output.startsWith("error") && !output.startsWith("fatal");
|
||||
}
|
||||
|
||||
void GitManager::clone(const QString &folder, const QString &url)
|
||||
{
|
||||
QStringList args;
|
||||
|
|
|
@ -36,6 +36,9 @@ public:
|
|||
QStringList listFiles(const QString& folder);
|
||||
QStringList listStagedFiles(const QString& folder);
|
||||
QStringList listChangedFiles(const QString& folder);
|
||||
QStringList listBranches(const QString& folder, int& current);
|
||||
bool switchToBranch(const QString& folder, const QString& branch, bool create,
|
||||
bool force, bool merge, bool track, bool noTrack, bool forceCreation );
|
||||
|
||||
void clone(const QString& folder, const QString& url);
|
||||
void commit(const QString& folder, const QString& message, bool autoStage);
|
||||
|
|
Loading…
Reference in New Issue