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 package org.eclipse.jgit.pgm;
47
48 import java.io.IOException;
49 import java.text.MessageFormat;
50 import java.util.List;
51
52 import org.eclipse.jgit.api.FetchCommand;
53 import org.eclipse.jgit.api.Git;
54 import org.eclipse.jgit.lib.Constants;
55 import org.eclipse.jgit.lib.SubmoduleConfig.FetchRecurseSubmodulesMode;
56 import org.eclipse.jgit.lib.TextProgressMonitor;
57 import org.eclipse.jgit.pgm.internal.CLIText;
58 import org.eclipse.jgit.transport.FetchResult;
59 import org.eclipse.jgit.transport.RefSpec;
60 import org.eclipse.jgit.transport.TagOpt;
61 import org.kohsuke.args4j.Argument;
62 import org.kohsuke.args4j.Option;
63
64 @Command(common = true, usage = "usage_updateRemoteRefsFromAnotherRepository")
65 class Fetch extends AbstractFetchCommand implements FetchCommand.Callback {
66 @Option(name = "--timeout", metaVar = "metaVar_seconds", usage = "usage_abortConnectionIfNoActivity")
67 int timeout = -1;
68
69 @Option(name = "--fsck", usage = "usage_performFsckStyleChecksOnReceive")
70 private Boolean fsck;
71
72 @Option(name = "--no-fsck")
73 void nofsck(@SuppressWarnings("unused") final boolean ignored) {
74 fsck = Boolean.FALSE;
75 }
76
77 @Option(name = "--prune", usage = "usage_pruneStaleTrackingRefs")
78 private Boolean prune;
79
80 @Option(name = "--dry-run")
81 private boolean dryRun;
82
83 @Option(name = "--thin", usage = "usage_fetchThinPack")
84 private Boolean thin;
85
86 @Option(name = "--no-thin")
87 void nothin(@SuppressWarnings("unused") final boolean ignored) {
88 thin = Boolean.FALSE;
89 }
90
91 @Option(name = "--quiet", usage = "usage_quiet")
92 private Boolean quiet;
93
94 @Option(name = "--tags", usage="usage_tags", aliases = { "-t" })
95 private Boolean tags;
96
97 @Option(name = "--no-tags", usage = "usage_notags", aliases = { "-n" })
98 void notags(@SuppressWarnings("unused")
99 final boolean ignored) {
100 tags = Boolean.FALSE;
101 }
102
103 @Option(name = "--force", usage = "usage_forcedFetch", aliases = { "-f" })
104 private Boolean force;
105
106 private FetchRecurseSubmodulesMode recurseSubmodules;
107
108 @Option(name = "--recurse-submodules", usage = "usage_recurseSubmodules")
109 void recurseSubmodules(String mode) {
110 if (mode == null || mode.isEmpty()) {
111 recurseSubmodules = FetchRecurseSubmodulesMode.YES;
112 } else {
113 for (FetchRecurseSubmodulesMode m : FetchRecurseSubmodulesMode
114 .values()) {
115 if (m.matchConfigValue(mode)) {
116 recurseSubmodules = m;
117 return;
118 }
119 }
120 throw die(MessageFormat
121 .format(CLIText.get().invalidRecurseSubmodulesMode, mode));
122 }
123 }
124
125 @Option(name = "--no-recurse-submodules", usage = "usage_noRecurseSubmodules")
126 void noRecurseSubmodules(@SuppressWarnings("unused")
127 final boolean ignored) {
128 recurseSubmodules = FetchRecurseSubmodulesMode.NO;
129 }
130
131 @Argument(index = 0, metaVar = "metaVar_uriish")
132 private String remote = Constants.DEFAULT_REMOTE_NAME;
133
134 @Argument(index = 1, metaVar = "metaVar_refspec")
135 private List<RefSpec> toget;
136
137
138 @Override
139 protected void run() throws Exception {
140 try (Git git = new Git(db)) {
141 FetchCommand fetch = git.fetch();
142 if (fsck != null)
143 fetch.setCheckFetchedObjects(fsck.booleanValue());
144 if (prune != null)
145 fetch.setRemoveDeletedRefs(prune.booleanValue());
146 if (toget != null)
147 fetch.setRefSpecs(toget);
148 if (tags != null) {
149 fetch.setTagOpt(tags.booleanValue() ? TagOpt.FETCH_TAGS
150 : TagOpt.NO_TAGS);
151 }
152 if (0 <= timeout)
153 fetch.setTimeout(timeout);
154 fetch.setDryRun(dryRun);
155 fetch.setRemote(remote);
156 if (thin != null)
157 fetch.setThin(thin.booleanValue());
158 if (quiet == null || !quiet.booleanValue())
159 fetch.setProgressMonitor(new TextProgressMonitor(errw));
160 fetch.setRecurseSubmodules(recurseSubmodules).setCallback(this);
161 if (force != null) {
162 fetch.setForceUpdate(force.booleanValue());
163 }
164
165 FetchResult result = fetch.call();
166 if (result.getTrackingRefUpdates().isEmpty()
167 && result.submoduleResults().isEmpty())
168 return;
169
170 showFetchResult(result);
171 }
172 }
173
174
175 @Override
176 public void fetchingSubmodule(String name) {
177 try {
178 outw.println(MessageFormat.format(CLIText.get().fetchingSubmodule,
179 name));
180 outw.flush();
181 } catch (IOException e) {
182
183 }
184 }
185 }