List of usage examples for org.eclipse.jgit.lib Repository renameRef
@NonNull public RefRename renameRef(String fromRef, String toRef) throws IOException
From source file:com.gitblit.tickets.BranchTicketService.java
License:Apache License
/** * Returns a RefModel for the refs/meta/gitblit/tickets branch in the repository. * If the branch can not be found, null is returned. * * @return a refmodel for the gitblit tickets branch or null *//*w w w . j a v a2 s . co m*/ private RefModel getTicketsBranch(Repository db) { List<RefModel> refs = JGitUtils.getRefs(db, "refs/"); Ref oldRef = null; for (RefModel ref : refs) { if (ref.reference.getName().equals(BRANCH)) { return ref; } else if (ref.reference.getName().equals("refs/gitblit/tickets")) { oldRef = ref.reference; } } if (oldRef != null) { // rename old ref to refs/meta/gitblit/tickets RefRename cmd; try { cmd = db.renameRef(oldRef.getName(), BRANCH); cmd.setRefLogIdent(new PersonIdent("Gitblit", "gitblit@localhost")); cmd.setRefLogMessage("renamed " + oldRef.getName() + " => " + BRANCH); Result res = cmd.rename(); switch (res) { case RENAMED: log.info(db.getDirectory() + " " + cmd.getRefLogMessage()); return getTicketsBranch(db); default: log.error("failed to rename " + oldRef.getName() + " => " + BRANCH + " (" + res.name() + ")"); } } catch (IOException e) { log.error("failed to rename tickets branch", e); } } return null; }
From source file:com.gitblit.utils.RefLogUtils.java
License:Apache License
/** * Returns a RefModel for the reflog branch in the repository. If the * branch can not be found, null is returned. * * @param repository//from w w w. j ava 2 s . c o m * @return a refmodel for the reflog branch or null */ public static RefModel getRefLogBranch(Repository repository) { List<RefModel> refs = JGitUtils.getRefs(repository, "refs/"); Ref oldRef = null; for (RefModel ref : refs) { if (ref.reference.getName().equals(GB_REFLOG)) { return ref; } else if (ref.reference.getName().equals("refs/gitblit/reflog")) { oldRef = ref.reference; } else if (ref.reference.getName().equals("refs/gitblit/pushes")) { oldRef = ref.reference; } } if (oldRef != null) { // rename old ref to refs/meta/gitblit/reflog RefRename cmd; try { cmd = repository.renameRef(oldRef.getName(), GB_REFLOG); cmd.setRefLogIdent(new PersonIdent("Gitblit", "gitblit@localhost")); cmd.setRefLogMessage("renamed " + oldRef.getName() + " => " + GB_REFLOG); Result res = cmd.rename(); switch (res) { case RENAMED: LOGGER.info(repository.getDirectory() + " " + cmd.getRefLogMessage()); return getRefLogBranch(repository); default: LOGGER.error( "failed to rename " + oldRef.getName() + " => " + GB_REFLOG + " (" + res.name() + ")"); } } catch (IOException e) { LOGGER.error("failed to rename reflog", e); } } return null; }
From source file:jetbrains.buildServer.buildTriggers.vcs.git.tests.AgentVcsSupportTest.java
License:Apache License
@TestFor(issues = "TW-28735") public void fetch_branch_with_same_name_but_different_register() throws Exception { AgentRunningBuild buildWithMirrorsEnabled = createRunningBuild(true); myRoot = vcsRoot().withBranch("refs/heads/master").withAgentGitPath(getGitPath()) .withFetchUrl(GitUtils.toURL(myMainRepo)).build(); myVcsSupport.updateSources(myRoot, CheckoutRules.DEFAULT, "465ad9f630e451b9f2b782ffb09804c6a98c4bb9", myCheckoutDir, buildWithMirrorsEnabled, false); //rename master->Master Repository r = new RepositoryBuilder().setGitDir(myMainRepo).build(); r.renameRef("refs/heads/master", "refs/heads/Master").rename(); myRoot = vcsRoot().withBranch("refs/heads/Master").withAgentGitPath(getGitPath()) .withFetchUrl(GitUtils.toURL(myMainRepo)).build(); myVcsSupport.updateSources(myRoot, CheckoutRules.DEFAULT, "465ad9f630e451b9f2b782ffb09804c6a98c4bb9", myCheckoutDir, buildWithMirrorsEnabled, false); }
From source file:org.kuali.student.git.model.ref.utils.GitRefUtils.java
License:Educational Community License
public static Ref renameRef(Repository repo, PersonIdent refLogIdent, String fromRefName, String toRefName) throws IOException { RefRename rename = repo.renameRef(fromRefName, toRefName); rename.setRefLogIdent(refLogIdent);//from ww w. j a va 2 s.c o m rename.setRefLogMessage(refLogIdent + " archived " + fromRefName + " to " + toRefName); Result result = rename.rename(); if (result.equals(Result.LOCK_FAILURE)) { log.warn("lockfailure archiving " + fromRefName + " to branch = " + toRefName); try { Thread.currentThread().sleep(1000); } catch (InterruptedException e) { //fall through } return renameRef(repo, refLogIdent, fromRefName, toRefName); } else { if (result.equals(Result.RENAMED)) return repo.getRef(toRefName); else return null; } }