1
2
3
4
5
6
7
8
9
10 package org.eclipse.jgit.api;
11
12 import java.io.IOException;
13 import java.util.ArrayList;
14 import java.util.Collections;
15 import java.util.List;
16
17 import org.eclipse.jgit.api.errors.GitAPIException;
18 import org.eclipse.jgit.api.errors.JGitInternalException;
19 import org.eclipse.jgit.lib.Constants;
20 import org.eclipse.jgit.lib.Ref;
21 import org.eclipse.jgit.lib.Repository;
22 import org.eclipse.jgit.revwalk.RevWalk;
23
24
25
26
27
28
29
30 public class ListTagCommand extends GitCommand<List<Ref>> {
31
32
33
34
35
36
37
38 protected ListTagCommand(Repository repo) {
39 super(repo);
40 }
41
42
43 @Override
44 public List<Ref> call() throws GitAPIException {
45 checkCallable();
46 List<Ref> tags = new ArrayList<>();
47 try (RevWalklk.html#RevWalk">RevWalk revWalk = new RevWalk(repo)) {
48 List<Ref> refList = repo.getRefDatabase()
49 .getRefsByPrefix(Constants.R_TAGS);
50 for (Ref ref : refList) {
51 tags.add(ref);
52 }
53 } catch (IOException e) {
54 throw new JGitInternalException(e.getMessage(), e);
55 }
56 Collections.sort(tags,
57 (Reff" href="../../../../org/eclipse/jgit/lib/Ref.html#Ref">Ref o1, Ref o2) -> o1.getName().compareTo(o2.getName()));
58 setCallable(false);
59 return tags;
60 }
61
62 }