gitplugin.h 8.31 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
con's avatar
con committed
2
**
3
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
hjk's avatar
hjk committed
4
** Contact: http://www.qt-project.org/legal
con's avatar
con committed
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
con's avatar
con committed
7
**
hjk's avatar
hjk committed
8
9
10
11
12
13
14
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia.  For licensing terms and
** conditions see http://qt.digia.com/licensing.  For further information
** use the contact form at http://qt.digia.com/contact-us.
15
**
16
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17
18
19
20
21
22
23
24
25
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights.  These rights are described in the Digia Qt LGPL Exception
con's avatar
con committed
26
27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
28
****************************************************************************/
hjk's avatar
hjk committed
29

con's avatar
con committed
30
31
32
#ifndef GITPLUGIN_H
#define GITPLUGIN_H

33
34
#include "gitsettings.h"

35
#include <vcsbase/vcsbaseplugin.h>
con's avatar
con committed
36

37
38
39
40
#include <QStringList>
#include <QPointer>
#include <QPair>
#include <QVector>
con's avatar
con committed
41
42
43
44

QT_BEGIN_NAMESPACE
class QFile;
class QAction;
45
class QFileInfo;
con's avatar
con committed
46
47
48
QT_END_NAMESPACE

namespace Core {
Friedemann Kleint's avatar
Friedemann Kleint committed
49
class IEditor;
50
class IEditorFactory;
51
class Command;
52
class Context;
53
54
class ActionManager;
class ActionContainer;
55
}
56
57
58
namespace Utils {
class ParameterAction;
}
Friedemann Kleint's avatar
Friedemann Kleint committed
59
60
61
namespace Locator {
    class CommandLocator;
}
62
63
64
65
66
namespace Gerrit {
namespace Internal {
class GerritPlugin;
}
}
con's avatar
con committed
67
68
69
namespace Git {
namespace Internal {

70
class GitVersionControl;
71
72
class GitClient;
class GitSubmitEditor;
73
class CommitData;
74
class StashDialog;
75
class BranchDialog;
76
class RemoteDialog;
con's avatar
con committed
77

78
79
80
81
82
typedef void (GitClient::*GitClientMemberFunc)(const QString &);

typedef QPair<QAction *, Core::Command* > ActionCommandPair;
typedef QPair<Utils::ParameterAction *, Core::Command* > ParameterActionCommandPair;

hjk's avatar
hjk committed
83
class GitPlugin : public VcsBase::VcsBasePlugin
con's avatar
con committed
84
85
{
    Q_OBJECT
86
    Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "Git.json")
con's avatar
con committed
87
88

public:
89
90
91
    GitPlugin();
    ~GitPlugin();

con's avatar
con committed
92
93
    static GitPlugin *instance();

Orgad Shaneh's avatar
Orgad Shaneh committed
94
    bool initialize(const QStringList &arguments, QString *errorMessage);
con's avatar
con committed
95

96
    GitVersionControl *gitVersionControl() const;
con's avatar
con committed
97

98
    const GitSettings &settings() const;
99
100
    void setSettings(const GitSettings &s);

101
    GitClient *gitClient() const;
con's avatar
con committed
102

103
104
public slots:
    void startCommit();
105
    void updateBranches(const QString &repository);
106

con's avatar
con committed
107
private slots:
108
109
    void diffCurrentFile();
    void diffCurrentProject();
110
    void diffRepository();
111
    void submitEditorDiff(const QStringList &unstaged, const QStringList &staged);
112
    void submitEditorMerge(const QStringList &unmerged);
113
114
115
116
    void submitCurrentLog();
    void logFile();
    void blameFile();
    void logProject();
117
    void logRepository();
Orgad Shaneh's avatar
Orgad Shaneh committed
118
    void reflogRepository();
119
120
    void undoFileChanges(bool revertStaging = true);
    void undoUnstagedFileChanges();
121
    void resetRepository();
Orgad Shaneh's avatar
Orgad Shaneh committed
122
    void startRebase();
123
    void startChangeRelatedAction();
124
125
    void stageFile();
    void unstageFile();
Petar Perisin's avatar
Petar Perisin committed
126
127
    void gitkForCurrentFile();
    void gitkForCurrentFolder();
128
    void gitGui();
129
    void cleanProject();
130
    void cleanRepository();
Petar Perisin's avatar
Petar Perisin committed
131
    void updateSubmodules();
132
133
    void applyCurrentFilePatch();
    void promptApplyPatch();
134
    void gitClientMemberFuncRepositoryAction();
135

136
    void startAmendCommit();
137
    void startFixupCommit();
138
    void stash();
139
    void stashSnapshot();
140
    void branchList();
141
    void remoteList();
142
    void stashList();
Robert Loehning's avatar
Robert Loehning committed
143
    void fetch();
144
145
    void pull();
    void push();
146
    void startMergeTool();
Petar Perisin's avatar
Petar Perisin committed
147
    void continueOrAbortCommand();
148
    void updateContinueAndAbortCommands();
149
    void delayedPushToGerrit();
con's avatar
con committed
150

151
152
153
#ifdef WITH_TESTS
    void testStatusParsing_data();
    void testStatusParsing();
154
155
    void testDiffFileResolving_data();
    void testDiffFileResolving();
156
    void testLogResolving();
157
#endif
158
protected:
Orgad Shaneh's avatar
Orgad Shaneh committed
159
    void updateActions(VcsBase::VcsBasePlugin::ActionState);
160
    bool submitEditorAboutToClose();
161

con's avatar
con committed
162
private:
163
    inline ParameterActionCommandPair
Eike Ziller's avatar
Eike Ziller committed
164
            createParameterAction(Core::ActionContainer *ac,
165
                                  const QString &defaultText, const QString &parameterText,
hjk's avatar
hjk committed
166
                                  const Core::Id &id, const Core::Context &context, bool addToLocator);
167
168

