import org.eclipse.jgit.lib.StoredConfig;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.transport.FetchResult;
-import org.eclipse.jgit.transport.RefSpec;
import org.eclipse.jgit.transport.RemoteConfig;
import org.eclipse.jgit.transport.TagOpt;
import org.eclipse.jgit.transport.TrackingRefUpdate;
RevCommit commit = remoteGit.commit().setMessage("initial commit").call();
Ref tagRef = remoteGit.tag().setName("tag").call();
- RefSpec spec = new RefSpec("refs/heads/master:refs/heads/x");
- git.fetch().setRemote("test").setRefSpecs(spec)
- .call();
+ git.fetch().setRemote("test")
+ .setRefSpecs("refs/heads/master:refs/heads/x").call();
assertEquals(commit.getId(),
db.resolve(commit.getId().getName() + "^{commit}"));
remoteGit.commit().setMessage("commit").call();
Ref tagRef = remoteGit.tag().setName("foo").call();
- RefSpec spec = new RefSpec("refs/heads/*:refs/remotes/origin/*");
- git.fetch().setRemote("test").setRefSpecs(spec)
+ git.fetch().setRemote("test")
+ .setRefSpecs("refs/heads/*:refs/remotes/origin/*")
.setTagOpt(TagOpt.AUTO_FOLLOW).call();
assertEquals(tagRef.getObjectId(), db.resolve("foo"));
remoteGit.commit().setMessage("commit").call();
Ref tagRef = remoteGit.tag().setName("foo").call();
remoteGit.commit().setMessage("commit2").call();
- RefSpec spec = new RefSpec("refs/heads/*:refs/remotes/origin/*");
- git.fetch().setRemote("test").setRefSpecs(spec)
+ git.fetch().setRemote("test")
+ .setRefSpecs("refs/heads/*:refs/remotes/origin/*")
.setTagOpt(TagOpt.AUTO_FOLLOW).call();
assertEquals(tagRef.getObjectId(), db.resolve("foo"));
}
remoteGit.checkout().setName("other").setCreateBranch(true).call();
remoteGit.commit().setMessage("commit2").call();
remoteGit.tag().setName("foo").call();
- RefSpec spec = new RefSpec(
- "refs/heads/master:refs/remotes/origin/master");
- git.fetch().setRemote("test").setRefSpecs(spec)
+ git.fetch().setRemote("test")
+ .setRefSpecs("refs/heads/master:refs/remotes/origin/master")
.setTagOpt(TagOpt.AUTO_FOLLOW).call();
assertNull(db.resolve("foo"));
}
Ref tagRef = remoteGit.tag().setName(tagName).call();
ObjectId originalId = tagRef.getObjectId();
- RefSpec spec = new RefSpec("refs/heads/*:refs/remotes/origin/*");
+ String spec = "refs/heads/*:refs/remotes/origin/*";
git.fetch().setRemote("test").setRefSpecs(spec)
.setTagOpt(TagOpt.AUTO_FOLLOW).call();
assertEquals(originalId, db.resolve(tagName));
remoteGit.commit().setMessage("commit").call();
Ref tagRef1 = remoteGit.tag().setName(tagName).call();
- RefSpec spec = new RefSpec("refs/heads/*:refs/remotes/origin/*");
+ String spec = "refs/heads/*:refs/remotes/origin/*";
git.fetch().setRemote("test").setRefSpecs(spec)
.setTagOpt(TagOpt.AUTO_FOLLOW).call();
assertEquals(tagRef1.getObjectId(), db.resolve(tagName));
*/
package org.eclipse.jgit.api;
+import static java.util.stream.Collectors.toList;
+
import java.io.IOException;
import java.net.URISyntaxException;
import java.text.MessageFormat;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
import org.eclipse.jgit.annotations.Nullable;
return refSpecs;
}
+ /**
+ * The ref specs to be used in the fetch operation
+ *
+ * @param specs
+ * @return {@code this}
+ * @since 4.9
+ */
+ public FetchCommand setRefSpecs(String... specs) {
+ return setRefSpecs(
+ Arrays.stream(specs).map(RefSpec::new).collect(toList()));
+ }
+
/**
* The ref specs to be used in the fetch operation
*
* @return {@code this}
*/
public FetchCommand setRefSpecs(RefSpec... specs) {
- checkCallable();
- this.refSpecs.clear();
- for (RefSpec spec : specs)
- refSpecs.add(spec);
- return this;
+ return setRefSpecs(Arrays.asList(specs));
}
/**