-
I am using libgit2 v1.8.1 and testing its functionality against the git CLI. I am trying to push a branch to our remote repo and it fails:
The remote server rejected my push and expects me to specify Now I am trying to push with libgit2 char *refspec[] = {(char *)"HEAD:refs/heads/__test"};
const git_strarray refspecs = {refspec, 1};
int ret = git_remote_push(remote, &refspecs, nullptr); The 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:
yet libgit2 happily ignores the error. I would expect that |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
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. |
Beta Was this translation helpful? Give feedback.
-
@lrm29 is correct here — to add some color, the rationale for this behavior is that there can be multiple ref updates in a single push, each one can fail or succeed individually. So the reporting of what tips the remote has updated is independent of the overall success or failure of the operation. |
Beta Was this translation helpful? Give feedback.
-
Thank you for the quick reply! I'll look at it. Handling errors from remote sounds like a common functionality. Are there any existing callback implementations that handle error codes? |
Beta Was this translation helpful? Give feedback.
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.