    inline ParameterActionCommandPair
Eike Ziller's avatar
Eike Ziller committed
169
            createFileAction(Core::ActionContainer *ac,
170
                             const QString &defaultText, const QString &parameterText,
hjk's avatar
hjk committed
171
                             const Core::Id &id, const Core::Context &context, bool addToLocator,
172
173
174
                             const char *pluginSlot);

    inline ParameterActionCommandPair
Eike Ziller's avatar
Eike Ziller committed
175
            createProjectAction(Core::ActionContainer *ac,
176
                                const QString &defaultText, const QString &parameterText,
hjk's avatar
hjk committed
177
                                const Core::Id &id, const Core::Context &context, bool addToLocator);
178
179

    inline ParameterActionCommandPair
Eike Ziller's avatar
Eike Ziller committed
180
                createProjectAction(Core::ActionContainer *ac,
181
                                    const QString &defaultText, const QString &parameterText,
hjk's avatar
hjk committed
182
                                    const Core::Id &id, const Core::Context &context, bool addToLocator,
183
184
185
                                    const char *pluginSlot);


Eike Ziller's avatar
Eike Ziller committed
186
    inline ActionCommandPair createRepositoryAction(Core::ActionContainer *ac,
hjk's avatar
hjk committed
187
                                           const QString &text, const Core::Id &id,
188
                                           const Core::Context &context, bool addToLocator);
Eike Ziller's avatar
Eike Ziller committed
189
    inline ActionCommandPair createRepositoryAction(Core::ActionContainer *ac,
hjk's avatar
hjk committed
190
                                           const QString &text, const Core::Id &id,
191
                                           const Core::Context &context,
192
                                           bool addToLocator, const char *pluginSlot);
Eike Ziller's avatar
Eike Ziller committed
193
    inline ActionCommandPair createRepositoryAction(Core::ActionContainer *ac,
hjk's avatar
hjk committed
194
                                           const QString &text, const Core::Id &id,
195
                                           const Core::Context &context,
196
197
                                           bool addToLocator, GitClientMemberFunc);

198
    void updateRepositoryBrowserAction();
199
    bool isCommitEditorOpen() const;
200
    Core::IEditor *openSubmitEditor(const QString &fileName, const CommitData &cd);
201
    void cleanCommitMessageFile();
202
    void cleanRepository(const QString &directory);
203
    void applyPatch(const QString &workingDirectory, QString file = QString());
204
    void startCommit(CommitType commitType);
Orgad Shaneh's avatar
Orgad Shaneh committed
205
    void updateVersionWarning();
206
207

    static GitPlugin *m_instance;
Friedemann Kleint's avatar
Friedemann Kleint committed
208
    Locator::CommandLocator *m_commandLocator;
209

210
211
212
213
    QAction *m_submitCurrentAction;
    QAction *m_diffSelectedFilesAction;
    QAction *m_undoAction;
    QAction *m_redoAction;
214
    QAction *m_menuAction;
215
    QAction *m_repositoryBrowserAction;
Petar Perisin's avatar
Petar Perisin committed
216
    QAction *m_mergeToolAction;
Petar Perisin's avatar
Petar Perisin committed
217
    QAction *m_submoduleUpdateAction;
Petar Perisin's avatar
Petar Perisin committed
218
219
220
221
222
223
224
    QAction *m_abortMergeAction;
    QAction *m_abortRebaseAction;
    QAction *m_abortCherryPickAction;
    QAction *m_abortRevertAction;
    QAction *m_continueRebaseAction;
    QAction *m_continueCherryPickAction;
    QAction *m_continueRevertAction;
225
226
    QAction *m_fixupCommitAction;
    QAction *m_interactiveRebaseAction;
con's avatar
con committed
227

228
229
230
    QVector<Utils::ParameterAction *> m_fileActions;
    QVector<Utils::ParameterAction *> m_projectActions;
    QVector<QAction *> m_repositoryActions;
231
    Utils::ParameterAction *m_applyCurrentFilePatchAction;
232
    Gerrit::Internal::GerritPlugin *m_gerritPlugin;
233

con's avatar
con committed
234
    GitClient                   *m_gitClient;
235
    QPointer<StashDialog>       m_stashDialog;
236
    QPointer<BranchDialog>      m_branchDialog;
237
    QPointer<RemoteDialog>      m_remoteDialog;
con's avatar
con committed
238
    QString                     m_submitRepository;
239
    QString                     m_commitMessageFileName;
240
    bool                        m_submitActionTriggered;
241

242
    GitSettings m_settings;
con's avatar
con committed
243
244
245
246
247
};

} // namespace Git
} // namespace Internal

hjk's avatar
hjk committed
248
#endif // GITPLUGIN_H