forked from qt-creator/qt-creator
Git: Archive support
This allows users to create archive files from local repository. Tools > Git > Local Repository > Archive will create <reponame>- HEAD.tar.gz Tools > Git > Actions on Commits... you can choose a commit to archive Change-Id: I09bbbdefe532237e9065d1ca3c21910a036ea149 Reviewed-by: Orgad Shaneh <orgads@gmail.com> Reviewed-by: André Hartmann <aha_1980@gmx.de> Reviewed-by: Tasuku Suzuki <tasuku.suzuki@qbc.io>
This commit is contained in:
committed by
Orgad Shaneh
parent
c5d63c8f14
commit
578cdf7c5a
@@ -83,6 +83,8 @@ ChangeSelectionDialog::ChangeSelectionDialog(const QString &workingDirectory, Co
|
|||||||
this, &ChangeSelectionDialog::acceptRevert);
|
this, &ChangeSelectionDialog::acceptRevert);
|
||||||
connect(m_ui->checkoutButton, &QPushButton::clicked,
|
connect(m_ui->checkoutButton, &QPushButton::clicked,
|
||||||
this, &ChangeSelectionDialog::acceptCheckout);
|
this, &ChangeSelectionDialog::acceptCheckout);
|
||||||
|
connect(m_ui->archiveButton, &QPushButton::clicked,
|
||||||
|
this, &ChangeSelectionDialog::acceptArchive);
|
||||||
|
|
||||||
if (id == "Git.Revert")
|
if (id == "Git.Revert")
|
||||||
m_ui->revertButton->setDefault(true);
|
m_ui->revertButton->setDefault(true);
|
||||||
@@ -90,6 +92,8 @@ ChangeSelectionDialog::ChangeSelectionDialog(const QString &workingDirectory, Co
|
|||||||
m_ui->cherryPickButton->setDefault(true);
|
m_ui->cherryPickButton->setDefault(true);
|
||||||
else if (id == "Git.Checkout")
|
else if (id == "Git.Checkout")
|
||||||
m_ui->checkoutButton->setDefault(true);
|
m_ui->checkoutButton->setDefault(true);
|
||||||
|
else if (id == "Git.Archive")
|
||||||
|
m_ui->archiveButton->setDefault(true);
|
||||||
else
|
else
|
||||||
m_ui->showButton->setDefault(true);
|
m_ui->showButton->setDefault(true);
|
||||||
m_changeModel = new QStringListModel(this);
|
m_changeModel = new QStringListModel(this);
|
||||||
@@ -147,6 +151,12 @@ ChangeCommand ChangeSelectionDialog::command() const
|
|||||||
return m_command;
|
return m_command;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ChangeSelectionDialog::acceptArchive()
|
||||||
|
{
|
||||||
|
m_command = Archive;
|
||||||
|
accept();
|
||||||
|
}
|
||||||
|
|
||||||
void ChangeSelectionDialog::acceptCheckout()
|
void ChangeSelectionDialog::acceptCheckout()
|
||||||
{
|
{
|
||||||
m_command = Checkout;
|
m_command = Checkout;
|
||||||
|
@@ -42,6 +42,7 @@ namespace Internal {
|
|||||||
|
|
||||||
enum ChangeCommand {
|
enum ChangeCommand {
|
||||||
NoCommand,
|
NoCommand,
|
||||||
|
Archive,
|
||||||
Checkout,
|
Checkout,
|
||||||
CherryPick,
|
CherryPick,
|
||||||
Revert,
|
Revert,
|
||||||
@@ -68,6 +69,7 @@ private:
|
|||||||
void recalculateCompletion();
|
void recalculateCompletion();
|
||||||
void recalculateDetails();
|
void recalculateDetails();
|
||||||
void changeTextChanged(const QString &text);
|
void changeTextChanged(const QString &text);
|
||||||
|
void acceptArchive();
|
||||||
void acceptCheckout();
|
void acceptCheckout();
|
||||||
void acceptCherryPick();
|
void acceptCherryPick();
|
||||||
void acceptRevert();
|
void acceptRevert();
|
||||||
|
@@ -83,6 +83,13 @@
|
|||||||
</property>
|
</property>
|
||||||
</spacer>
|
</spacer>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="archiveButton">
|
||||||
|
<property name="text">
|
||||||
|
<string>&Archive...</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="checkoutButton">
|
<widget class="QPushButton" name="checkoutButton">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
|
@@ -74,6 +74,7 @@
|
|||||||
#include <QAction>
|
#include <QAction>
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
|
#include <QFileDialog>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QHash>
|
#include <QHash>
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
@@ -1086,6 +1087,49 @@ void GitClient::show(const QString &source, const QString &id, const QString &na
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GitClient::archive(const QString &workingDirectory, const QString &commit)
|
||||||
|
{
|
||||||
|
QString repoDirectory = VcsManager::findTopLevelForDirectory(workingDirectory);
|
||||||
|
if (repoDirectory.isEmpty())
|
||||||
|
repoDirectory = workingDirectory;
|
||||||
|
QString repoName = QFileInfo(repoDirectory).fileName();
|
||||||
|
|
||||||
|
QHash<QString, QString> filters {
|
||||||
|
{ tr("Tarball (*.tar.gz)"), ".tar.gz" },
|
||||||
|
{ tr("Zip archive (*.zip)"), ".zip" }
|
||||||
|
};
|
||||||
|
QString selectedFilter;
|
||||||
|
if (HostOsInfo::isWindowsHost())
|
||||||
|
selectedFilter = filters.key(".zip");
|
||||||
|
else
|
||||||
|
selectedFilter = filters.key(".tar.gz");
|
||||||
|
|
||||||
|
QString archiveName = QFileDialog::getSaveFileName(
|
||||||
|
ICore::dialogParent(),
|
||||||
|
tr("Generate %1 archive").arg(repoName),
|
||||||
|
repoDirectory + QString("/%1-%2").arg(repoName).arg(commit.left(8)),
|
||||||
|
filters.keys().join(";;"),
|
||||||
|
&selectedFilter);
|
||||||
|
if (archiveName.isEmpty())
|
||||||
|
return;
|
||||||
|
QString extension = filters.value(selectedFilter);
|
||||||
|
QFileInfo archive(archiveName);
|
||||||
|
if (archive.completeSuffix() != extension) {
|
||||||
|
archive = QFileInfo(archive.absoluteDir().absoluteFilePath(archive.baseName() + extension));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (archive.exists()) {
|
||||||
|
if (QMessageBox::warning(ICore::dialogParent(), tr("Overwrite?"),
|
||||||
|
tr("An item named \"%1\" already exists at this location. "
|
||||||
|
"Do you want to overwrite it?").arg(QDir::toNativeSeparators(archive.absoluteFilePath())),
|
||||||
|
QMessageBox::Yes | QMessageBox::No) == QMessageBox::No) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
vcsExec(workingDirectory, {"archive", commit, "-o", archive.absoluteFilePath()}, nullptr, true);
|
||||||
|
}
|
||||||
|
|
||||||
VcsBaseEditorWidget *GitClient::annotate(
|
VcsBaseEditorWidget *GitClient::annotate(
|
||||||
const QString &workingDir, const QString &file, const QString &revision,
|
const QString &workingDir, const QString &file, const QString &revision,
|
||||||
int lineNumber, const QStringList &extraOptions)
|
int lineNumber, const QStringList &extraOptions)
|
||||||
|
@@ -326,6 +326,7 @@ public:
|
|||||||
static QString msgNoChangedFiles();
|
static QString msgNoChangedFiles();
|
||||||
static QString msgNoCommits(bool includeRemote);
|
static QString msgNoCommits(bool includeRemote);
|
||||||
void show(const QString &source, const QString &id, const QString &name = QString());
|
void show(const QString &source, const QString &id, const QString &name = QString());
|
||||||
|
void archive(const QString &workingDirectory, const QString &commit);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void finishSubmoduleUpdate();
|
void finishSubmoduleUpdate();
|
||||||
|
@@ -588,6 +588,7 @@ bool GitPlugin::initialize(const QStringList &arguments, QString *errorMessage)
|
|||||||
createChangeRelatedRepositoryAction(tr("Revert..."), "Git.Revert", context);
|
createChangeRelatedRepositoryAction(tr("Revert..."), "Git.Revert", context);
|
||||||
createChangeRelatedRepositoryAction(tr("Cherry Pick..."), "Git.CherryPick", context);
|
createChangeRelatedRepositoryAction(tr("Cherry Pick..."), "Git.CherryPick", context);
|
||||||
createChangeRelatedRepositoryAction(tr("Checkout..."), "Git.Checkout", context);
|
createChangeRelatedRepositoryAction(tr("Checkout..."), "Git.Checkout", context);
|
||||||
|
createChangeRelatedRepositoryAction(tr("Archive..."), "Git.Archive", context);
|
||||||
|
|
||||||
createRepositoryAction(nullptr, tr("Rebase..."), "Git.Rebase", context, true,
|
createRepositoryAction(nullptr, tr("Rebase..."), "Git.Rebase", context, true,
|
||||||
std::bind(&GitPlugin::branchList, this));
|
std::bind(&GitPlugin::branchList, this));
|
||||||
@@ -852,6 +853,9 @@ void GitPlugin::startChangeRelatedAction(const Id &id)
|
|||||||
if (dialog.command() == Show) {
|
if (dialog.command() == Show) {
|
||||||
m_gitClient->show(workingDirectory, change);
|
m_gitClient->show(workingDirectory, change);
|
||||||
return;
|
return;
|
||||||
|
} else if (dialog.command() == Archive) {
|
||||||
|
m_gitClient->archive(workingDirectory, change);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!DocumentManager::saveAllModifiedDocuments())
|
if (!DocumentManager::saveAllModifiedDocuments())
|
||||||
|
Reference in New Issue
Block a user