1#ifndef GITMANAGER_H
2#define GITMANAGER_H
3
4#include <QObject>
5#include <QFileInfo>
6#include <QSet>
7#include "utils.h"
8#include "gitutils.h"
9
10class GitError: public BaseError {
11public:
12 explicit GitError(const QString& reason);
13};
14
15class GitManager : public QObject
16{
17 Q_OBJECT
18public:
19
20 explicit GitManager(QObject *parent = nullptr);
21
22 void createRepository(const QString& folder);
23 bool hasRepository(const QString& folder, QString& currentBranch);
24
25 QString rootFolder(const QString& folder);
26
27 bool isFileInRepository(const QFileInfo& fileInfo);
28 bool isFileStaged(const QFileInfo& fileInfo);
29 bool isFileChanged(const QFileInfo& fileInfo);
30
31 bool add(const QString& folder, const QString& path, QString& output);
32 bool remove(const QString& folder, const QString& path, QString& output);
33 bool rename(const QString& folder, const QString& oldName, const QString& newName, QString& output);
34 bool restore(const QString& folder, const QString& path, QString& output);
35
36 int logCounts(const QString& folder, const QString& branch=QString());
37 QList<PGitCommitInfo> log(const QString& folder, int start, int count, const QString& branch=QString());
38
39 QStringList listFiles(const QString& folder);
40 QStringList listStagedFiles(const QString& folder);
41 QStringList listChangedFiles(const QString& folder);
42 QStringList listConflicts(const QString& folder);
43 QStringList listRemotes(const QString& folder);
44
45 bool removeRemote(const QString& folder, const QString& remoteName, QString& output);
46 bool renameRemote(const QString& folder, const QString& oldName,
47 const QString& newName, QString& output);
48 bool addRemote(const QString& folder, const QString& name,
49 const QString& url, QString& output);
50 bool setRemoteURL(const QString& folder, const QString& name,
51 const QString& newURL, QString& output);
52 QString getRemoteURL(const QString& folder, const QString& name);
53 QString getBranchRemote(const QString& folder, const QString& branch);
54 QString getBranchMerge(const QString& folder, const QString& branch);
55 bool setBranchUpstream(const QString& folder,
56 const QString& branch,
57 const QString& remoteName,
58 QString &output);
59
60 bool fetch(const QString& folder, QString& output);
61 bool pull(const QString& folder, QString& output);
62 bool push(const QString& folder, QString& output);
63 bool push(const QString& folder,
64 const QString& remoteName,
65 const QString& branch,
66 QString& output);
67
68 bool removeConfig(const QString& folder, const QString &name, QString& output);
69 bool setConfig(const QString& folder, const QString &name, const QString &value, QString& output);
70 bool setUserName(const QString& folder, const QString& userName, QString& output);
71 bool setUserEmail(const QString& folder, const QString& userEmail, QString& output);
72
73 QString getConfig(const QString& folder, const QString& name);
74 QString getUserName(const QString& folder);
75 QString getUserEmail(const QString& folder);
76
77
78 QStringList listBranches(const QString& folder, int& current);
79 bool switchToBranch(const QString& folder, const QString& branch, bool create,
80 bool force, bool merge, bool track, bool noTrack, bool forceCreation,
81 QString& output);
82 bool merge(const QString& folder, const QString& commit, bool squash, bool fastForwardOnly,
83 bool noFastForward, bool noCommit,
84 QString& output,
85 const QString& commitMessage=QString()
86 );
87 bool continueMerge(const QString& folder);
88 void abortMerge(const QString& folder);
89
90 bool isSuccess(const QString& output);
91 bool clone(const QString& folder, const QString& url, QString& output);
92 bool commit(const QString& folder, const QString& message, bool autoStage, QString& output);
93 bool revert(const QString& folder, QString& output);
94 bool reset(const QString& folder, const QString& commit, GitResetStrategy strategy, QString& output);
95
96 bool isValid();
97
98signals:
99 void gitCmdRunning(const QString& gitCmd);
100 void gitCmdFinished(const QString& message);
101private:
102 QString runGit(const QString& workingFolder, const QStringList& args);
103
104 QString escapeUTF8String(const QByteArray& rawString);
105private:
106};
107
108#endif // GITMANAGER_H
109