File: gitwrapper.h

package info (click to toggle)
dolphin-plugins 4%3A25.04.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 5,476 kB
  • sloc: cpp: 10,512; xml: 167; sh: 10; makefile: 3
file content (126 lines) | stat: -rw-r--r-- 3,944 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*
    SPDX-FileCopyrightText: 2010 Sebastian Doerner <sebastian@sebastian-doerner.de>

    SPDX-License-Identifier: GPL-2.0-or-later
*/

#ifndef GITWRAPPER_H
#define GITWRAPPER_H

#include <QProcess>
#include <QSet>
#include <QStringList>

/**
 * @brief A git wrapper class to access git functions conveniently using a Singleton interface.
 */
class GitWrapper
{
private:
    GitWrapper();
    static GitWrapper *m_instance;
    /// size of the line buffers when parsing git output
    static const int BUFFER_SIZE;
    /// size of the line buffers when parsing shorter git output
    static const int SMALL_BUFFER_SIZE;
    QProcess m_process;
    /**
     * Gets a list of all remote hosts, whose entry ends with \a lineEnd
     * @param lineEnd The end of the lines, which should be returned as entries.
     *                Should be "(pull)" or "(push)".
     */
    QStringList remotes(QLatin1String lineEnd);

public:
    static GitWrapper *instance();
    static void freeInstance();
    void setWorkingDirectory(const QString &workingDirectory)
    {
        m_process.setWorkingDirectory(workingDirectory);
    }

    /**
     * Returns length of short id (short SHA-signature) for current repository.
     * Usually it is 7+ characters.
     * @returns Short id length. If `0` - error occured.
     */
    int shortIdLength();

    /**
     * Checks if commit id (SHA-signature) is valid for current repository.
     * @param commitSha
     *          Requested SHA to check.
     * @returns True for a valid SHA, false otherwise.
     */
    bool isCommitIdValid(const QString &commitSha);

    /**
     * Gets a list of all branches for remote repository.
     * @param remote
     *          Remote repository URL.
     * @returns A QStringList containing the names of remote branches.
     *          First entry is for default branch.
     *
     * @note Might be time consuming, prefer to call it from a separate thread.
     */
    QStringList remoteBranches(const QString &remote);

    /**
     * Gets a list of untracked files/dirs in the repository.
     * @returns A StringList containing the names of all untracked entries.
     *
     * @note List contains of file names and directory names without path
     *       and without trailing slash. If whole current directory is untracked list
     *       contains a single entry ".".
     */
    QStringList listUntracked();

    /**
     * @returns The configured user.name of the repository,
                the empty String (which is NOT null) if not configured.
     */
    QString userName();
    /**
     * @returns The configured user.email of the repository,
                the empty String (which is NOT null) if not configured.
     */
    QString userEmail();
    /**
     * Gets a list of all branches in the repository.
     * @param currentBranchIndex
     *          Pointer to the location in which to store the index of the current branch
     *          within the returned QStringList. Set to -1 if currently not on any branch.
     * @returns A StringList containing the names of all local and remote branches.
     */
    QStringList branches(int *currentBranchIndex = nullptr);

    /**
     * Gets a list of all tags in the repository.
     * @returns A list containing the tag names
     */
    QStringList tags();
    /**
     * Gets a set of all tags in the repository.
     * @param result Set to store the results in.
     */
    void tagSet(QSet<QString> &result);

    /**
     * Gets a list of all remote hosts we can pull from.
     * @returns The list containing the remote hosts.
     */
    QStringList pullRemotes();

    /**
     * Gets a list of all remote hosts we can push to.
     * @returns The list containing the remote hosts.
     */
    QStringList pushRemotes();

    /**
     * @returns The last commit message. Null-String if there is no last commit.
     */
    QString lastCommitMessage();
};

#endif // GITWRAPPER_H