Java Code Examples for org.eclipse.jgit.api.CreateBranchCommand#setName()

The following examples show how to use org.eclipse.jgit.api.CreateBranchCommand#setName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JGitOperator.java    From verigreen with Apache License 2.0 6 votes vote down vote up
@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();
}
 
Example 2
Source File: SMAGitTest.java    From salesforce-migration-assistant with MIT License 6 votes vote down vote up
/**
 * 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());
}
 
Example 3
Source File: Project.java    From onedev with MIT License 5 votes vote down vote up
public void createBranch(String branchName, String branchRevision) {
try {
	CreateBranchCommand command = git().branchCreate();
	command.setName(branchName);
	RevCommit commit = getRevCommit(branchRevision, true);
	command.setStartPoint(getRevCommit(branchRevision, true));
	command.call();
	String refName = GitUtils.branch2ref(branchName); 
	cacheObjectId(refName, commit);
	
   	ObjectId commitId = commit.copy();
   	OneDev.getInstance(TransactionManager.class).runAfterCommit(new Runnable() {

		@Override
		public void run() {
	    	OneDev.getInstance(SessionManager.class).runAsync(new Runnable() {

				@Override
				public void run() {
					Project project = OneDev.getInstance(ProjectManager.class).load(getId());
					OneDev.getInstance(ListenerRegistry.class).post(
							new RefUpdated(project, refName, ObjectId.zeroId(), commitId));
				}
	    		
	    	});
		}
   		
   	});			
} catch (GitAPIException e) {
	throw new RuntimeException(e);
}
  }