-
-
Notifications
You must be signed in to change notification settings - Fork 401
Expand file tree
/
Copy pathGitAPI.java
More file actions
439 lines (385 loc) · 14.2 KB
/
Copy pathGitAPI.java
File metadata and controls
439 lines (385 loc) · 14.2 KB
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
package hudson.plugins.git;
import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.EnvVars;
import hudson.FilePath;
import hudson.model.TaskListener;
import java.io.*;
import java.util.List;
import java.util.Set;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.PersonIdent;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.transport.RefSpec;
import org.eclipse.jgit.transport.URIish;
import org.jenkinsci.plugins.gitclient.CliGitAPIImpl;
import org.jenkinsci.plugins.gitclient.Git;
import org.jenkinsci.plugins.gitclient.GitClient;
/**
* Backward compatible class to match the one some plugins used from git-plugin.
* Extends CliGitAPIImpl to implement deprecated IGitAPI methods, but delegates supported methods to the selected git implementation (based on
* {@link org.jenkinsci.plugins.gitclient.Git#USE_CLI}).
*
* New implementations should use {@link org.jenkinsci.plugins.gitclient.GitClient}.
*
* @author <a href="mailto:nicolas.deloof@gmail.com">Nicolas De Loof</a>
* @deprecated
*/
@Deprecated
public class GitAPI extends CliGitAPIImpl {
@Serial
private static final long serialVersionUID = 1L;
private final GitClient jgit;
/**
* Constructor for GitAPI.
*
* @param gitExe name of git executable (git or git.exe or jgit)
* @param repository a {@link hudson.FilePath} for the repository directory
* @param listener a {@link hudson.model.TaskListener} which monitors the git work
* @param environment the {@link hudson.EnvVars} environment for the build
* @throws java.io.IOException if any IO failure
* @throws java.lang.InterruptedException if interrupted
*/
@Deprecated
public GitAPI(String gitExe, FilePath repository, TaskListener listener, EnvVars environment)
throws IOException, InterruptedException {
this(gitExe, new File(repository.getRemote()), listener, environment);
}
/**
* Constructor for GitAPI.
*
* @param gitExe name of git executable (git or git.exe or jgit)
* @param repository a {@link hudson.FilePath} for the repository directory
* @param listener a {@link hudson.model.TaskListener} which monitors the git work
* @param environment the {@link hudson.EnvVars} environment for the build
* @param reference SHA1 for checkout
* @throws java.io.IOException if any IO failure
* @throws java.lang.InterruptedException if interrupted.
*/
@Deprecated
public GitAPI(String gitExe, FilePath repository, TaskListener listener, EnvVars environment, String reference)
throws IOException, InterruptedException {
this(gitExe, repository, listener, environment);
}
/**
* Constructor for GitAPI.
*
* @param gitExe name of git executable (git or git.exe or jgit)
* @param repository a {@link hudson.FilePath} for the repository directory
* @param listener a {@link hudson.model.TaskListener} which monitors the git work
* @param environment the {@link hudson.EnvVars} environment for the build
* @throws java.io.IOException if any IO failure
* @throws java.lang.InterruptedException if interrupted.
*/
@Deprecated
public GitAPI(String gitExe, File repository, TaskListener listener, EnvVars environment)
throws IOException, InterruptedException {
super(gitExe, repository, listener, environment);
// If USE_CLI is forced, don't delegate to JGit client
this.jgit = Git.USE_CLI
? null
: Git.with(listener, environment).in(repository).using("jgit").getClient();
}
// --- delegate implemented methods to JGit client
/** {@inheritDoc} */
@Override
public void add(String filePattern) throws GitException, InterruptedException {
if (Git.USE_CLI) {
super.add(filePattern);
} else {
jgit.add(filePattern);
}
}
/*
public List<ObjectId> revList(String ref) throws GitException {
return Git.USE_CLI ? super.revList(ref) : jgit.revList(ref);
}
*/
/** {@inheritDoc} */
@Override
public String getRemoteUrl(String name) throws GitException, InterruptedException {
return Git.USE_CLI ? super.getRemoteUrl(name) : jgit.getRemoteUrl(name);
}
/** {@inheritDoc} */
@Override
public void push(String remoteName, String refspec) throws GitException, InterruptedException {
if (Git.USE_CLI) {
super.push(remoteName, refspec);
} else {
jgit.push(remoteName, refspec);
}
}
/** {@inheritDoc} */
@Override
public String getTagMessage(String tagName) throws GitException, InterruptedException {
return Git.USE_CLI ? super.getTagMessage(tagName) : jgit.getTagMessage(tagName);
}
/*
public List<ObjectId> revListAll() throws GitException {
return Git.USE_CLI ? super.revListAll() : jgit.revListAll();
}
*/
/*
public void addNote(String note, String namespace) throws GitException {
if (Git.USE_CLI) super.addNote(note, namespace); else jgit.addNote(note, namespace);
}
*/
/*
public void appendNote(String note, String namespace) throws GitException {
if (Git.USE_CLI) super.appendNote(note, namespace); else jgit.appendNote(note, namespace);
}
*/
/*
public void changelog(String revFrom, String revTo, OutputStream fos) throws GitException {
if (Git.USE_CLI) super.changelog(revFrom, revTo, fos); else jgit.changelog(revFrom, revTo, fos);
}
*/
/*
public List<IndexEntry> getSubmodules(String treeIsh) throws GitException {
return Git.USE_CLI ? super.getSubmodules(treeIsh) : jgit.getSubmodules(treeIsh);
}
*/
/*
public ObjectId getHeadRev(String remoteRepoUrl, String branch) throws GitException {
return Git.USE_CLI ? super.getHeadRev(remoteRepoUrl, branch) : jgit.getHeadRev(remoteRepoUrl, branch);
}
*/
/*
public Set<String> getTagNames(String tagPattern) throws GitException {
return Git.USE_CLI ? super.getTagNames(tagPattern) : jgit.getTagNames(tagPattern);
}
*/
/** {@inheritDoc} */
@Override
public GitClient subGit(String subdir) {
return Git.USE_CLI ? super.subGit(subdir) : jgit.subGit(subdir);
}
/** {@inheritDoc} */
@Override
public GitClient newGit(String somedir) {
return Git.USE_CLI ? super.newGit(somedir) : jgit.newGit(somedir);
}
/** {@inheritDoc} */
@Override
public void setRemoteUrl(String name, String url) throws GitException, InterruptedException {
if (Git.USE_CLI) {
super.setRemoteUrl(name, url);
} else {
jgit.setRemoteUrl(name, url);
}
}
/*
public void prune(RemoteConfig repository) throws GitException {
if (Git.USE_CLI) super.prune(repository); else jgit.prune(repository);
}
*/
/*
public void submoduleUpdate(boolean recursive) throws GitException {
if (Git.USE_CLI) super.submoduleUpdate(recursive); else jgit.submoduleUpdate(recursive);
}
*/
/*
public void submoduleUpdate(boolean recursive, String reference) throws GitException {
if (Git.USE_CLI) super.submoduleUpdate(recursive, String reference); else jgit.submoduleUpdate(recursive, String reference);
}
*/
/*
public List<String> showRevision(ObjectId from, ObjectId to) throws GitException {
return Git.USE_CLI ? super.showRevision(from, to) : jgit.showRevision(from, to);
}
*/
/*
public boolean hasGitModules() throws GitException {
return Git.USE_CLI ? super.hasGitModules() : jgit.hasGitModules();
}
*/
/** {@inheritDoc} */
@Override
public Set<Branch> getBranches() throws GitException, InterruptedException {
return Git.USE_CLI ? super.getBranches() : jgit.getBranches();
}
/*
public void addSubmodule(String remoteURL, String subdir) throws GitException {
if (Git.USE_CLI) super.addSubmodule(remoteURL, subdir); else jgit.addSubmodule(remoteURL, subdir);
}
*/
/*
public void clone(String url, String origin, boolean useShallowClone, String reference) throws GitException {
if (Git.USE_CLI) super.clone(url, origin, useShallowClone, reference); else jgit.clone(url, origin, useShallowClone, reference);
}
*/
/** {@inheritDoc} */
@Override
public Set<Branch> getRemoteBranches() throws GitException, InterruptedException {
return Git.USE_CLI ? super.getRemoteBranches() : jgit.getRemoteBranches();
}
/** {@inheritDoc} */
@Override
public void init() throws GitException, InterruptedException {
if (Git.USE_CLI) {
super.init();
} else {
jgit.init();
}
}
/** {@inheritDoc} */
@Override
public void deleteBranch(String name) throws GitException, InterruptedException {
if (Git.USE_CLI) {
super.deleteBranch(name);
} else {
jgit.deleteBranch(name);
}
}
/** {@inheritDoc} */
@Override
@SuppressWarnings("deprecation")
public void checkout(String ref, String branch) throws GitException, InterruptedException {
/* Intentionally using the deprecated method because the replacement method is not serializable. */
if (Git.USE_CLI) {
super.checkout(ref, branch);
} else {
jgit.checkout(ref, branch);
}
}
/** {@inheritDoc} */
@Override
public boolean hasGitRepo() throws GitException, InterruptedException {
return Git.USE_CLI ? super.hasGitRepo() : jgit.hasGitRepo();
}
/** {@inheritDoc} */
@Override
public boolean hasGitRepo(boolean checkParentDirectories) throws GitException, InterruptedException {
return Git.USE_CLI ? super.hasGitRepo(checkParentDirectories) : jgit.hasGitRepo(checkParentDirectories);
}
/** {@inheritDoc} */
@Override
public boolean isCommitInRepo(ObjectId commit) throws GitException, InterruptedException {
return Git.USE_CLI ? super.isCommitInRepo(commit) : jgit.isCommitInRepo(commit);
}
/*
public void setupSubmoduleUrls(Revision rev, TaskListener listener) throws GitException {
if (Git.USE_CLI) super.setupSubmoduleUrls(rev, listener); else jgit.setupSubmoduleUrls(rev, listener);
}
*/
/** {@inheritDoc} */
@Override
public void commit(String message) throws GitException, InterruptedException {
if (Git.USE_CLI) {
super.commit(message);
} else {
jgit.commit(message);
}
}
/** {@inheritDoc} */
@Override
public void commit(String message, PersonIdent author, PersonIdent committer)
throws GitException, InterruptedException {
if (Git.USE_CLI) {
super.setAuthor(author);
super.setCommitter(committer);
super.commit(message);
} else {
jgit.setAuthor(author);
jgit.setCommitter(committer);
jgit.commit(message);
}
}
/** {@inheritDoc} */
@Override
@SuppressWarnings("deprecation")
public void checkout(String ref) throws GitException, InterruptedException {
/* Intentionally using the deprecated method because the replacement method is not serializable. */
if (Git.USE_CLI) {
super.checkout(ref);
} else {
jgit.checkout(ref);
}
}
/** {@inheritDoc} */
@Override
public void deleteTag(String tagName) throws GitException, InterruptedException {
if (Git.USE_CLI) {
super.deleteTag(tagName);
} else {
jgit.deleteTag(tagName);
}
}
/** {@inheritDoc} */
@Override
@NonNull
public Repository getRepository() throws GitException {
return Git.USE_CLI ? super.getRepository() : jgit.getRepository();
}
/** {@inheritDoc} */
@Override
public void tag(String tagName, String comment) throws GitException, InterruptedException {
if (Git.USE_CLI) {
super.tag(tagName, comment);
} else {
jgit.tag(tagName, comment);
}
}
/*
public List<String> showRevision(ObjectId r) throws GitException {
return Git.USE_CLI ? super.showRevision(r) : jgit.showRevision(r);
}
*/
/** {@inheritDoc} */
@Override
@SuppressWarnings("deprecation")
public void fetch(URIish url, List<RefSpec> refspecs) throws GitException, InterruptedException {
/* Intentionally using the deprecated method because the replacement method is not serializable. */
if (Git.USE_CLI) {
super.fetch(url, refspecs);
} else {
jgit.fetch(url, refspecs);
}
}
/** {@inheritDoc} */
@Override
public void fetch(String remoteName, RefSpec... refspec) throws GitException, InterruptedException {
if (Git.USE_CLI) {
super.fetch(remoteName, refspec);
} else {
jgit.fetch(remoteName, refspec);
}
}
/** {@inheritDoc} */
@Override
public void fetch(String remoteName, RefSpec refspec) throws GitException, InterruptedException {
fetch(remoteName, new RefSpec[] {refspec});
}
/** {@inheritDoc} */
@Override
public boolean tagExists(String tagName) throws GitException, InterruptedException {
return Git.USE_CLI ? super.tagExists(tagName) : jgit.tagExists(tagName);
}
/*
public void submoduleClean(boolean recursive) throws GitException {
if (Git.USE_CLI) super.submoduleClean(recursive); else jgit.submoduleClean(recursive);
}
*/
/** {@inheritDoc} */
@Override
public void clean() throws GitException, InterruptedException {
if (Git.USE_CLI) {
super.clean();
} else {
jgit.clean();
}
}
/** {@inheritDoc} */
@Override
public ObjectId revParse(String revName) throws GitException, InterruptedException {
return Git.USE_CLI ? super.revParse(revName) : jgit.revParse(revName);
}
/** {@inheritDoc} */
@Override
public void branch(String name) throws GitException, InterruptedException {
if (Git.USE_CLI) {
super.branch(name);
} else {
jgit.branch(name);
}
}
}