-
Notifications
You must be signed in to change notification settings - Fork 381
/
GitClient.java
909 lines (811 loc) · 36.9 KB
/
GitClient.java
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
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
package org.jenkinsci.plugins.gitclient;
import com.cloudbees.jenkins.plugins.sshcredentials.SSHUserPrivateKey;
import com.cloudbees.plugins.credentials.CredentialsMatcher;
import com.cloudbees.plugins.credentials.CredentialsMatchers;
import com.cloudbees.plugins.credentials.common.StandardCredentials;
import com.cloudbees.plugins.credentials.common.StandardUsernameCredentials;
import com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials;
import hudson.FilePath;
import hudson.ProxyConfiguration;
import hudson.model.TaskListener;
import hudson.plugins.git.*;
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.RemoteConfig;
import org.eclipse.jgit.transport.URIish;
import javax.annotation.CheckForNull;
import java.io.IOException;
import java.io.OutputStream;
import java.io.Writer;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* Interface to Git functionality.
*
* <p>
* Since 1.1, this interface is remotable, meaning it can be referenced from a remote closure call.
*
* @author <a href="mailto:nicolas.deloof@gmail.com">Nicolas De Loof</a>
*/
public interface GitClient {
/** Constant <code>verbose=Boolean.getBoolean(IGitAPI.class.getName() + ".verbose")</code> */
boolean verbose = Boolean.getBoolean(IGitAPI.class.getName() + ".verbose");
// If true, do not print the list of remote branches.
/** Constant <code>quietRemoteBranches=Boolean.getBoolean(GitClient.class.getName() + ".quietRemoteBranches")</code> */
boolean quietRemoteBranches = Boolean.getBoolean(GitClient.class.getName() + ".quietRemoteBranches");
/**
* The supported credential types.
* @since 1.2.0
*/
CredentialsMatcher CREDENTIALS_MATCHER = CredentialsMatchers.anyOf(
CredentialsMatchers.instanceOf(StandardUsernamePasswordCredentials.class),
CredentialsMatchers.instanceOf(SSHUserPrivateKey.class)
// TODO does anyone use SSL client certificates with GIT?
);
/**
* Remove all credentials from the client.
*
* @since 1.2.0
*/
void clearCredentials();
/**
* Adds credentials to be used against a specific url.
*
* @param url the url for the credentials to be used against.
* @param credentials the credentials to use.
* @since 1.2.0
*/
void addCredentials(String url, StandardCredentials credentials);
/**
* Adds credentials to be used when there are not url specific credentials defined.
*
* @param credentials the credentials to use.
* @see #addCredentials(String, com.cloudbees.plugins.credentials.common.StandardCredentials)
* @since 1.2.0
*/
void addDefaultCredentials(StandardCredentials credentials);
/**
* Sets the identity of the author for future commits and merge operations.
*
* @param name a {@link java.lang.String} object.
* @param email a {@link java.lang.String} object.
* @throws hudson.plugins.git.GitException if underlying git operation fails.
*/
void setAuthor(String name, String email) throws GitException;
/**
* setAuthor.
*
* @param p a {@link org.eclipse.jgit.lib.PersonIdent} object.
* @throws hudson.plugins.git.GitException if underlying git operation fails.
*/
void setAuthor(PersonIdent p) throws GitException;
/**
* Sets the identity of the committer for future commits and merge operations.
*
* @param name a {@link java.lang.String} object.
* @param email a {@link java.lang.String} object.
* @throws hudson.plugins.git.GitException if underlying git operation fails.
*/
void setCommitter(String name, String email) throws GitException;
/**
* setCommitter.
*
* @param p a {@link org.eclipse.jgit.lib.PersonIdent} object.
* @throws hudson.plugins.git.GitException if underlying git operation fails.
*/
void setCommitter(PersonIdent p) throws GitException;
/**
* Expose the JGit repository this GitClient is using.
* Don't forget to call {@link org.eclipse.jgit.lib.Repository#close()}, to avoid JENKINS-12188.
*
* @deprecated as of 1.1
* This method was deprecated to make {@link org.jenkinsci.plugins.gitclient.GitClient} remotable. When called on
* a proxy object, this method throws {@link java.io.NotSerializableException}.
* Use {@link #withRepository(RepositoryCallback)} to pass in the closure instead.
* This prevents the repository leak (JENKINS-12188), too.
* @return a {@link org.eclipse.jgit.lib.Repository} object.
* @throws hudson.plugins.git.GitException if underlying git operation fails.
*/
Repository getRepository() throws GitException;
/**
* Runs the computation that requires local access to {@link org.eclipse.jgit.lib.Repository}.
*
* @param callable the repository callback used as closure to instance
* @param <T> type for the repository callback
* @return a T object.
* @throws java.io.IOException in case of IO error
* @throws java.lang.InterruptedException if interrupted
*/
<T> T withRepository(RepositoryCallback<T> callable) throws IOException, InterruptedException;
/**
* The working tree of this repository.
*
* @return a {@link hudson.FilePath} object.
*/
FilePath getWorkTree();
/**
* init.
*
* @throws hudson.plugins.git.GitException if underlying git operation fails.
* @throws java.lang.InterruptedException if interrupted.
*/
public void init() throws GitException, InterruptedException;
/**
* add.
*
* @param filePattern a {@link java.lang.String} object.
* @throws hudson.plugins.git.GitException if underlying git operation fails.
* @throws java.lang.InterruptedException if interrupted.
*/
void add(String filePattern) throws GitException, InterruptedException;
/**
* commit.
*
* @param message a {@link java.lang.String} object.
* @throws hudson.plugins.git.GitException if underlying git operation fails.
* @throws java.lang.InterruptedException if interrupted.
*/
void commit(String message) throws GitException, InterruptedException;
/**
* commit.
*
* @deprecated as of 1.1
* Use {@link #setAuthor(String, String)} and {@link #setCommitter(String, String)}
* then call {@link #commit(String)}
* @param message a {@link java.lang.String} object.
* @param author a {@link org.eclipse.jgit.lib.PersonIdent} object.
* @param committer a {@link org.eclipse.jgit.lib.PersonIdent} object.
* @throws hudson.plugins.git.GitException if underlying git operation fails.
* @throws java.lang.InterruptedException if interrupted.
*/
void commit(String message, PersonIdent author, PersonIdent committer) throws GitException, InterruptedException;
/**
* hasGitRepo.
*
* @return true if this workspace has a git repository
* @throws hudson.plugins.git.GitException if underlying git operation fails.
* @throws java.lang.InterruptedException if interrupted.
*/
boolean hasGitRepo() throws GitException, InterruptedException;
/**
* isCommitInRepo.
*
* @param commit a {@link org.eclipse.jgit.lib.ObjectId} object.
* @return true if commit is in repository
* @throws hudson.plugins.git.GitException if underlying git operation fails.
* @throws java.lang.InterruptedException if interrupted.
*/
boolean isCommitInRepo(ObjectId commit) throws GitException, InterruptedException;
/**
* From a given repository, get a remote's URL
*
* @param name The name of the remote (e.g. origin)
* @throws hudson.plugins.git.GitException if executing the git command fails
* @return a {@link java.lang.String} object.
* @throws java.lang.InterruptedException if interrupted.
*/
String getRemoteUrl(String name) throws GitException, InterruptedException;
/**
* For a given repository, set a remote's URL
*
* @param name The name of the remote (e.g. origin)
* @param url The new value of the remote's URL
* @throws hudson.plugins.git.GitException if executing the git command fails
* @throws java.lang.InterruptedException if interrupted.
*/
void setRemoteUrl(String name, String url) throws GitException, InterruptedException;
/**
* addRemoteUrl.
*
* @param name a {@link java.lang.String} object.
* @param url a {@link java.lang.String} object.
* @throws hudson.plugins.git.GitException if underlying git operation fails.
* @throws java.lang.InterruptedException if interrupted.
*/
void addRemoteUrl(String name, String url) throws GitException, InterruptedException;
/**
* Checks out the specified commit/tag/branch into the workspace.
* (equivalent of <tt>git checkout <em>branch</em></tt>.)
*
* @param ref A git object references expression (either a sha1, tag or branch)
* @deprecated use {@link #checkout()} and {@link org.jenkinsci.plugins.gitclient.CheckoutCommand}
* @throws hudson.plugins.git.GitException if underlying git operation fails.
* @throws java.lang.InterruptedException if interrupted.
*/
void checkout(String ref) throws GitException, InterruptedException;
/**
* Creates a new branch that points to the specified ref.
* (equivalent to git checkout -b <em>branch</em> <em>commit</em>)
*
* This will fail if the branch already exists.
*
* @param ref A git object references expression. For backward compatibility, <tt>null</tt> will checkout current HEAD
* @param branch name of the branch to create from reference
* @deprecated use {@link #checkout()} and {@link org.jenkinsci.plugins.gitclient.CheckoutCommand}
* @throws hudson.plugins.git.GitException if underlying git operation fails.
* @throws java.lang.InterruptedException if interrupted.
*/
void checkout(String ref, String branch) throws GitException, InterruptedException;
/**
* checkout.
*
* @return a {@link org.jenkinsci.plugins.gitclient.CheckoutCommand} object.
*/
CheckoutCommand checkout();
/**
* Regardless of the current state of the workspace (whether there is some dirty files, etc)
* and the state of the repository (whether the branch of the specified name exists or not),
* when this method exits the following conditions hold:
*
* <ul>
* <li>The branch of the specified name <em>branch</em> exists and points to the specified <em>ref</em>
* <li><tt>HEAD</tt> points to <em>branch</em>. IOW, the workspace is on the specified branch.
* <li>Both index and workspace are the same tree with <em>ref</em>.
* (no dirty files and no staged changes, although this method will not touch untracked files
* in the workspace.)
* </ul>
*
* <p>
* This method is preferred over the {@link #checkout(String, String)} family of methods, as
* this method is affected far less by the current state of the repository. The <tt>checkout</tt>
* methods, in their attempt to emulate the "git checkout" command line behaviour, have too many
* side effects. In Jenkins, where you care a lot less about throwing away local changes and
* care a lot more about resetting the workspace into a known state, methods like this is more useful.
*
* <p>
* For compatibility reasons, the order of the parameter is different from {@link #checkout(String, String)}.
*
* @since 1.0.6
* @param branch a {@link java.lang.String} object.
* @param ref a {@link java.lang.String} object.
* @throws hudson.plugins.git.GitException if underlying git operation fails.
* @throws java.lang.InterruptedException if interrupted.
*/
void checkoutBranch(@CheckForNull String branch, String ref) throws GitException, InterruptedException;
/**
* Clone a remote repository
*
* @param url URL for remote repository to clone
* @param origin upstream track name, defaults to <tt>origin</tt> by convention
* @param useShallowClone option to create a shallow clone, that has some restriction but will make clone operation
* @param reference (optional) reference to a local clone for faster clone operations (reduce network and local storage costs)
* @throws hudson.plugins.git.GitException if underlying git operation fails.
* @throws java.lang.InterruptedException if interrupted.
*/
void clone(String url, String origin, boolean useShallowClone, String reference) throws GitException, InterruptedException;
/**
* Returns a {@link org.jenkinsci.plugins.gitclient.CloneCommand} to build up the git-log invocation.
*
* @return a {@link org.jenkinsci.plugins.gitclient.CloneCommand} object.
*/
CloneCommand clone_(); // can't use 'clone' as it collides with Object.clone()
/**
* Fetch commits from url which match any of the passed in
* refspecs. Assumes <tt>remote.remoteName.url</tt> has been set.
*
* @deprecated use {@link #fetch_()} and configure a {@link org.jenkinsci.plugins.gitclient.FetchCommand}
* @param url a {@link org.eclipse.jgit.transport.URIish} object.
* @param refspecs a {@link java.util.List} object.
* @throws hudson.plugins.git.GitException if underlying git operation fails.
* @throws java.lang.InterruptedException if interrupted.
*/
void fetch(URIish url, List<RefSpec> refspecs) throws GitException, InterruptedException;
/**
* fetch.
*
* @deprecated use {@link #fetch_()} and configure a {@link org.jenkinsci.plugins.gitclient.FetchCommand}
* @param remoteName a {@link java.lang.String} object.
* @param refspec a {@link org.eclipse.jgit.transport.RefSpec} object.
* @throws hudson.plugins.git.GitException if underlying git operation fails.
* @throws java.lang.InterruptedException if interrupted.
*/
void fetch(String remoteName, RefSpec... refspec) throws GitException, InterruptedException;
/**
* fetch.
*
* @deprecated use {@link #fetch_()} and configure a {@link org.jenkinsci.plugins.gitclient.FetchCommand}
* @param remoteName a {@link java.lang.String} object.
* @param refspec a {@link org.eclipse.jgit.transport.RefSpec} object.
* @throws hudson.plugins.git.GitException if underlying git operation fails.
* @throws java.lang.InterruptedException if interrupted.
*/
void fetch(String remoteName, RefSpec refspec) throws GitException, InterruptedException;
/**
* fetch_.
*
* @return a {@link org.jenkinsci.plugins.gitclient.FetchCommand} object.
*/
FetchCommand fetch_(); // can't use 'fetch' as legacy IGitAPI already define this method
/**
* push.
*
* @deprecated use {@link #push()} and configure a {@link org.jenkinsci.plugins.gitclient.PushCommand}
* @param remoteName a {@link java.lang.String} object.
* @param refspec a {@link java.lang.String} object.
* @throws hudson.plugins.git.GitException if underlying git operation fails.
* @throws java.lang.InterruptedException if interrupted.
*/
void push(String remoteName, String refspec) throws GitException, InterruptedException;
/**
* push.
*
* @deprecated use {@link #push()} and configure a {@link org.jenkinsci.plugins.gitclient.PushCommand}
* @param url a {@link org.eclipse.jgit.transport.URIish} object.
* @param refspec a {@link java.lang.String} object.
* @throws hudson.plugins.git.GitException if underlying git operation fails.
* @throws java.lang.InterruptedException if interrupted.
*/
void push(URIish url, String refspec) throws GitException, InterruptedException;
/**
* push.
*
* @return a {@link org.jenkinsci.plugins.gitclient.PushCommand} object.
*/
PushCommand push();
/**
* merge.
*
* @deprecated use {@link #merge()} and configure a {@link org.jenkinsci.plugins.gitclient.MergeCommand}
* @param rev a {@link org.eclipse.jgit.lib.ObjectId} object.
* @throws hudson.plugins.git.GitException if underlying git operation fails.
* @throws java.lang.InterruptedException if interrupted.
*/
void merge(ObjectId rev) throws GitException, InterruptedException;
/**
* merge.
*
* @return a {@link org.jenkinsci.plugins.gitclient.MergeCommand} object.
*/
MergeCommand merge();
/**
* rebase.
*
* @return a {@link org.jenkinsci.plugins.gitclient.RebaseCommand} object.
*/
RebaseCommand rebase();
/**
* init_.
*
* @return a {@link org.jenkinsci.plugins.gitclient.InitCommand} object.
*/
InitCommand init_(); // can't use 'init' as legacy IGitAPI already define this method
/**
* Prune stale remote tracking branches with "git remote prune" on the specified remote.
*
* @param repository a {@link org.eclipse.jgit.transport.RemoteConfig} object.
* @throws hudson.plugins.git.GitException if underlying git operation fails.
* @throws java.lang.InterruptedException if interrupted.
*/
void prune(RemoteConfig repository) throws GitException, InterruptedException;
/**
* Fully revert working copy to a clean state, i.e. run both
* <a href="https://www.kernel.org/pub/software/scm/git/docs/git-reset.html">git-reset(1) --hard</a> then
* <a href="https://www.kernel.org/pub/software/scm/git/docs/git-clean.html">git-clean(1)</a> for working copy to
* match a fresh clone.
*
* @throws hudson.plugins.git.GitException if underlying git operation fails.
* @throws java.lang.InterruptedException if interrupted.
*/
void clean() throws GitException, InterruptedException;
// --- manage branches
/**
* branch.
*
* @param name a {@link java.lang.String} object.
* @throws hudson.plugins.git.GitException if underlying git operation fails.
* @throws java.lang.InterruptedException if interrupted.
*/
void branch(String name) throws GitException, InterruptedException;
/**
* (force) delete a branch.
*
* @param name a {@link java.lang.String} object.
* @throws hudson.plugins.git.GitException if underlying git operation fails.
* @throws java.lang.InterruptedException if interrupted.
*/
void deleteBranch(String name) throws GitException, InterruptedException;
/**
* getBranches.
*
* @return a {@link java.util.Set} object.
* @throws hudson.plugins.git.GitException if underlying git operation fails.
* @throws java.lang.InterruptedException if interrupted.
*/
Set<Branch> getBranches() throws GitException, InterruptedException;
/**
* getRemoteBranches.
*
* @return a {@link java.util.Set} object.
* @throws hudson.plugins.git.GitException if underlying git operation fails.
* @throws java.lang.InterruptedException if interrupted.
*/
Set<Branch> getRemoteBranches() throws GitException, InterruptedException;
// --- manage tags
/**
* Create (or update) a tag. If tag already exist it gets updated (equivalent to <tt>git tag --force</tt>)
*
* @param tagName a {@link java.lang.String} object.
* @param comment a {@link java.lang.String} object.
* @throws hudson.plugins.git.GitException if underlying git operation fails.
* @throws java.lang.InterruptedException if interrupted.
*/
void tag(String tagName, String comment) throws GitException, InterruptedException;
/**
* tagExists.
*
* @param tagName a {@link java.lang.String} object.
* @return true if tag exists in repository
* @throws hudson.plugins.git.GitException if underlying git operation fails.
* @throws java.lang.InterruptedException if interrupted.
*/
boolean tagExists(String tagName) throws GitException, InterruptedException;
/**
* getTagMessage.
*
* @param tagName a {@link java.lang.String} object.
* @return a {@link java.lang.String} object.
* @throws hudson.plugins.git.GitException if underlying git operation fails.
* @throws java.lang.InterruptedException if interrupted.
*/
String getTagMessage(String tagName) throws GitException, InterruptedException;
/**
* deleteTag.
*
* @param tagName a {@link java.lang.String} object.
* @throws hudson.plugins.git.GitException if underlying git operation fails.
* @throws java.lang.InterruptedException if interrupted.
*/
void deleteTag(String tagName) throws GitException, InterruptedException;
/**
* getTagNames.
*
* @param tagPattern a {@link java.lang.String} object.
* @return a {@link java.util.Set} object.
* @throws hudson.plugins.git.GitException if underlying git operation fails.
* @throws java.lang.InterruptedException if interrupted.
*/
Set<String> getTagNames(String tagPattern) throws GitException, InterruptedException;
/**
* getRemoteTagNames.
*
* @param tagPattern a {@link java.lang.String} object.
* @return a {@link java.util.Set} object.
* @throws hudson.plugins.git.GitException if underlying git operation fails.
* @throws java.lang.InterruptedException if interrupted.
*/
Set<String> getRemoteTagNames(String tagPattern) throws GitException, InterruptedException;
// --- manage refs
/**
* Create (or update) a ref. The ref will reference HEAD (equivalent to <tt>git update-ref ... HEAD</tt>).
*
* @param refName the full name of the ref (e.g. "refs/myref"). Spaces will be replaced with underscores.
* @throws hudson.plugins.git.GitException if underlying git operation fails.
* @throws java.lang.InterruptedException if interrupted.
*/
void ref(String refName) throws GitException, InterruptedException;
/**
* Check if a ref exists. Equivalent to comparing the return code of <tt>git show-ref</tt> to zero.
*
* @param refName the full name of the ref (e.g. "refs/myref"). Spaces will be replaced with underscores.
* @return True if the ref exists, false otherwse.
* @throws hudson.plugins.git.GitException if underlying git operation fails.
* @throws java.lang.InterruptedException if interrupted.
*/
boolean refExists(String refName) throws GitException, InterruptedException;
/**
* Deletes a ref. Has no effect if the ref does not exist, equivalent to <tt>git update-ref -d</tt>.
*
* @param refName the full name of the ref (e.g. "refs/myref"). Spaces will be replaced with underscores.
* @throws hudson.plugins.git.GitException if underlying git operation fails.
* @throws java.lang.InterruptedException if interrupted.
*/
void deleteRef(String refName) throws GitException, InterruptedException;
/**
* List refs with the given prefix. Equivalent to <tt>git for-each-ref --format="%(refname)"</tt>.
*
* @param refPrefix the literal prefix any ref returned will have. The empty string implies all.
* @return a set of refs, each beginning with the given prefix. Empty if none.
* @throws hudson.plugins.git.GitException if underlying git operation fails.
* @throws java.lang.InterruptedException if interrupted.
*/
Set<String> getRefNames(String refPrefix) throws GitException, InterruptedException;
// --- lookup revision
/**
* getHeadRev.
*
* @param url a {@link java.lang.String} object.
* @return a {@link java.util.Map} object.
* @throws hudson.plugins.git.GitException if underlying git operation fails.
* @throws java.lang.InterruptedException if interrupted.
*/
Map<String, ObjectId> getHeadRev(String url) throws GitException, InterruptedException;
/**
* getHeadRev.
*
* @param remoteRepoUrl a {@link java.lang.String} object.
* @param branch a {@link java.lang.String} object.
* @return a {@link org.eclipse.jgit.lib.ObjectId} object.
* @throws hudson.plugins.git.GitException if underlying git operation fails.
* @throws java.lang.InterruptedException if interrupted.
*/
ObjectId getHeadRev(String remoteRepoUrl, String branch) throws GitException, InterruptedException;
/**
* List references in a remote repository. Equivalent to <tt>git ls-remote [--heads] [--tags] <repository> [<refs>]</tt>.
*
* @param remoteRepoUrl
* Remote repository URL.
* @param pattern
* Only references matching the given pattern are displayed.
* @param headsOnly
* Limit to only refs/heads.
* @param tagsOnly
* Limit to only refs/tags.
* headsOnly and tagsOnly are not mutually exclusive;
* when both are true, references stored in refs/heads and refs/tags are displayed.
* @return a map of references name and its commit hash. Empty if none.
* @throws hudson.plugins.git.GitException if underlying git operation fails.
* @throws java.lang.InterruptedException if interrupted.
*/
Map<String, ObjectId> getRemoteReferences(String remoteRepoUrl, String pattern, boolean headsOnly, boolean tagsOnly) throws GitException, InterruptedException;
/**
* Retrieve commit object that is direct child for <tt>revName</tt> revision reference.
*
* @param revName a commit sha1 or tag/branch refname
* @throws hudson.plugins.git.GitException when no such commit / revName is found in repository.
* @return a {@link org.eclipse.jgit.lib.ObjectId} object.
* @throws java.lang.InterruptedException if interrupted.
*/
ObjectId revParse(String revName) throws GitException, InterruptedException;
/**
* revList_.
*
* @return a {@link org.jenkinsci.plugins.gitclient.RevListCommand} object.
*/
RevListCommand revList_();
/**
* revListAll.
*
* @return a {@link java.util.List} object.
* @throws hudson.plugins.git.GitException if underlying git operation fails.
* @throws java.lang.InterruptedException if interrupted.
*/
List<ObjectId> revListAll() throws GitException, InterruptedException;
/**
* revList.
*
* @param ref a {@link java.lang.String} object.
* @return a {@link java.util.List} object.
* @throws hudson.plugins.git.GitException if underlying git operation fails.
* @throws java.lang.InterruptedException if interrupted.
*/
List<ObjectId> revList(String ref) throws GitException, InterruptedException;
// --- submodules
/**
* subGit.
*
* @return a IGitAPI implementation to manage git submodule repository
* @param subdir a {@link java.lang.String} object.
*/
GitClient subGit(String subdir);
/**
* Returns true if the repository has Git submodules.
*
* @return true if this repository has submodules
* @throws hudson.plugins.git.GitException if underlying git operation fails.
* @throws java.lang.InterruptedException if interrupted.
*/
boolean hasGitModules() throws GitException, InterruptedException;
/**
* Finds all the submodule references in this repository at the specified tree.
*
* @return never null.
* @param treeIsh a {@link java.lang.String} object.
* @throws hudson.plugins.git.GitException if underlying git operation fails.
* @throws java.lang.InterruptedException if interrupted.
*/
List<IndexEntry> getSubmodules( String treeIsh ) throws GitException, InterruptedException;
/**
* Create a submodule in subdir child directory for remote repository
*
* @param remoteURL a {@link java.lang.String} object.
* @param subdir a {@link java.lang.String} object.
* @throws hudson.plugins.git.GitException if underlying git operation fails.
* @throws java.lang.InterruptedException if interrupted.
*/
void addSubmodule(String remoteURL, String subdir) throws GitException, InterruptedException;
/**
* Run submodule update optionally recursively on all submodules
* (equivalent of <tt>git submodule update <em>--recursive</em></tt>.)
*
* @deprecated use {@link #submoduleUpdate()} and {@link org.jenkinsci.plugins.gitclient.SubmoduleUpdateCommand}
* @param recursive a boolean.
* @throws hudson.plugins.git.GitException if underlying git operation fails.
* @throws java.lang.InterruptedException if interrupted.
*/
void submoduleUpdate(boolean recursive) throws GitException, InterruptedException;
/**
* Run submodule update optionally recursively on all submodules, with a specific
* reference passed to git clone if needing to --init.
* (equivalent of <tt>git submodule update <em>--recursive</em> <em>--reference 'reference'</em></tt>.)
*
* @deprecated use {@link #submoduleUpdate()} and {@link org.jenkinsci.plugins.gitclient.SubmoduleUpdateCommand}
* @param recursive a boolean.
* @param reference a {@link java.lang.String} object.
* @throws hudson.plugins.git.GitException if underlying git operation fails.
* @throws java.lang.InterruptedException if interrupted.
*/
void submoduleUpdate(boolean recursive, String reference) throws GitException, InterruptedException;
/**
* Run submodule update optionally recursively on all submodules, optionally with remoteTracking submodules
* (equivalent of <tt>git submodule update <em>--recursive</em> <em>--remote</em></tt>.)
*
* @deprecated use {@link #submoduleUpdate()} and {@link org.jenkinsci.plugins.gitclient.SubmoduleUpdateCommand}
* @param recursive a boolean.
* @param remoteTracking a boolean.
* @throws hudson.plugins.git.GitException if underlying git operation fails.
* @throws java.lang.InterruptedException if interrupted.
*/
void submoduleUpdate(boolean recursive, boolean remoteTracking) throws GitException, InterruptedException;
/**
* Run submodule update optionally recursively on all submodules, optionally with remoteTracking, with a specific
* reference passed to git clone if needing to --init.
* (equivalent of <tt>git submodule update <em>--recursive</em> <em>--remote</em> <em>--reference 'reference'</em></tt>.)
*
* @deprecated use {@link #submoduleUpdate()} and {@link org.jenkinsci.plugins.gitclient.SubmoduleUpdateCommand}
* @param recursive a boolean.
* @param remoteTracking a boolean.
* @param reference a {@link java.lang.String} object.
* @throws hudson.plugins.git.GitException if underlying git operation fails.
* @throws java.lang.InterruptedException if interrupted.
*/
void submoduleUpdate(boolean recursive, boolean remoteTracking, String reference) throws GitException, InterruptedException;
/**
* submoduleUpdate.
*
* @return a {@link org.jenkinsci.plugins.gitclient.SubmoduleUpdateCommand} object.
*/
SubmoduleUpdateCommand submoduleUpdate();
/**
* submoduleClean.
*
* @param recursive a boolean.
* @throws hudson.plugins.git.GitException if underlying git operation fails.
* @throws java.lang.InterruptedException if interrupted.
*/
void submoduleClean(boolean recursive) throws GitException, InterruptedException;
/**
* submoduleInit.
*
* @throws hudson.plugins.git.GitException if underlying git operation fails.
* @throws java.lang.InterruptedException if interrupted.
*/
void submoduleInit() throws GitException, InterruptedException;
/**
* Set up submodule URLs so that they correspond to the remote pertaining to
* the revision that has been checked out.
*
* @param rev a {@link hudson.plugins.git.Revision} object.
* @param listener a {@link hudson.model.TaskListener} object.
* @throws hudson.plugins.git.GitException if underlying git operation fails.
* @throws java.lang.InterruptedException if interrupted.
*/
void setupSubmoduleUrls( Revision rev, TaskListener listener ) throws GitException, InterruptedException;
// --- commit log and notes
/**
* changelog.
*
* @deprecated use {@link #changelog(String, String, Writer)}
* @param revFrom a {@link java.lang.String} object.
* @param revTo a {@link java.lang.String} object.
* @param os a {@link java.io.OutputStream} object.
* @throws hudson.plugins.git.GitException if underlying git operation fails.
* @throws java.lang.InterruptedException if interrupted.
*/
void changelog(String revFrom, String revTo, OutputStream os) throws GitException, InterruptedException;
/**
* Adds the changelog entries for commits in the range revFrom..revTo.
*
* This is just a short cut for calling {@link #changelog()} with appropriate parameters.
*
* @param revFrom a {@link java.lang.String} object.
* @param revTo a {@link java.lang.String} object.
* @param os a {@link java.io.Writer} object.
* @throws hudson.plugins.git.GitException if underlying git operation fails.
* @throws java.lang.InterruptedException if interrupted.
*/
void changelog(String revFrom, String revTo, Writer os) throws GitException, InterruptedException;
/**
* Returns a {@link org.jenkinsci.plugins.gitclient.ChangelogCommand} to build up the git-log invocation.
*
* @return a {@link org.jenkinsci.plugins.gitclient.ChangelogCommand} object.
*/
ChangelogCommand changelog();
/**
* Appends to an existing git-note on the current HEAD commit.
*
* If a note doesn't exist, it works just like {@link #addNote(String, String)}
*
* @param note
* Content of the note.
* @param namespace
* If unqualified, interpreted as "refs/notes/NAMESPACE" just like cgit.
* @throws hudson.plugins.git.GitException if underlying git operation fails.
* @throws java.lang.InterruptedException if interrupted.
*/
void appendNote(String note, String namespace ) throws GitException, InterruptedException;
/**
* Adds a new git-note on the current HEAD commit.
*
* @param note
* Content of the note.
* @param namespace
* If unqualified, interpreted as "refs/notes/NAMESPACE" just like cgit.
* @throws hudson.plugins.git.GitException if underlying git operation fails.
* @throws java.lang.InterruptedException if interrupted.
*/
void addNote(String note, String namespace ) throws GitException, InterruptedException;
/**
* showRevision.
*
* @param r a {@link org.eclipse.jgit.lib.ObjectId} object.
* @return a {@link java.util.List} object.
* @throws hudson.plugins.git.GitException if underlying git operation fails.
* @throws java.lang.InterruptedException if interrupted.
*/
public List<String> showRevision(ObjectId r) throws GitException, InterruptedException;
/**
* Given a Revision, show it as if it were an entry from git whatchanged, so that it
* can be parsed by GitChangeLogParser.
*
* <p>
* Changes are computed on the [from..to] range. If {@code from} is null, this prints
* just one commit that {@code to} represents.
*
* <p>
* For merge commit, this method reports one diff per each parent. This makes this method
* behave differently from {@link #changelog()}.
*
* @return The git show output, in <tt>raw</tt> format.
* @param from a {@link org.eclipse.jgit.lib.ObjectId} object.
* @param to a {@link org.eclipse.jgit.lib.ObjectId} object.
* @throws hudson.plugins.git.GitException if underlying git operation fails.
* @throws java.lang.InterruptedException if interrupted.
*/
List<String> showRevision(ObjectId from, ObjectId to) throws GitException, InterruptedException;
/**
* Equivalent of "git-describe --tags".
*
* Find a nearby tag (including unannotated ones) and come up with a short identifier to describe the tag.
*
* @param commitIsh a {@link java.lang.String} object.
* @return a {@link java.lang.String} object.
* @throws hudson.plugins.git.GitException if underlying git operation fails.
* @throws java.lang.InterruptedException if interrupted.
*/
String describe(String commitIsh) throws GitException, InterruptedException;
/**
* setCredentials.
*
* @param cred a {@link com.cloudbees.plugins.credentials.common.StandardUsernameCredentials} object.
*/
void setCredentials(StandardUsernameCredentials cred);
/**
* setProxy.
*
* @param proxy a {@link hudson.ProxyConfiguration} object.
*/
void setProxy(ProxyConfiguration proxy);
/**
* Find all the branches that include the given commit.
*
* @param revspec commit id to query for
* @param allBranches whether remote branches should be also queried (<code>true</code>) or not (<code>false</code>)
* @return list of branches the specified commit belongs to
* @throws hudson.plugins.git.GitException on Git exceptions
* @throws java.lang.InterruptedException on thread interruption
*/
List<Branch> getBranchesContaining(String revspec, boolean allBranches) throws GitException, InterruptedException;
}