public static Memory valueOf(AnyObjectId value) { return value == null ? Memory.NULL : StringMemory.valueOf(value.getName()); }
/** * Include a commit * * @param commit * the Id of a commit which is cherry-picked to the current head * @return {@code this} */ public CherryPickCommand include(AnyObjectId commit) { return include(commit.getName(), commit); }
/** * Include a commit to be reverted * * @param commit * the Id of a commit to be reverted into the current head * @return {@code this} */ public RevertCommand include(AnyObjectId commit) { return include(commit.getName(), commit); }
/** * Id of a commit which is to be merged with the current head * * @param aCommit * the Id of a commit which is merged with the current head * @return {@code this} */ public MergeCommand include(AnyObjectId aCommit) { return include(aCommit.getName(), aCommit); }
/** * Simplify an expression, but unlike {@link #resolve(String)} it will not * resolve a branch passed or resulting from the expression, such as @{-}. * Thus this method can be used to process an expression to a method that * expects a branch or revision id. * * @param revstr a {@link java.lang.String} object. * @return object id or ref name from resolved expression or {@code null} if * given expression cannot be resolved * @throws org.eclipse.jgit.errors.AmbiguousObjectException * @throws java.io.IOException */ @Nullable public String simplify(String revstr) throws AmbiguousObjectException, IOException { try (RevWalk rw = new RevWalk(this)) { Object resolved = resolve(rw, revstr); if (resolved != null) if (resolved instanceof String) return (String) resolved; else return ((AnyObjectId) resolved).getName(); return null; } }
/** * @param aCommit * the Id of a commit which is merged with the current head * @return {@code this} */ public MergeCommand include(AnyObjectId aCommit) { return include(aCommit.getName(), aCommit); }
/** * @param commit * the Id of a commit which is reverted into the current head * @return {@code this} */ public RevertCommand include(AnyObjectId commit) { return include(commit.getName(), commit); }
/** * Id of a commit which is to be merged with the current head * * @param aCommit * the Id of a commit which is merged with the current head * @return {@code this} */ public MergeCommand include(AnyObjectId aCommit) { return include(aCommit.getName(), aCommit); }
public static void detachRepositoryHead(@Nonnull Repository repo, @Nonnull AnyObjectId id) throws IOException { id = CommitUtils.getCommit(id, repo); RefUpdate update = prepareUpdateHead(repo, id.getName(), true); update.setNewObjectId(id); RefUpdateValidator.validate(update.forceUpdate()); }
public static void detachRepositoryHead(Repository repo, AnyObjectId id) throws IOException { id = CommitUtils.getCommit(id, repo); RefUpdate update = prepareUpdateHead(repo, id.getName(), true); update.setNewObjectId(id); RefUpdateValidator.validate(update.forceUpdate()); }
public static void detachRepositoryHead(Repository repo, AnyObjectId id) throws IOException { id = CommitUtils.getCommit(id, repo); RefUpdate update = prepareUpdateHead(repo, id.getName(), true); update.setNewObjectId(id); RefUpdateValidator.validate(update.forceUpdate()); }
@Test(expected = BranchAlreadyExistsException.class) public void createBranchWhenBranchAlreadyExists_shouldThrowBranchAlreadyExistsException() throws IOException { writeSomethingToCache(); AnyObjectId commit = commitToMaster(); BranchUtils.createBranch("test_branch", commit.getName(), repo); BranchUtils.createBranch("test_branch", commit.getName(), repo); }
@Test(expected = NoSuchFileException.class) public void openFileWhenFileDoesNotExist_shouldThrowNoSuchFileException() throws IOException { writeSomethingToCache(); AnyObjectId commit = commitToMaster(); GitFileUtils.openFile("/non_existent_file.txt", commit.getName(), repo); }
@Test(expected = NoSuchFileException.class) public void readFileWhenFileDoesNotExist_shouldThrowNoSuchFileException() throws IOException { writeSomethingToCache(); AnyObjectId commit = commitToMaster(); GitFileUtils.readFile("/non_existent_file.txt", commit.getName(), repo); }
@Test public void createBranchFromCommitName_theRefLogShouldStartWithBranchCreatedFromCommit() throws IOException { writeSomethingToCache(); AnyObjectId commit = commitToMaster(); BranchUtils.createBranch("test_branch", commit.getName(), repo); ReflogEntry lastRefLog = BranchUtils.getLastLog("test_branch", repo); assert lastRefLog != null; assertTrue(lastRefLog.getComment().startsWith("branch: Created from commit")); }
@Test public void detachHeadToCommit_theRepositoryHeadShouldBecomeTheSpecifiedCommitId() throws IOException { writeSomethingToCache(); AnyObjectId commitId = commitToMaster(); RepositoryUtils.detachRepositoryHead(repo, commitId); assertEquals(commitId.getName(), repo.getBranch()); }
@Test public void createBranch_theNewBranchShouldExistAfterTheOperation() throws IOException { writeSomethingToCache(); AnyObjectId commit = commitToMaster(); BranchUtils.createBranch("test_branch", commit.getName(), repo); assertTrue(BranchUtils.branchExists("test_branch", repo)); }
@Test public void readFile_theResultShouldEqualToTheFileContent() throws IOException { byte[] expected = someBytes(); writeToCache("/test_file.txt", expected); AnyObjectId commit = commitToMaster(); byte[] actual = GitFileUtils.readFile("/test_file.txt", commit.getName(), repo).getData(); assertArrayEquals(expected, actual); }
@Test public void setHeadToTag_theRepositoryHeadShouldDetachToTheTaggedCommit() throws IOException { writeSomethingToCache(); AnyObjectId commitId = commitToMaster(); Ref tagRef = TagUtils.tagCommit("test_tag", commitId, repo); RepositoryUtils.setRepositoryHead(repo, tagRef.getName()); assertEquals(commitId.getName(), repo.getBranch()); }