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
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user