Skip to content
\n

The remote server rejected my push and expects me to specify -o push-justification='bug_id' option. It is expected.

\n

Now I am trying to push with libgit2

\n
  char *refspec[] = {(char *)\"HEAD:refs/heads/__test\"};\n  const git_strarray refspecs = {refspec, 1};\n  int ret = git_remote_push(remote, &refspecs, nullptr);
\n

The git_remote_push function above returns 0 as a sign of success.

\n

But there are no any branch updates on the remotes. The remote rejected my push. I captured the traffic and I see a rejection message from the remote:

\n
009b�000eunpack ok\n0084ng refs/heads/__test Pushing to the ref 'refs/heads/__test' requires a justification: git push -o push-justification='bug_id'\n00000000\n
\n

yet libgit2 happily ignores the error.

\n

I would expect that git_remote_push returns a error code and the error message set to Pushing to the ref 'refs/heads/__test' requires a justification: git push -o push-justification='bug_id'.

","upvoteCount":1,"answerCount":3,"acceptedAnswer":{"@type":"Answer","text":"

I can provide a solution for you: The callback you need to register is git_push_update_reference_cb: https://libgit2.org/libgit2/#HEAD/group/callback/git_push_update_reference_cb. status will contain the rejection message you see.

","upvoteCount":1,"url":"https://github.com/libgit2/libgit2/discussions/6832#discussioncomment-9778528"}}}
Discussion options

You must be logged in to vote

I can provide a solution for you: The callback you need to register is git_push_update_reference_cb: https://libgit2.org/libgit2/#HEAD/group/callback/git_push_update_reference_cb. status will contain the rejection message you see.

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by ethomson
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #6831 on June 14, 2024 20:49.