File indexing completed on 2025-03-09 05:11:40
0001 /* 0002 SPDX-FileCopyrightText: 2021 Hamed Masafi <hamed.masfi@gmail.com> 0003 0004 SPDX-License-Identifier: GPL-3.0-or-later 0005 */ 0006 0007 #include "testcommon.h" 0008 0009 #include <QDir> 0010 #include <QFile> 0011 #include <QStandardPaths> 0012 #include <QUuid> 0013 #include <gitmanager.h> 0014 0015 namespace TestCommon 0016 { 0017 0018 QString touch(const QString &fileName) 0019 { 0020 QFileInfo fi{fileName}; 0021 fi.absoluteDir().mkpath(fi.absolutePath()); 0022 0023 QFile f(fileName); 0024 if (!f.open(QIODevice::WriteOnly | QIODevice::Text)) 0025 return {}; 0026 0027 auto content = QUuid::createUuid().toString(QUuid::Id128); 0028 f.write(content.toLatin1()); 0029 f.close(); 0030 return content; 0031 } 0032 0033 QString getTempPath() 0034 { 0035 auto path = QStandardPaths::writableLocation(QStandardPaths::TempLocation) + QLatin1Char('/') + QUuid::createUuid().toString(QUuid::Id128); 0036 QDir d; 0037 d.mkpath(path); 0038 return path; 0039 } 0040 0041 bool cleanPath(Git::Manager *manager) 0042 { 0043 if (!manager->isValid()) 0044 return false; 0045 QDir d{manager->path()}; 0046 return d.removeRecursively(); 0047 } 0048 0049 QString readFile(const QString &fileName) 0050 { 0051 QFile f(fileName); 0052 if (!f.open(QIODevice::ReadOnly | QIODevice::Text)) 0053 return {}; 0054 auto buffer = f.readAll(); 0055 f.close(); 0056 return buffer; 0057 } 0058 0059 bool makePath(Git::Manager *manager, const QString &path) 0060 { 0061 QDir d{}; 0062 return d.mkpath(manager->path() + "/" + path); 0063 } 0064 0065 QString touch(Git::Manager *manager, const QString &fileName) 0066 { 0067 QString content; 0068 if (fileName.startsWith("/")) 0069 content = touch(manager->path() + fileName); 0070 else 0071 content = touch(manager->path() + "/" + fileName); 0072 manager->addFile(fileName); 0073 return content; 0074 } 0075 0076 void initSignature(Git::Manager *manager) 0077 { 0078 manager->setConfig("user.name", "kommit test user", Git::Manager::ConfigLocal); 0079 manager->setConfig("user.email", "kommit@kde.org", Git::Manager::ConfigLocal); 0080 } 0081 }