1#ifndef GITREPOSITORY_H
2#define GITREPOSITORY_H
3
4#include <QFileInfo>
5#include <QObject>
6#include <QSet>
7#include <memory>
8#include "gitutils.h"
9
10class GitManager;
11class GitRepository : public QObject
12{
13 Q_OBJECT
14public:
15 explicit GitRepository(const QString& folder, QObject *parent = nullptr);
16 ~GitRepository();
17
18 const QString &folder() const;
19
20 void createRepository();
21 bool hasRepository(QString& currentBranch);
22
23 bool isFileInRepository(const QFileInfo& fileInfo) {
24 return isFileInRepository(fileInfo.absoluteFilePath());
25 }
26 bool isFileInRepository(const QString& filePath) {
27 return mFilesInRepositories.contains(filePath);
28 }
29 bool isFileStaged(const QFileInfo& fileInfo) {
30 return isFileStaged(fileInfo.absoluteFilePath());
31 }
32 bool isFileStaged(const QString& filePath) {
33 return mStagedFiles.contains(filePath);
34 }
35 bool hasStagedFiles() {
36 return !mStagedFiles.isEmpty();
37 }
38 bool isFileChanged(const QFileInfo& fileInfo) {
39 return isFileChanged(fileInfo.absoluteFilePath());
40 }
41 bool isFileChanged(const QString& filePath) {
42 return mChangedFiles.contains(filePath);
43 }
44 bool hasChangedFiles() {
45 return !mChangedFiles.isEmpty();
46 }
47 bool isFileConflicting(const QFileInfo& fileInfo) {
48 return isFileConflicting(fileInfo.absoluteFilePath());
49 }
50 bool isFileConflicting(const QString& filePath) {
51 return mConflicts.contains(filePath);
52 }
53 bool hasConflicts(){
54 return !mConflicts.isEmpty();
55 }
56
57 bool add(const QString& path, QString& output);
58 bool remove(const QString& path, QString& output);
59 bool rename(const QString& oldName, const QString& newName, QString& output);
60 bool restore(const QString& path, QString& output);
61 QSet<QString> listFiles(bool refresh);
62
63 bool clone(const QString& url, QString& output);
64 bool commit(const QString& message, QString& output, bool autoStage=true);
65 bool revert(QString& output);
66
67
68 void setFolder(const QString &newFolder);
69 void update();
70
71 const QString &realFolder() const;
72
73signals:
74private:
75 QString mRealFolder;
76 QString mFolder;
77 bool mInRepository;
78 QString mBranch;
79 GitManager* mManager;
80 QSet<QString> mFilesInRepositories;
81 QSet<QString> mChangedFiles;
82 QSet<QString> mStagedFiles;
83 QSet<QString> mConflicts;
84private:
85 void convertFilesListToSet(const QStringList& filesList,QSet<QString>& set);
86};
87
88#endif // GITREPOSITORY_H
89