本文整理汇总了Java中org.eclipse.jgit.api.CreateBranchCommand类的典型用法代码示例。如果您正苦于以下问题:Java CreateBranchCommand类的具体用法?Java CreateBranchCommand怎么用?Java CreateBranchCommand使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CreateBranchCommand类属于org.eclipse.jgit.api包,在下文中一共展示了CreateBranchCommand类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: checkoutBranch
import org.eclipse.jgit.api.CreateBranchCommand; //导入依赖的package包/类
protected void checkoutBranch(Git git, GitContext context) throws GitAPIException {
String current = currentBranch(git);
if (Objects.equals(current, branch)) {
return;
}
System.out.println("Checking out branch: " + branch);
// lets check if the branch exists
CheckoutCommand command = git.checkout().setName(branch);
boolean exists = localBranchExists(git, branch);
if (!exists) {
command = command.setCreateBranch(true).setForce(true).
setUpstreamMode(CreateBranchCommand.SetupUpstreamMode.TRACK).
setStartPoint(getRemote() + "/" + branch);
}
Ref ref = command.call();
if (LOG.isDebugEnabled()) {
LOG.debug("Checked out branch " + branch + " with results " + ref.getName());
}
configureBranch(git, branch);
}
示例4: 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);
}
}
示例5: checkoutToBranch
import org.eclipse.jgit.api.CreateBranchCommand; //导入依赖的package包/类
private void checkoutToBranch(String branch) throws GitAPIException {
CheckoutCommand checkoutCommand = clonedRepo.checkout()
.setCreateBranch(false)
.setName(branch);
List<Ref> refList = clonedRepo.branchList().call();
if (!anyRefMatches(refList, branch)) {
checkoutCommand = checkoutCommand
.setCreateBranch(true)
.setUpstreamMode(CreateBranchCommand.SetupUpstreamMode.TRACK)
.setStartPoint("origin/" + branch);
}
checkoutCommand
.call();
}
示例6: 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();
}
示例7: 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());
}
示例8: checkoutBranch
import org.eclipse.jgit.api.CreateBranchCommand; //导入依赖的package包/类
public void checkoutBranch(final String branchName) {
workspaceProvider.synchronizedOperation(new Callable<Void>() {
@Override
public Void call() {
try {
git.branchCreate()
.setName(branchName)
.setUpstreamMode(CreateBranchCommand.SetupUpstreamMode.SET_UPSTREAM)
.setStartPoint("origin/" + branchName)
.setForce(true)
.call();
git.checkout().setName(branchName).call();
} catch (final GitAPIException e) {
LOGGER.error("Unable to create/checkout branch " + branchName, e);
}
return null;
}
});
}
示例9: 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);
}
}
示例10: checkoutNewBranchFromRemote
import org.eclipse.jgit.api.CreateBranchCommand; //导入依赖的package包/类
/**
* Creates a new branch at the given start point and checks it out.
* @param git the git repository
* @param branchName the name of the new branch
* @param startPoint the starting point of the new branch
* @param upstreamMode whether to track the upstream branch or not.
* @return the checked out branch
* @throws GitAPIException
*/
public static Ref checkoutNewBranchFromRemote(
Git git, String branchName, String startPoint,
CreateBranchCommand.SetupUpstreamMode upstreamMode) throws GitAPIException {
return git.checkout()
.setCreateBranch(true)
.setName(branchName)
.setStartPoint(startPoint)
.setUpstreamMode(upstreamMode)
.call();
}
示例11: createNewBranchFromRemote
import org.eclipse.jgit.api.CreateBranchCommand; //导入依赖的package包/类
public static Ref createNewBranchFromRemote(
Git git, String branchName, RevCommit startingPoint,
CreateBranchCommand.SetupUpstreamMode upstreamMode) throws GitAPIException {
return git.branchCreate()
.setStartPoint(startingPoint)
.setName(branchName)
.setUpstreamMode(upstreamMode)
.call();
}
示例12: initializeGit
import org.eclipse.jgit.api.CreateBranchCommand; //导入依赖的package包/类
private Git initializeGit() throws IOException, GitAPIException {
if (path.isDirectory()) {
Git git = Git.open(path);
String current = git.getRepository().getBranch();
if (branch.equalsIgnoreCase(current)) {
PullResult pull = git.pull().setRemote(remote).call();
if (!pull.isSuccessful()) {
LOGGER.warn("Unable to pull the branch + '" + branch +
"' from the remote repository '" + remote + "'");
}
return git;
} else {
git.checkout().
setName(branch).
setUpstreamMode(CreateBranchCommand.SetupUpstreamMode.TRACK).
setStartPoint(remote + "/" + branch).
call();
return git;
}
} else {
return Git.cloneRepository()
.setURI(url)
.setBranch(branch)
.setRemote(remote)
.setDirectory(path)
.call();
}
}
示例13: checkoutBranch
import org.eclipse.jgit.api.CreateBranchCommand; //导入依赖的package包/类
/**
* Checkout existing branch.
*
* @param git
* instance.
* @param branch
* to move
* @param remote
* repository name
*
* @return Ref to current branch
*/
public Ref checkoutBranch(Git git, String branch, String remote) {
try {
return git.checkout()
.setCreateBranch(true)
.setName(branch)
.setUpstreamMode(CreateBranchCommand.SetupUpstreamMode.TRACK)
.setStartPoint(remote + "/" + branch)
.call();
} catch (GitAPIException e) {
throw new IllegalStateException(e);
}
}
示例14: createBranchAndCheckout
import org.eclipse.jgit.api.CreateBranchCommand; //导入依赖的package包/类
/**
* Executes a checkout -b command using given branch.
*
* @param git
* instance.
* @param branch
* to create and checkout.
*
* @return Ref to current branch.
*/
public Ref createBranchAndCheckout(Git git, String branch) {
try {
return git.checkout()
.setCreateBranch(true)
.setName(branch)
.setUpstreamMode(CreateBranchCommand.SetupUpstreamMode.TRACK)
.call();
} catch (GitAPIException e) {
throw new IllegalStateException(e);
}
}
示例15: checkout
import org.eclipse.jgit.api.CreateBranchCommand; //导入依赖的package包/类
/**
* Does not do anything if already on target branch.
*/
public void checkout(String branch) throws Exception {
if (!branch.equals(getBranch())) {
createBranchIfNeeded(branch);
git.checkout().setName(branch).setStartPoint("origin/" + branch)
.setUpstreamMode(CreateBranchCommand.SetupUpstreamMode.TRACK).call();
// for some reason jgit needs this when branch is switched
git.checkout().setName(branch).call();
}
}