libgit2 / libgit2sharp

Git + .NET = ❤
http://libgit2.github.com
MIT License
3.21k stars 890 forks source link

View Incoming Commits from a Pre-Receive Hook #1977

Open tghanem opened 2 years ago

tghanem commented 2 years ago

I have developed a pre-receive hook using C#/.NET and used libgit2sharp to retrieve the commits that are being pushed from the client. When I access the Repository.Commits, I only see the old commits not the ones that are being pushed.

I tried using a bash script to implement the hook and execute git rev-list $rev_old..$rev_new and it works and I can see the commits.

So, I'm wondering why does the bash script work and the C#/.NET executable does not given that both executables are executing on the same working directory that Git assigns to the hook.

P.S. I'm using BitBucket Server on-premise deployment - it shouldn't matter I think because the hook works at the Git level not BitBucket

Reproduction steps

  1. Create a .NET 6.0 Console application and add a reference to libgit2sharp.
  2. Write code to obtain the commits between the old ref and the new ref as provided by Git.
  3. Build and configure the hook on the Git repository directory.
  4. Use a Git client to push commits to the server.

Expected behavior

The commits coming from the client should be seen when the Repository.Commits is enumerated.

Actual behavior

Only the commits before the push are returned not the incoming commits.

Version of LibGit2Sharp (release number or SHA1)

0.26.2

Operating system(s) tested; .NET runtime tested

Ubuntu 18.04 and .NET 6.0

qx4235 commented 2 years ago

same issue,may someone could help us, plz!