This is such a common pattern that it might be nice to make an internal helper method to help here.  (In fact, I thought we *did*, but it might be hanging out on some unmerged branch somewhere.)  For example:

    char *git_oid_fmtz(char *oidstr, git_oid *oid) {
        git_oid_fmt(oidstr, oid);
        oidstr[GIT_OID_HEXSZ] = 0;
        return oidstr;
    }

So that you could:

    char commit_oidstr[GIT_OID_HEXSZ + 1];

    giterr_set(GITERR_CHERRYPICK, "Mainline branch specified, but %s is not a merge commit",
        git_oid_fmtz(commit_oidstr, cherry_pick_commit));

This would let you drop this helper method *and* we could drop the various places that we do this git_oid_fmt and then null-terminate pattern, which I personally find very annoying.