diff options
author | Tasuku Suzuki <tasuku.suzuki@qbc.io> | 2019-05-28 15:06:35 +0900 |
---|---|---|
committer | Orgad Shaneh <orgads@gmail.com> | 2019-06-10 18:19:57 +0000 |
commit | 578cdf7c5a470feb21aa6ec75d15560e678eacb0 (patch) | |
tree | 8c2a40d9c45326f6fed6d8ecd1c0362885e8d5b2 /src | |
parent | c5d63c8f14b35dee94ef07c687629587c789ad2d (diff) | |
download | qt-creator-578cdf7c5a470feb21aa6ec75d15560e678eacb0.tar.gz |
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>
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/git/changeselectiondialog.cpp | 10 | ||||
-rw-r--r-- | src/plugins/git/changeselectiondialog.h | 2 | ||||
-rw-r--r-- | src/plugins/git/changeselectiondialog.ui | 7 | ||||
-rw-r--r-- | src/plugins/git/gitclient.cpp | 44 | ||||
-rw-r--r-- | src/plugins/git/gitclient.h | 1 | ||||
-rw-r--r-- | src/plugins/git/gitplugin.cpp | 4 |
6 files changed, 68 insertions, 0 deletions
diff --git a/src/plugins/git/changeselectiondialog.cpp b/src/plugins/git/changeselectiondialog.cpp index 48f4cf9ccf..43909108f8 100644 --- a/src/plugins/git/changeselectiondialog.cpp +++ b/src/plugins/git/changeselectiondialog.cpp @@ -83,6 +83,8 @@ ChangeSelectionDialog::ChangeSelectionDialog(const QString &workingDirectory, Co this, &ChangeSelectionDialog::acceptRevert); connect(m_ui->checkoutButton, &QPushButton::clicked, this, &ChangeSelectionDialog::acceptCheckout); + connect(m_ui->archiveButton, &QPushButton::clicked, + this, &ChangeSelectionDialog::acceptArchive); if (id == "Git.Revert") m_ui->revertButton->setDefault(true); @@ -90,6 +92,8 @@ ChangeSelectionDialog::ChangeSelectionDialog(const QString &workingDirectory, Co m_ui->cherryPickButton->setDefault(true); else if (id == "Git.Checkout") m_ui->checkoutButton->setDefault(true); + else if (id == "Git.Archive") + m_ui->archiveButton->setDefault(true); else m_ui->showButton->setDefault(true); m_changeModel = new QStringListModel(this); @@ -147,6 +151,12 @@ ChangeCommand ChangeSelectionDialog::command() const return m_command; } +void ChangeSelectionDialog::acceptArchive() +{ + m_command = Archive; + accept(); +} + void ChangeSelectionDialog::acceptCheckout() { m_command = Checkout; diff --git a/src/plugins/git/changeselectiondialog.h b/src/plugins/git/changeselectiondialog.h index 1de142ac7d..9c6290162a 100644 --- a/src/plugins/git/changeselectiondialog.h +++ b/src/plugins/git/changeselectiondialog.h @@ -42,6 +42,7 @@ namespace Internal { enum ChangeCommand { NoCommand, + Archive, Checkout, CherryPick, Revert, @@ -68,6 +69,7 @@ private: void recalculateCompletion(); void recalculateDetails(); void changeTextChanged(const QString &text); + void acceptArchive(); void acceptCheckout(); void acceptCherryPick(); void acceptRevert(); diff --git a/src/plugins/git/changeselectiondialog.ui b/src/plugins/git/changeselectiondialog.ui index 3ccd3f31ea..b6db63a45a 100644 --- a/src/plugins/git/changeselectiondialog.ui +++ b/src/plugins/git/changeselectiondialog.ui @@ -84,6 +84,13 @@ </spacer> </item> <item> + <widget class="QPushButton" name="archiveButton"> + <property name="text"> + <string>&Archive...</string> + </property> + </widget> + </item> + <item> <widget class="QPushButton" name="checkoutButton"> <property name="text"> <string>Check&out</string> diff --git a/src/plugins/git/gitclient.cpp b/src/plugins/git/gitclient.cpp index f95cda6e00..92bd78b6c6 100644 --- a/src/plugins/git/gitclient.cpp +++ b/src/plugins/git/gitclient.cpp @@ -74,6 +74,7 @@ #include <QAction> #include <QCoreApplication> #include <QDir> +#include <QFileDialog> #include <QFileInfo> #include <QHash> #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( const QString &workingDir, const QString &file, const QString &revision, int lineNumber, const QStringList &extraOptions) diff --git a/src/plugins/git/gitclient.h b/src/plugins/git/gitclient.h index abde02f40d..2c67f87d96 100644 --- a/src/plugins/git/gitclient.h +++ b/src/plugins/git/gitclient.h @@ -326,6 +326,7 @@ public: static QString msgNoChangedFiles(); static QString msgNoCommits(bool includeRemote); void show(const QString &source, const QString &id, const QString &name = QString()); + void archive(const QString &workingDirectory, const QString &commit); private: void finishSubmoduleUpdate(); diff --git a/src/plugins/git/gitplugin.cpp b/src/plugins/git/gitplugin.cpp index 924f1da5e2..db3154e499 100644 --- a/src/plugins/git/gitplugin.cpp +++ b/src/plugins/git/gitplugin.cpp @@ -588,6 +588,7 @@ bool GitPlugin::initialize(const QStringList &arguments, QString *errorMessage) createChangeRelatedRepositoryAction(tr("Revert..."), "Git.Revert", context); createChangeRelatedRepositoryAction(tr("Cherry Pick..."), "Git.CherryPick", context); createChangeRelatedRepositoryAction(tr("Checkout..."), "Git.Checkout", context); + createChangeRelatedRepositoryAction(tr("Archive..."), "Git.Archive", context); createRepositoryAction(nullptr, tr("Rebase..."), "Git.Rebase", context, true, std::bind(&GitPlugin::branchList, this)); @@ -852,6 +853,9 @@ void GitPlugin::startChangeRelatedAction(const Id &id) if (dialog.command() == Show) { m_gitClient->show(workingDirectory, change); return; + } else if (dialog.command() == Archive) { + m_gitClient->archive(workingDirectory, change); + return; } if (!DocumentManager::saveAllModifiedDocuments()) |