2022-02-08 23:38:29 +08:00
|
|
|
#ifndef GITMANAGER_H
|
|
|
|
#define GITMANAGER_H
|
|
|
|
|
|
|
|
#include <QObject>
|
2022-02-14 00:13:00 +08:00
|
|
|
#include <QFileInfo>
|
2022-02-15 00:01:50 +08:00
|
|
|
#include <QSet>
|
2022-02-09 14:58:39 +08:00
|
|
|
#include "utils.h"
|
2022-02-15 21:39:17 +08:00
|
|
|
#include "gitutils.h"
|
2022-02-09 14:58:39 +08:00
|
|
|
|
|
|
|
class GitError: public BaseError {
|
|
|
|
public:
|
|
|
|
explicit GitError(const QString& reason);
|
|
|
|
};
|
|
|
|
|
2022-02-08 23:38:29 +08:00
|
|
|
class GitManager : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2022-02-09 14:58:39 +08:00
|
|
|
|
2022-02-08 23:38:29 +08:00
|
|
|
explicit GitManager(QObject *parent = nullptr);
|
|
|
|
|
2022-02-09 14:58:39 +08:00
|
|
|
void createRepository(const QString& folder);
|
2022-02-14 00:13:00 +08:00
|
|
|
bool hasRepository(const QString& folder, QString& currentBranch);
|
|
|
|
|
2022-02-15 17:22:44 +08:00
|
|
|
QString rootFolder(const QString& folder);
|
|
|
|
|
2022-02-14 00:13:00 +08:00
|
|
|
bool isFileInRepository(const QFileInfo& fileInfo);
|
2022-02-15 00:01:50 +08:00
|
|
|
bool isFileStaged(const QFileInfo& fileInfo);
|
2022-02-14 00:13:00 +08:00
|
|
|
bool isFileChanged(const QFileInfo& fileInfo);
|
2022-02-08 23:38:29 +08:00
|
|
|
|
2022-02-25 11:07:30 +08:00
|
|
|
bool add(const QString& folder, const QString& path, QString& output);
|
|
|
|
bool remove(const QString& folder, const QString& path, QString& output);
|
|
|
|
bool rename(const QString& folder, const QString& oldName, const QString& newName, QString& output);
|
|
|
|
bool restore(const QString& folder, const QString& path, QString& output);
|
2022-02-15 21:39:17 +08:00
|
|
|
|
2022-02-21 23:35:28 +08:00
|
|
|
int logCounts(const QString& folder, const QString& branch=QString());
|
|
|
|
QList<PGitCommitInfo> log(const QString& folder, int start, int count, const QString& branch=QString());
|
|
|
|
|
2022-02-09 14:58:39 +08:00
|
|
|
QStringList listFiles(const QString& folder);
|
2022-02-15 00:01:50 +08:00
|
|
|
QStringList listStagedFiles(const QString& folder);
|
|
|
|
QStringList listChangedFiles(const QString& folder);
|
2022-02-21 11:37:29 +08:00
|
|
|
QStringList listConflicts(const QString& folder);
|
2022-02-24 07:22:44 +08:00
|
|
|
QStringList listRemotes(const QString& folder);
|
|
|
|
|
|
|
|
bool removeRemote(const QString& folder, const QString& remoteName, QString& output);
|
|
|
|
bool renameRemote(const QString& folder, const QString& oldName,
|
|
|
|
const QString& newName, QString& output);
|
|
|
|
bool addRemote(const QString& folder, const QString& name,
|
|
|
|
const QString& url, QString& output);
|
|
|
|
bool setRemoteURL(const QString& folder, const QString& name,
|
|
|
|
const QString& newURL, QString& output);
|
|
|
|
QString getRemoteURL(const QString& folder, const QString& name);
|
2022-02-24 23:31:48 +08:00
|
|
|
QString getBranchRemote(const QString& folder, const QString& branch);
|
|
|
|
QString getBranchMerge(const QString& folder, const QString& branch);
|
|
|
|
bool setBranchUpstream(const QString& folder,
|
|
|
|
const QString& branch,
|
|
|
|
const QString& remoteName,
|
|
|
|
QString &output);
|
|
|
|
|
|
|
|
bool fetch(const QString& folder, QString& output);
|
|
|
|
bool pull(const QString& folder, QString& output);
|
|
|
|
bool push(const QString& folder, QString& output);
|
|
|
|
bool push(const QString& folder,
|
|
|
|
const QString& remoteName,
|
|
|
|
const QString& branch,
|
|
|
|
QString& output);
|
|
|
|
|
2022-02-25 11:07:30 +08:00
|
|
|
bool removeConfig(const QString& folder, const QString &name, QString& output);
|
|
|
|
bool setConfig(const QString& folder, const QString &name, const QString &value, QString& output);
|
|
|
|
bool setUserName(const QString& folder, const QString& userName, QString& output);
|
|
|
|
bool setUserEmail(const QString& folder, const QString& userEmail, QString& output);
|
|
|
|
|
|
|
|
QString getConfig(const QString& folder, const QString& name);
|
|
|
|
QString getUserName(const QString& folder);
|
|
|
|
QString getUserEmail(const QString& folder);
|
|
|
|
|
2022-02-21 11:37:29 +08:00
|
|
|
|
2022-02-19 20:38:08 +08:00
|
|
|
QStringList listBranches(const QString& folder, int& current);
|
|
|
|
bool switchToBranch(const QString& folder, const QString& branch, bool create,
|
2022-02-20 13:26:15 +08:00
|
|
|
bool force, bool merge, bool track, bool noTrack, bool forceCreation,
|
|
|
|
QString& output);
|
|
|
|
bool merge(const QString& folder, const QString& commit, bool squash, bool fastForwardOnly,
|
|
|
|
bool noFastForward, bool noCommit,
|
|
|
|
QString& output,
|
|
|
|
const QString& commitMessage=QString()
|
|
|
|
);
|
|
|
|
bool continueMerge(const QString& folder);
|
|
|
|
void abortMerge(const QString& folder);
|
2022-02-09 14:58:39 +08:00
|
|
|
|
2022-02-25 11:07:30 +08:00
|
|
|
bool isSuccess(const QString& output);
|
|
|
|
bool clone(const QString& folder, const QString& url, QString& output);
|
|
|
|
bool commit(const QString& folder, const QString& message, bool autoStage, QString& output);
|
|
|
|
bool revert(const QString& folder, QString& output);
|
2022-02-22 17:12:54 +08:00
|
|
|
bool reset(const QString& folder, const QString& commit, GitResetStrategy strategy, QString& output);
|
2022-02-08 23:38:29 +08:00
|
|
|
|
2022-02-15 00:01:50 +08:00
|
|
|
bool isValid();
|
|
|
|
|
2022-02-08 23:38:29 +08:00
|
|
|
signals:
|
2022-02-09 14:58:39 +08:00
|
|
|
void gitCmdRunning(const QString& gitCmd);
|
|
|
|
void gitCmdFinished(const QString& message);
|
2022-02-08 23:38:29 +08:00
|
|
|
private:
|
2022-02-09 14:58:39 +08:00
|
|
|
QString runGit(const QString& workingFolder, const QStringList& args);
|
2022-02-15 00:01:50 +08:00
|
|
|
|
|
|
|
QString escapeUTF8String(const QByteArray& rawString);
|
2022-02-08 23:38:29 +08:00
|
|
|
private:
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // GITMANAGER_H
|