libgit2 / libgit2/libgit2sharp

Failed push not displaying pre-receive hook error message

Open
#1,838 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
3.5k
Forks
925
PR merge metrics
No merged PRs in 30d

Description

Executing a push that is rejected by the pre-receive hook on the server side, the OnPushStatusError notification is not displaying the error message returning by the remote git server, it is just showing the generic error pre-receive hook declined.

Executing the same push but with the git command line, the message error is dsplayed correctly.

# git push origin master
Enumerating objects: 8, done.
Counting objects: 100% (8/8), done.
Delta compression using up to 12 threads
Compressing objects: 100% (4/4), done.
Writing objects: 100% (6/6), 504 bytes | 504.00 KiB/s, done.
Total 6 (delta 2), reused 0 (delta 0)
remote: GL-HOOK-ERR: MY SPECIFIC ERROR MESSAGE
To https://nsgitlab/pablo.nardone/test3.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://nsgitlab/pablo.nardone/test3.git'
Reproduction steps

Setup a pre-receive hook that reject the push with some specific error message. In my case the message is GL-HOOK-ERR: MY SPECIFIC ERROR MESSAGE. Execute from command line git push origin master and verifiy the push si rejected and the specific error message is displayed correctly. Execute the same push operation but this time with the LibGit2Sharp library and verify the push is rejected but only displaying the generic error pre-receive hook declined and not the specific error returning by the pre-receive hook.

try
{
	PushOptions options = new PushOptions
	{
		OnPushStatusError = (PushStatusError pushStatusErrors) =>
		{
			throw new Exception($"OnPushStatusError - Reference({pushStatusErrors.Reference}) Message({pushStatusErrors.Message})");
		},
	};
	repo.Network.Push(branch, options);
}
catch (Exception ex)
{
	Debug.WriteLine(ex.Message);
}
Expected behavior
OnPushStatusError - Reference(refs/heads/master) Message(pre-receive hook declined. GL-HOOK-ERR: MY SPECIFIC ERROR MESSAGE)
Actual behavior
OnPushStatusError - Reference(refs/heads/master) Message(pre-receive hook declined)
Version of LibGit2Sharp (release number or SHA1)

LibGitSharp 0.26.2

Operating system(s) tested; .NET runtime tested

Windows 10 Pro, .NET 4.7.2

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at PushOptions.OnPushStatusError and the repo.Network.Push entry point shown in the reproduction, then trace how the remote rejection message reaches PushStatusError.Message. Reproduce the pre-receive hook failure and compare the library callback with the command-line output. Done means the callback includes both the generic rejection and the hook's specific message.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, git
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.