本文整理汇总了Java中org.eclipse.jgit.api.CreateBranchCommand.call方法的典型用法代码示例。如果您正苦于以下问题:Java CreateBranchCommand.call方法的具体用法?Java CreateBranchCommand.call怎么用?Java CreateBranchCommand.call使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jgit.api.CreateBranchCommand
的用法示例。
在下文中一共展示了CreateBranchCommand.call方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createBranch
import org.eclipse.jgit.api.CreateBranchCommand; //导入方法依赖的package包/类
/**
* Creates branch on provided repository - git branch name
*
* @param repositoryName for which repository
* @param name of branch
*/
public void createBranch(String repositoryName, String name)
{
RepositoryContext repositoryContext = repositoryByName.get(repositoryName);
try
{
CreateBranchCommand createBranchCommand = repositoryContext.git.branchCreate();
createBranchCommand.setName(name);
createBranchCommand.call();
}
catch (GitAPIException e)
{
throw new RuntimeException(e);
}
}
示例2: createBranch
import org.eclipse.jgit.api.CreateBranchCommand; //导入方法依赖的package包/类
/**
* Create a new branch in the local git repository
* (git checkout -b branchname) and finally pushes new branch on the remote repository (git push)
*
* @param directory the directory in which the local git repository is located
* @param username the username to be used while pushing
* @param password the password matching with the provided username to be used
* for authentication
* @param message the commit message to be used
*/
public static void createBranch(@NonNull File directory, String branchName, String username,
String password, String message) throws GitAPIException {
try {
final Git git = Git.open(directory);
final UsernamePasswordCredentialsProvider userCredential = new UsernamePasswordCredentialsProvider(
username, password);
CreateBranchCommand branchCommand = git.branchCreate();
branchCommand.setName(branchName);
branchCommand.call();
// and then commit
final PersonIdent author = new PersonIdent(username, "");
git.commit().setCommitter(author).setMessage(message)
.setAuthor(author).call();
log.info(message);
git.push().setCredentialsProvider(userCredential).call();
log.info("Pushed the changes in remote Git repository...");
} catch (final GitAPIException | IOException e) {
log.error(e.getMessage(), e);
}
}
示例3: branchCreate
import org.eclipse.jgit.api.CreateBranchCommand; //导入方法依赖的package包/类
@Override
public Branch branchCreate(String name, String startPoint) throws GitException {
CreateBranchCommand createBranchCommand = getGit().branchCreate().setName(name);
if (startPoint != null) {
createBranchCommand.setStartPoint(startPoint);
}
try {
Ref brRef = createBranchCommand.call();
String refName = brRef.getName();
String displayName = Repository.shortenRefName(refName);
return newDto(Branch.class)
.withName(refName)
.withDisplayName(displayName)
.withActive(false)
.withRemote(false);
} catch (GitAPIException exception) {
throw new GitException(exception.getMessage(), exception);
}
}
示例4: createBranch
import org.eclipse.jgit.api.CreateBranchCommand; //导入方法依赖的package包/类
@Override
public String createBranch(String commitId, String branchName) {
Ref result = null;
CreateBranchCommand branchCreate = _git.branchCreate();
branchCreate.setName(branchName);
branchCreate.setStartPoint(commitId);
try {
result = branchCreate.call();
} catch (Throwable e) {
throw new RuntimeException(String.format(
"Failed creating branch: %s for commit [%s]",
branchName,
commitId), e);
}
return result.getName();
}
示例5: testPullRequest
import org.eclipse.jgit.api.CreateBranchCommand; //导入方法依赖的package包/类
/**
* Test the ghprb constructor.
*
* @throws Exception
*/
@Test
public void testPullRequest() throws Exception
{
Map<String, byte[]> expectedContents = new HashMap<String, byte[]>();
expectedContents.put("src/pages/modifyThis.page", contents.getBytes());
expectedContents.put("src/pages/modifyThis.page-meta.xml", contents.getBytes());
expectedContents.put("src/triggers/addThis.trigger", contents.getBytes());
expectedContents.put("src/triggers/addThis.trigger-meta.xml", contents.getBytes());
String oldBranch = "refs/remotes/origin/oldBranch";
CreateBranchCommand cbc = new Git(repository).branchCreate();
cbc.setName(oldBranch);
cbc.setStartPoint(oldSha);
cbc.call();
git = new SMAGit(gitDir, newSha, "oldBranch", SMAGit.Mode.PRB);
Map<String, byte[]> allMetadata = git.getAllMetadata();
assertEquals(expectedContents.size(), allMetadata.size());
}
示例6: createBranch
import org.eclipse.jgit.api.CreateBranchCommand; //导入方法依赖的package包/类
public void createBranch(String branchName, String branchRevision) {
try {
CreateBranchCommand command = git().branchCreate();
command.setName(branchName);
command.setStartPoint(getRevCommit(branchRevision));
command.call();
} catch (GitAPIException e) {
throw new RuntimeException(e);
}
}
示例7: createLocalBranch
import org.eclipse.jgit.api.CreateBranchCommand; //导入方法依赖的package包/类
public LocalBranch createLocalBranch() throws GitAPIException {
GitRepository gitRepository = getGitRepository();
Repository repository = gitRepository.getRepository();
Git git = gitRepository.getGit();
CreateBranchCommand branchCreate = git.branchCreate();
String name = getName();
String shortenRefName = repository.shortenRemoteBranchName(name);
branchCreate.setName(shortenRefName);
branchCreate.setStartPoint(name);
branchCreate.setUpstreamMode(SetupUpstreamMode.SET_UPSTREAM);
Ref call = branchCreate.call();
return new LocalBranch(gitRepository, call);
}
示例8: build
import org.eclipse.jgit.api.CreateBranchCommand; //导入方法依赖的package包/类
/**
* Requires a bare repository. We clone to a random workspace
*
* @throws Exception
* @return The generator currently being worked on
*/
public UniqueBranchGenerator build() throws Exception {
Git git;
File workDirTarget = new File(repo.getDirectory().getAbsolutePath() + "/../../" + UUID.randomUUID().toString());
System.out.println(workDirTarget.getAbsolutePath());
Git.cloneRepository()
.setURI("file://" + repo.getDirectory().getAbsolutePath())
.setBare(false)
.setNoCheckout(false)
.setCloneAllBranches(true)
.setDirectory(workDirTarget).call().close();
File gitMetaDir = new File(workDirTarget.getAbsolutePath() + System.getProperty("file.separator") + ".git");
System.out.println("Setting .git metadata to work in directory: " + gitMetaDir.getAbsolutePath());
git = Git.open(gitMetaDir);
CreateBranchCommand createBranchCommand = git.branchCreate();
createBranchCommand.setName(branchName);
createBranchCommand.call();
git.checkout().setName(branchName).call();
File repoRoot = git.getRepository().getWorkTree();
UUID rand = UUID.randomUUID();
File randomFile = new File(repoRoot, rand.toString() + ".log");
randomFile.createNewFile();
git.add().addFilepattern(".").call();
int cnt = 0;
for (String msg : commitMessages) {
FileUtils.writeStringToFile(randomFile, rand.toString() + "-" + cnt + "\n", true);
CommitCommand commitCommand = git.commit();
commitCommand.setMessage(msg);
commitCommand.setAuthor(AUTHOR_NAME, AUTHOR_EMAIL);
commitCommand.call();
cnt++;
}
git.push().setPushAll().call();
git.checkout().setName("master");
git.close();
FileUtils.deleteDirectory(workDirTarget);
return this;
}
示例9: createValidRepository
import org.eclipse.jgit.api.CreateBranchCommand; //导入方法依赖的package包/类
public static Repository createValidRepository(String repoFolderName) throws IOException, GitAPIException {
File repo = new File(WORKDIR,repoFolderName + ".git"); // bare repo should have suffix .git, and contain what normally in .git
if (repo.exists()) {
System.out.format("EXIST:" + repo.getAbsolutePath());
try {
TestUtilsFactory.destroyDirectory(repo);
} catch (InterruptedException e) {
throw new IOException(e);
}
}
File workDirForRepo = new File(WORKDIR, repoFolderName);
Repository repository = new FileRepository(repo);
repository.create(true);
Git.cloneRepository().setURI("file:///" + repo.getAbsolutePath()).setDirectory(workDirForRepo)
.setBare(false)
.setCloneAllBranches(true)
.setNoCheckout(false)
.call().close();
Git git = Git.open(workDirForRepo);
String FEATURE_BRANCH_NAME = "ready/feature_1";
File readme = new File(workDirForRepo + "/readme");
if (!readme.exists()) {
FileUtils.writeStringToFile(readme, "sample text\n");
}
git.add().addFilepattern(readme.getName()).call();
git.commit().setMessage(TestUtilsFactory.createCommitMessageForRepo(repoFolderName, git.getRepository().getBranch(), "commit message 1")).call();
FileUtils.writeStringToFile(readme, "changed sample text\n");
git.add().addFilepattern(readme.getName()).call();
git.commit().setMessage(TestUtilsFactory.createCommitMessageForRepo(repoFolderName, git.getRepository().getBranch(), "commit message 2")).call();
CreateBranchCommand createBranchCommand = git.branchCreate();
createBranchCommand.setName(FEATURE_BRANCH_NAME);
createBranchCommand.call();
git.checkout().setName(FEATURE_BRANCH_NAME).call();
FileUtils.writeStringToFile(readme, "FEATURE_1 branch commit 1\n", true);
git.add().addFilepattern(readme.getName()).call();
CommitCommand commitCommand = git.commit();
commitCommand.setMessage(TestUtilsFactory.createCommitMessageForRepo(repoFolderName, git.getRepository().getBranch(), "feature 1 commit 1"));
commitCommand.setAuthor(AUTHOR_NAME, AUTHOR_EMAIL);
commitCommand.call();
FileUtils.writeStringToFile(readme, "FEATURE_1 branch commit 2\n", true);
git.add().addFilepattern(readme.getName()).call();
commitCommand = git.commit();
commitCommand.setMessage(TestUtilsFactory.createCommitMessageForRepo(repoFolderName, git.getRepository().getBranch(), "feature 1 commit 2"));
commitCommand.setAuthor(AUTHOR_NAME, AUTHOR_EMAIL);
commitCommand.call();
git.push().setPushAll().call();
git.checkout().setName("master").call();
FileUtils.deleteDirectory(workDirForRepo);
return repository;
}
示例10: createRepositoryWithMergeConflict
import org.eclipse.jgit.api.CreateBranchCommand; //导入方法依赖的package包/类
public static Repository createRepositoryWithMergeConflict(String repoFolderName) throws IOException, GitAPIException {
String FEATURE_BRANCH_NAME = "ready/feature_1";
File repo = new File(WORKDIR,repoFolderName + ".git"); // bare repo should have suffix .git, and contain what normally in .git
File workDirForRepo = new File(WORKDIR, repoFolderName);
Repository repository = new FileRepository(repo);
repository.create(true);
Git.cloneRepository().setURI("file:///" + repo.getAbsolutePath()).setDirectory(workDirForRepo)
.setBare(false)
.setCloneAllBranches(true)
.setNoCheckout(false)
.call().close();
Git git = Git.open(workDirForRepo);
File readme = new File(workDirForRepo + "/readme");
if (!readme.exists()) {
FileUtils.writeStringToFile(readme, "sample text\n");
}
git.add().addFilepattern(readme.getName()).call();
git.commit().setMessage("commit message 1").call();
FileUtils.writeStringToFile(readme, "changed sample text\n");
git.add().addFilepattern(readme.getName()).call();
git.commit().setMessage("commit message 2").call();
CreateBranchCommand createBranchCommand = git.branchCreate();
createBranchCommand.setName(FEATURE_BRANCH_NAME);
createBranchCommand.call();
git.checkout().setName(FEATURE_BRANCH_NAME).call();
FileUtils.writeStringToFile(readme, "FEATURE_1 branch commit 1\n");
git.add().addFilepattern(readme.getName()).call();
CommitCommand commitCommand = git.commit();
commitCommand.setMessage("feature 1 commit 1");
commitCommand.setAuthor(AUTHOR_NAME, AUTHOR_EMAIL);
commitCommand.call();
FileUtils.writeStringToFile(readme, "FEATURE_1 branch commit 2\n");
git.add().addFilepattern(readme.getName()).call();
commitCommand = git.commit();
commitCommand.setMessage("feature 1 commit 2");
commitCommand.setAuthor(AUTHOR_NAME, AUTHOR_EMAIL);
commitCommand.call();
git.checkout().setName("master").call();
FileUtils.writeStringToFile(readme, "Merge conflict branch commit 2\n");
git.add().addFilepattern(readme.getName()).call();
commitCommand = git.commit();
commitCommand.setMessage("merge conflict message 1");
commitCommand.setAuthor(AUTHOR_NAME, AUTHOR_EMAIL);
commitCommand.call();
git.push().setPushAll().call();
FileUtils.deleteDirectory(workDirForRepo);
return repository;
}
示例11: createRepository
import org.eclipse.jgit.api.CreateBranchCommand; //导入方法依赖的package包/类
private void createRepository() throws IOException, GitAPIException {
File repo = new File(TestUtilsFactory.WORKDIR,"EnvVar - " + UUID.randomUUID().toString().substring(0, 6) + "/.git");
if (repo.getAbsoluteFile().exists()) {
FileUtils.deleteDirectory(repo.getParentFile());
}
FileRepositoryBuilder builder = new FileRepositoryBuilder();
repository = builder.setGitDir(repo.getAbsoluteFile())
.readEnvironment() // scan environment GIT_* variables
.findGitDir() // scan up the file system tree
.build();
if (!repository.isBare() && repository.getBranch() == null) {
repository.create();
}
Git git = new Git(repository);
File readme = new File(repository.getDirectory().getParent().concat("/" + "readme"));
FileUtils.writeStringToFile(readme, "commit 1\n");
git.add().addFilepattern(readme.getName()).call();
git.commit().setMessage("commit message 1").call();
CreateBranchCommand createBranchCommand = git.branchCreate();
createBranchCommand.setName(INTEGRATION_BRANCH);
createBranchCommand.call();
createBranchCommand = git.branchCreate();
createBranchCommand.setName(READY_BRANCH);
createBranchCommand.call();
CheckoutCommand checkout = git.checkout();
checkout.setName(READY_BRANCH);
checkout.call();
FileUtils.writeStringToFile(readme, "commit 2\n");
git.add().addFilepattern(readme.getName()).call();
git.commit().setMessage("commit message 2").call();
checkout = git.checkout();
checkout.setName(INTEGRATION_BRANCH);
checkout.call();
DeleteBranchCommand deleteBranchCommand = git.branchDelete();
deleteBranchCommand.setBranchNames("master");
deleteBranchCommand.call();
REPOSITORY = repository.getDirectory().getAbsolutePath();
}