本文整理匯總了Java中org.eclipse.jgit.api.CloneCommand.setCloneAllBranches方法的典型用法代碼示例。如果您正苦於以下問題:Java CloneCommand.setCloneAllBranches方法的具體用法?Java CloneCommand.setCloneAllBranches怎麽用?Java CloneCommand.setCloneAllBranches使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.eclipse.jgit.api.CloneCommand
的用法示例。
在下文中一共展示了CloneCommand.setCloneAllBranches方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: cloneRepo
import org.eclipse.jgit.api.CloneCommand; //導入方法依賴的package包/類
/**
*
* Clones a git repository using the given uri and stores it in the parent directory. Checks out the
* given reference or (if value is null) does not check out a branch
* (which reduces time needed to complete command).
* @param cloneURI the uri to the remote repository
* @param parentDirectory the directory in which to store the git meta directory (".git" directory)
* @param checkoutRef the ref name ("refs/heads/master"), branch name ("master") or tag name ("v1.2.3"). If
* {@code null} is passed, will not checkout a branch.
* @param branchesToClone the branches to clone or all branches if passed a {@code null} value.
* @param monitor reports the progress of the clone command; can be null
* @return the cloned Git repository
* @throws GitAPIException
*/
public static Git cloneRepo(String cloneURI, File parentDirectory, String remoteName,
String checkoutRef, List<String> branchesToClone, ProgressMonitor monitor) throws GitAPIException {
CloneCommand clone = Git.cloneRepository();
if (checkoutRef == null) {
clone.setNoCheckout(true);
} else {
clone.setBranch(checkoutRef);
}
if (branchesToClone == null) {
clone.setCloneAllBranches(true);
} else {
clone.setBranchesToClone(branchesToClone);
}
if (monitor != null) { clone.setProgressMonitor(monitor); }
return clone
.setURI(cloneURI)
.setDirectory(parentDirectory)
.setRemote(remoteName)
.call();
}
示例2: testAnonymousClone
import org.eclipse.jgit.api.CloneCommand; //導入方法依賴的package包/類
@Test
public void testAnonymousClone() throws Exception {
GitBlitSuite.close(ticgitFolder);
if (ticgitFolder.exists()) {
FileUtils.delete(ticgitFolder, FileUtils.RECURSIVE | FileUtils.RETRY);
}
// set push restriction
RepositoryModel model = GitBlit.self().getRepositoryModel("ticgit.git");
model.accessRestriction = AccessRestrictionType.PUSH;
model.authorizationControl = AuthorizationControl.NAMED;
GitBlit.self().updateRepositoryModel(model.name, model, false);
CloneCommand clone = Git.cloneRepository();
clone.setURI(MessageFormat.format("{0}/ticgit.git", url));
clone.setDirectory(ticgitFolder);
clone.setBare(false);
clone.setCloneAllBranches(true);
GitBlitSuite.close(clone.call());
assertTrue(true);
// restore anonymous repository access
model.accessRestriction = AccessRestrictionType.NONE;
model.authorizationControl = AuthorizationControl.NAMED;
GitBlit.self().updateRepositoryModel(model.name, model, false);
}
示例3: testClone
import org.eclipse.jgit.api.CloneCommand; //導入方法依賴的package包/類
@Test
public void testClone() throws Exception {
GitBlitSuite.close(ticgitFolder);
if (ticgitFolder.exists()) {
FileUtils.delete(ticgitFolder, FileUtils.RECURSIVE | FileUtils.RETRY);
}
CloneCommand clone = Git.cloneRepository();
clone.setURI(MessageFormat.format("{0}/ticgit.git", url));
clone.setDirectory(ticgitFolder);
clone.setBare(false);
clone.setCloneAllBranches(true);
clone.setCredentialsProvider(new UsernamePasswordCredentialsProvider(account, password));
GitBlitSuite.close(clone.call());
assertTrue(true);
}
示例4: clone
import org.eclipse.jgit.api.CloneCommand; //導入方法依賴的package包/類
private Git clone(Pom pom, GitDependency dependency) throws MojoExecutionException {
final CloneCommand c = new CloneCommand();
final String location = dependency.getLocation();
c.setURI(location);
c.setCloneAllBranches(true);
c.setProgressMonitor(new TextProgressMonitor());
final GitDependencyHandler dependencyHandler = new GitDependencyHandler(dependency);
final String version = dependencyHandler.getDependencyVersion(pom);
final String tempDirectory = Directory.getTempDirectoryString(location, version);
c.setDirectory(new File(tempDirectory));
return c.call();
}
示例5: testCloneRestrictedRepo
import org.eclipse.jgit.api.CloneCommand; //導入方法依賴的package包/類
@Test
public void testCloneRestrictedRepo() throws Exception {
GitBlitSuite.close(ticgit2Folder);
if (ticgit2Folder.exists()) {
FileUtils.delete(ticgit2Folder, FileUtils.RECURSIVE);
}
// restrict repository access
RepositoryModel model = GitBlit.self().getRepositoryModel("ticgit.git");
model.accessRestriction = AccessRestrictionType.CLONE;
model.authorizationControl = AuthorizationControl.NAMED;
GitBlit.self().updateRepositoryModel(model.name, model, false);
// delete any existing working folder
boolean cloned = false;
try {
CloneCommand clone = Git.cloneRepository();
clone.setURI(MessageFormat.format("{0}/ticgit.git", url));
clone.setDirectory(ticgit2Folder);
clone.setBare(false);
clone.setCloneAllBranches(true);
GitBlitSuite.close(clone.call());
cloned = true;
} catch (Exception e) {
// swallow the exception which we expect
}
assertFalse("Anonymous was able to clone the repository?!", cloned);
FileUtils.delete(ticgit2Folder, FileUtils.RECURSIVE);
// restore anonymous repository access
model.accessRestriction = AccessRestrictionType.NONE;
model.authorizationControl = AuthorizationControl.NAMED;
GitBlit.self().updateRepositoryModel(model.name, model, false);
}
示例6: testAnonymousPush
import org.eclipse.jgit.api.CloneCommand; //導入方法依賴的package包/類
@Test
public void testAnonymousPush() throws Exception {
GitBlitSuite.close(ticgitFolder);
if (ticgitFolder.exists()) {
FileUtils.delete(ticgitFolder, FileUtils.RECURSIVE | FileUtils.RETRY);
}
// restore anonymous repository access
RepositoryModel model = GitBlit.self().getRepositoryModel("ticgit.git");
model.accessRestriction = AccessRestrictionType.NONE;
model.authorizationControl = AuthorizationControl.NAMED;
GitBlit.self().updateRepositoryModel(model.name, model, false);
CloneCommand clone = Git.cloneRepository();
clone.setURI(MessageFormat.format("{0}/ticgit.git", url));
clone.setDirectory(ticgitFolder);
clone.setBare(false);
clone.setCloneAllBranches(true);
GitBlitSuite.close(clone.call());
assertTrue(true);
Git git = Git.open(ticgitFolder);
File file = new File(ticgitFolder, "TODO");
OutputStreamWriter os = new OutputStreamWriter(new FileOutputStream(file, true), Constants.CHARSET);
BufferedWriter w = new BufferedWriter(os);
w.write("// hellol中文 " + new Date().toString() + "\n");
w.close();
git.add().addFilepattern(file.getName()).call();
git.commit().setMessage("test commit").call();
Iterable<PushResult> results = git.push().setPushAll().call();
GitBlitSuite.close(git);
for (PushResult result : results) {
for (RemoteRefUpdate update : result.getRemoteUpdates()) {
assertEquals(Status.OK, update.getStatus());
}
}
}
示例7: testPushRestrictedRepo
import org.eclipse.jgit.api.CloneCommand; //導入方法依賴的package包/類
@Test
public void testPushRestrictedRepo() throws Exception {
GitBlitSuite.close(ticgitFolder);
if (ticgitFolder.exists()) {
FileUtils.delete(ticgitFolder, FileUtils.RECURSIVE | FileUtils.RETRY);
}
// restore anonymous repository access
RepositoryModel model = GitBlit.self().getRepositoryModel("ticgit.git");
model.accessRestriction = AccessRestrictionType.PUSH;
model.authorizationControl = AuthorizationControl.NAMED;
GitBlit.self().updateRepositoryModel(model.name, model, false);
CloneCommand clone = Git.cloneRepository();
clone.setURI(MessageFormat.format("{0}/ticgit.git", url));
clone.setDirectory(ticgitFolder);
clone.setBare(false);
clone.setCloneAllBranches(true);
GitBlitSuite.close(clone.call());
assertTrue(true);
Git git = Git.open(ticgitFolder);
File file = new File(ticgitFolder, "TODO");
OutputStreamWriter os = new OutputStreamWriter(new FileOutputStream(file, true), Constants.CHARSET);
BufferedWriter w = new BufferedWriter(os);
w.write("// hellol中文 " + new Date().toString() + "\n");
w.close();
git.add().addFilepattern(file.getName()).call();
git.commit().setMessage("test commit").call();
Iterable<PushResult> results = git.push().setPushAll().call();
GitBlitSuite.close(git);
for (PushResult result : results) {
for (RemoteRefUpdate update : result.getRemoteUpdates()) {
assertEquals(Status.REJECTED_OTHER_REASON, update.getStatus());
}
}
}
示例8: testPushToNonBareRepository
import org.eclipse.jgit.api.CloneCommand; //導入方法依賴的package包/類
@Test
public void testPushToNonBareRepository() throws Exception {
GitBlitSuite.close(jgit2Folder);
if (jgit2Folder.exists()) {
FileUtils.delete(jgit2Folder, FileUtils.RECURSIVE | FileUtils.RETRY);
}
CloneCommand clone = Git.cloneRepository();
clone.setURI(MessageFormat.format("{0}/working/jgit", url));
clone.setDirectory(jgit2Folder);
clone.setBare(false);
clone.setCloneAllBranches(true);
GitBlitSuite.close(clone.call());
assertTrue(true);
Git git = Git.open(jgit2Folder);
File file = new File(jgit2Folder, "NONBARE");
OutputStreamWriter os = new OutputStreamWriter(new FileOutputStream(file, true), Constants.CHARSET);
BufferedWriter w = new BufferedWriter(os);
w.write("// " + new Date().toString() + "\n");
w.close();
git.add().addFilepattern(file.getName()).call();
git.commit().setMessage("test commit followed by push to non-bare repository").call();
Iterable<PushResult> results = git.push().setPushAll().call();
GitBlitSuite.close(git);
for (PushResult result : results) {
for (RemoteRefUpdate update : result.getRemoteUpdates()) {
assertEquals(Status.REJECTED_OTHER_REASON, update.getStatus());
}
}
}
示例9: testPushToNonBareRepository
import org.eclipse.jgit.api.CloneCommand; //導入方法依賴的package包/類
@Test
public void testPushToNonBareRepository() throws Exception {
CloneCommand clone = Git.cloneRepository();
clone.setURI(MessageFormat.format("{0}/working/jgit", url));
clone.setDirectory(jgit2Folder);
clone.setBare(false);
clone.setCloneAllBranches(true);
clone.setCredentialsProvider(new UsernamePasswordCredentialsProvider(account, password));
GitBlitSuite.close(clone.call());
assertTrue(true);
Git git = Git.open(jgit2Folder);
File file = new File(jgit2Folder, "NONBARE");
OutputStreamWriter os = new OutputStreamWriter(new FileOutputStream(file, true), Constants.CHARSET);
BufferedWriter w = new BufferedWriter(os);
w.write("// " + new Date().toString() + "\n");
w.close();
git.add().addFilepattern(file.getName()).call();
git.commit().setMessage("test commit followed by push to non-bare repository").call();
Iterable<PushResult> results = git.push().setPushAll().setCredentialsProvider(new UsernamePasswordCredentialsProvider(account, password)).call();
GitBlitSuite.close(git);
for (PushResult result : results) {
for (RemoteRefUpdate update : result.getRemoteUpdates()) {
assertEquals(Status.REJECTED_OTHER_REASON, update.getStatus());
}
}
}
示例10: testBogusLoginClone
import org.eclipse.jgit.api.CloneCommand; //導入方法依賴的package包/類
@Test
public void testBogusLoginClone() throws Exception {
// restrict repository access
RepositoryModel model = GitBlit.self().getRepositoryModel("ticgit.git");
model.accessRestriction = AccessRestrictionType.CLONE;
GitBlit.self().updateRepositoryModel(model.name, model, false);
// delete any existing working folder
boolean cloned = false;
try {
CloneCommand clone = Git.cloneRepository();
clone.setURI(MessageFormat.format("{0}/ticgit.git", url));
clone.setDirectory(ticgit2Folder);
clone.setBare(false);
clone.setCloneAllBranches(true);
clone.setCredentialsProvider(new UsernamePasswordCredentialsProvider("bogus", "bogus"));
GitBlitSuite.close(clone.call());
cloned = true;
} catch (Exception e) {
// swallow the exception which we expect
}
// restore anonymous repository access
model.accessRestriction = AccessRestrictionType.NONE;
GitBlit.self().updateRepositoryModel(model.name, model, false);
assertFalse("Bogus login cloned a repository?!", cloned);
}
示例11: testAnonymousPush
import org.eclipse.jgit.api.CloneCommand; //導入方法依賴的package包/類
@Test
public void testAnonymousPush() throws Exception {
GitBlitSuite.close(ticgitFolder);
if (ticgitFolder.exists()) {
FileUtils.delete(ticgitFolder, FileUtils.RECURSIVE | FileUtils.RETRY);
}
RepositoryModel model = GitBlit.self().getRepositoryModel("ticgit.git");
model.accessRestriction = AccessRestrictionType.NONE;
GitBlit.self().updateRepositoryModel(model.name, model, false);
CloneCommand clone = Git.cloneRepository();
clone.setURI(MessageFormat.format("{0}/ticgit.git", url));
clone.setDirectory(ticgitFolder);
clone.setBare(false);
clone.setCloneAllBranches(true);
clone.setCredentialsProvider(new UsernamePasswordCredentialsProvider(account, password));
GitBlitSuite.close(clone.call());
assertTrue(true);
Git git = Git.open(ticgitFolder);
File file = new File(ticgitFolder, "TODO");
OutputStreamWriter os = new OutputStreamWriter(new FileOutputStream(file, true), Constants.CHARSET);
BufferedWriter w = new BufferedWriter(os);
w.write("// hellol中文 " + new Date().toString() + "\n");
w.close();
git.add().addFilepattern(file.getName()).call();
git.commit().setMessage("test commit").call();
Iterable<PushResult> results = git.push().setPushAll().call();
GitBlitSuite.close(git);
for (PushResult result : results) {
for (RemoteRefUpdate update : result.getRemoteUpdates()) {
assertEquals(Status.OK, update.getStatus());
}
}
}
示例12: testSubfolderPush
import org.eclipse.jgit.api.CloneCommand; //導入方法依賴的package包/類
@Test
public void testSubfolderPush() throws Exception {
GitBlitSuite.close(jgitFolder);
if (jgitFolder.exists()) {
FileUtils.delete(jgitFolder, FileUtils.RECURSIVE | FileUtils.RETRY);
}
CloneCommand clone = Git.cloneRepository();
clone.setURI(MessageFormat.format("{0}/test/jgit.git", url));
clone.setDirectory(jgitFolder);
clone.setBare(false);
clone.setCloneAllBranches(true);
clone.setCredentialsProvider(new UsernamePasswordCredentialsProvider(account, password));
GitBlitSuite.close(clone.call());
assertTrue(true);
Git git = Git.open(jgitFolder);
File file = new File(jgitFolder, "TODO");
OutputStreamWriter os = new OutputStreamWriter(new FileOutputStream(file, true), Constants.CHARSET);
BufferedWriter w = new BufferedWriter(os);
w.write("// " + new Date().toString() + "\n");
w.close();
git.add().addFilepattern(file.getName()).call();
git.commit().setMessage("test commit").call();
Iterable<PushResult> results = git.push().setPushAll().setCredentialsProvider(new UsernamePasswordCredentialsProvider(account, password)).call();
GitBlitSuite.close(git);
for (PushResult result : results) {
for (RemoteRefUpdate update : result.getRemoteUpdates()) {
assertEquals(Status.OK, update.getStatus());
}
}
}
示例13: cloneAndCheckout
import org.eclipse.jgit.api.CloneCommand; //導入方法依賴的package包/類
void cloneAndCheckout(BuildRequest request) throws ScmException {
final Path dir = request.getProjectRootDirectory();
final SrcVersion srcVersion = request.getSrcVersion();
ScmException lastException = null;
/* Try the urls one after another and exit on the first success */
for (String url : request.getScmUrls()) {
String useUrl = stripUriPrefix(url);
log.info("srcdeps: attempting to clone version {} from SCM URL {}", request.getSrcVersion(), useUrl);
CloneCommand cmd = Git.cloneRepository().setURI(useUrl).setDirectory(dir.toFile());
switch (srcVersion.getWellKnownType()) {
case branch:
case tag:
cmd.setBranch(srcVersion.getScmVersion());
break;
case revision:
cmd.setCloneAllBranches(true);
break;
default:
throw new IllegalStateException("Unexpected " + WellKnownType.class.getName() + " value '"
+ srcVersion.getWellKnownType() + "'.");
}
try (Git git = cmd.call()) {
git.checkout().setName(srcVersion.getScmVersion()).call();
/*
* workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=474093
*/
git.getRepository().close();
/* return on the first success */
return;
} catch (Exception e) {
log.warn("srcdeps: could not checkout version {} from SCM URL {}: {}: {}", request.getSrcVersion(),
useUrl, e.getClass().getName(), e.getMessage());
lastException = new ScmException(String.format("Could not checkout from URL [%s]", useUrl), e);
}
}
throw lastException;
}
示例14: clone
import org.eclipse.jgit.api.CloneCommand; //導入方法依賴的package包/類
private Git clone(POM pom, GitDependency dependency) {
final CloneCommand c = new CloneCommand();
c.setURI(dependency.getLocation());
c.setCloneAllBranches(true);
c.setProgressMonitor(new TextProgressMonitor());
final GitDependencyHandler dependencyHandler = new GitDependencyHandler(dependency);
String version = "";
version = dependencyHandler.getDependencyVersion(pom);
final String tempDirectory = Directory.getTempDirectoryString(dependency.getLocation(), version);
c.setDirectory(new File(tempDirectory));
return c.call();
}
示例15: testCommitterVerification
import org.eclipse.jgit.api.CloneCommand; //導入方法依賴的package包/類
private void testCommitterVerification(UserModel user, String displayName, String emailAddress, boolean expectedSuccess) throws Exception {
if (GitBlit.self().getUserModel(user.username) != null) {
GitBlit.self().deleteUser(user.username);
}
CredentialsProvider cp = new UsernamePasswordCredentialsProvider(user.username, user.password);
// fork from original to a temporary bare repo
File verification = new File(GitBlitSuite.REPOSITORIES, "refchecks/verify-committer.git");
if (verification.exists()) {
FileUtils.delete(verification, FileUtils.RECURSIVE);
}
CloneCommand clone = Git.cloneRepository();
clone.setURI(MessageFormat.format("{0}/ticgit.git", url));
clone.setDirectory(verification);
clone.setBare(true);
clone.setCloneAllBranches(true);
clone.setCredentialsProvider(cp);
GitBlitSuite.close(clone.call());
// require push permissions and committer verification
RepositoryModel model = GitBlit.self().getRepositoryModel("refchecks/verify-committer.git");
model.authorizationControl = AuthorizationControl.NAMED;
model.accessRestriction = AccessRestrictionType.PUSH;
model.verifyCommitter = true;
// grant user push permission
user.setRepositoryPermission(model.name, AccessPermission.PUSH);
GitBlit.self().updateUserModel(user.username, user, true);
GitBlit.self().updateRepositoryModel(model.name, model, false);
// clone temp bare repo to working copy
File local = new File(GitBlitSuite.REPOSITORIES, "refchecks/verify-wc");
if (local.exists()) {
FileUtils.delete(local, FileUtils.RECURSIVE);
}
clone = Git.cloneRepository();
clone.setURI(MessageFormat.format("{0}/{1}", url, model.name));
clone.setDirectory(local);
clone.setBare(false);
clone.setCloneAllBranches(true);
clone.setCredentialsProvider(cp);
GitBlitSuite.close(clone.call());
Git git = Git.open(local);
// force an identity which may or may not match the account's identity
git.getRepository().getConfig().setString("user", null, "name", displayName);
git.getRepository().getConfig().setString("user", null, "email", emailAddress);
git.getRepository().getConfig().save();
// commit a file and push it
File file = new File(local, "PUSHCHK");
OutputStreamWriter os = new OutputStreamWriter(new FileOutputStream(file, true), Constants.CHARSET);
BufferedWriter w = new BufferedWriter(os);
w.write("// " + new Date().toString() + "\n");
w.close();
git.add().addFilepattern(file.getName()).call();
git.commit().setMessage("push test").call();
Iterable<PushResult> results = git.push().setCredentialsProvider(cp).setRemote("origin").call();
for (PushResult result : results) {
RemoteRefUpdate ref = result.getRemoteUpdate("refs/heads/master");
Status status = ref.getStatus();
if (expectedSuccess) {
assertTrue("Verification failed! User was NOT able to push commit! " + status.name(), Status.OK.equals(status));
} else {
assertTrue("Verification failed! User was able to push commit! " + status.name(), Status.REJECTED_OTHER_REASON.equals(status));
}
}
GitBlitSuite.close(git);
// close serving repository
GitBlitSuite.close(verification);
}