RedPanda-CPP/RedPandaIDE/vcs/gitrepository.h

89 lines
2.5 KiB
C
Raw Normal View History

#ifndef GITREPOSITORY_H
#define GITREPOSITORY_H
#include <QFileInfo>
#include <QObject>
#include <QSet>
#include <memory>
2022-02-15 21:39:17 +08:00
#include "gitutils.h"
class GitManager;
class GitRepository : public QObject
{
Q_OBJECT
public:
explicit GitRepository(const QString& folder, QObject *parent = nullptr);
~GitRepository();
const QString &folder() const;
void createRepository();
bool hasRepository(QString& currentBranch);
bool isFileInRepository(const QFileInfo& fileInfo) {
return isFileInRepository(fileInfo.absoluteFilePath());
}
bool isFileInRepository(const QString& filePath) {
return mFilesInRepositories.contains(filePath);
}
bool isFileStaged(const QFileInfo& fileInfo) {
return isFileStaged(fileInfo.absoluteFilePath());
}
bool isFileStaged(const QString& filePath) {
return mStagedFiles.contains(filePath);
}
2022-02-20 21:47:57 +08:00
bool hasStagedFiles() {
return !mStagedFiles.isEmpty();
}
bool isFileChanged(const QFileInfo& fileInfo) {
return isFileChanged(fileInfo.absoluteFilePath());
}
bool isFileChanged(const QString& filePath) {
return mChangedFiles.contains(filePath);
}
2022-02-20 21:47:57 +08:00
bool hasChangedFiles() {
return !mChangedFiles.isEmpty();
}
2022-02-21 11:37:29 +08:00
bool isFileConflicting(const QFileInfo& fileInfo) {
return isFileConflicting(fileInfo.absoluteFilePath());
}
bool isFileConflicting(const QString& filePath) {
return mConflicts.contains(filePath);
}
bool hasConflicts(){
return !mConflicts.isEmpty();
}
2022-02-25 11:07:30 +08:00
bool add(const QString& path, QString& output);
bool remove(const QString& path, QString& output);
bool rename(const QString& oldName, const QString& newName, QString& output);
bool restore(const QString& path, QString& output);
QSet<QString> listFiles(bool refresh);
2022-02-25 11:07:30 +08:00
bool clone(const QString& url, QString& output);
bool commit(const QString& message, QString& output, bool autoStage=true);
bool revert(QString& output);
void setFolder(const QString &newFolder);
void update();
2022-02-15 17:22:44 +08:00
const QString &realFolder() const;
signals:
private:
2022-02-15 17:22:44 +08:00
QString mRealFolder;
QString mFolder;
bool mInRepository;
QString mBranch;
GitManager* mManager;
QSet<QString> mFilesInRepositories;
QSet<QString> mChangedFiles;
QSet<QString> mStagedFiles;
2022-02-21 11:37:29 +08:00
QSet<QString> mConflicts;
private:
void convertFilesListToSet(const QStringList& filesList,QSet<QString>& set);
};
#endif // GITREPOSITORY_H