2022-02-10 12:03:56 +08:00
|
|
|
#ifndef GITREPOSITORY_H
|
|
|
|
#define GITREPOSITORY_H
|
|
|
|
|
2022-02-15 00:01:50 +08:00
|
|
|
#include <QFileInfo>
|
2022-02-10 12:03:56 +08:00
|
|
|
#include <QObject>
|
2022-02-15 00:01:50 +08:00
|
|
|
#include <QSet>
|
2022-02-10 12:03:56 +08:00
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
enum class GitResetStrategy {
|
|
|
|
Soft,
|
|
|
|
Hard,
|
|
|
|
Merge,
|
|
|
|
Mixed,
|
|
|
|
Keep
|
|
|
|
};
|
|
|
|
|
|
|
|
class GitManager;
|
|
|
|
class GitRepository : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2022-02-15 00:01:50 +08:00
|
|
|
explicit GitRepository(const QString& folder, QObject *parent = nullptr);
|
|
|
|
~GitRepository();
|
2022-02-10 12:03:56 +08:00
|
|
|
|
|
|
|
const QString &folder() const;
|
|
|
|
|
|
|
|
void createRepository();
|
2022-02-14 00:13:00 +08:00
|
|
|
bool hasRepository(QString& currentBranch);
|
2022-02-10 12:03:56 +08:00
|
|
|
|
2022-02-15 00:01:50 +08:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
bool isFileChanged(const QFileInfo& fileInfo) {
|
|
|
|
return isFileChanged(fileInfo.absoluteFilePath());
|
|
|
|
}
|
|
|
|
bool isFileChanged(const QString& filePath) {
|
|
|
|
return mChangedFiles.contains(filePath);
|
|
|
|
}
|
|
|
|
|
2022-02-10 12:03:56 +08:00
|
|
|
void add(const QString& path);
|
|
|
|
void remove(const QString& path);
|
|
|
|
void rename(const QString& oldName, const QString& newName);
|
|
|
|
void restore(const QString& path);
|
2022-02-15 00:01:50 +08:00
|
|
|
QSet<QString> listFiles(bool refresh);
|
2022-02-10 12:03:56 +08:00
|
|
|
|
|
|
|
void clone(const QString& url);
|
2022-02-15 17:22:44 +08:00
|
|
|
void commit(const QString& message, bool autoAdd=true);
|
2022-02-10 12:03:56 +08:00
|
|
|
void revert();
|
|
|
|
void reset(const QString& commit, GitResetStrategy strategy);
|
|
|
|
|
|
|
|
|
2022-02-14 00:13:00 +08:00
|
|
|
void setFolder(const QString &newFolder);
|
2022-02-15 00:01:50 +08:00
|
|
|
void update();
|
2022-02-14 00:13:00 +08:00
|
|
|
|
2022-02-15 17:22:44 +08:00
|
|
|
const QString &realFolder() const;
|
|
|
|
|
2022-02-10 12:03:56 +08:00
|
|
|
signals:
|
|
|
|
private:
|
2022-02-15 17:22:44 +08:00
|
|
|
QString mRealFolder;
|
2022-02-10 12:03:56 +08:00
|
|
|
QString mFolder;
|
2022-02-15 00:01:50 +08:00
|
|
|
bool mInRepository;
|
|
|
|
QString mBranch;
|
2022-02-10 12:03:56 +08:00
|
|
|
GitManager* mManager;
|
2022-02-15 00:01:50 +08:00
|
|
|
QSet<QString> mFilesInRepositories;
|
|
|
|
QSet<QString> mChangedFiles;
|
|
|
|
QSet<QString> mStagedFiles;
|
|
|
|
private:
|
|
|
|
void convertFilesListToSet(const QStringList& filesList,QSet<QString>& set);
|
2022-02-10 12:03:56 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // GITREPOSITORY_H
|