-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
**Whitelist-Push** and **MergePullrequest** does not work when Branch-Protection is enabled #7754
Comments
Cannot reproduce this on my local |
We need to see the Gitea log. |
@lunny I also can not produce this bug on I think 356854f has something to do with this. before:
after
I'll try to provide the gitea log. |
Ah. I've figured this out. That repo path needs to be prefixed with the Gitea repository path. You're running Gitea from a weird working directory meaning that repo.RepoPath() won't work. Nope this was totally wrong. |
I am taking care of the infrastructure for the system on which the problem was found by @sharpSteff. INFO: Gitea is running behind a reverse proxy mapping the server to a sub-directory ( As mentioned rolling back to HEAD of 1.8 branch solves the issue, there must be something breaking in 1.9 regarding such setups. Is this information enough? |
I could find the related entry in the log file (the
|
I think maybe environments break it.
We can remove these. But I can't reproduce that locally. |
@lunny hooks will not work without these environment variables. It should be something to do with specific configuration (gitea workdir, homedir or app.ini paths) |
part of app.ini:
|
|
what is workdir in service file specified and what is home directory for git user? |
The service file is:
|
BTW the permissions inside |
This does not seem correct in service file: |
@jdehaan Which git version are you using? |
2.7.4 on that server |
Gosh... you're right I must have done this wrong for years.... Strangely the same config works for Gitea 1.8.3 without trouble, I did not touch that part only upgraded Gitea. |
@lafriks this git command will only detect force push, it's unrelated with hooks. The http request is from a prereceived hook I know. |
@lunny yes but it was rewritten to remove gitea serv command |
As the code modified something regarding the environment handling, I could give the upgrade a second try with the right parameters and report, before wasting your time. Thanks for the hints. |
Changed the service file part:
Same error, currently tested with Gitea Version: 1.9.0+10-gaea49d0
|
From the log:
|
While it is probably not a clean fix..... I am aware of that I tried to patch the code in the following way: --- a/routers/private/hook.go
+++ b/routers/private/hook.go
@@ -8,13 +8,13 @@ package private
import (
"fmt"
"net/http"
- "os"
+ //"os"
"strings"
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log"
- "code.gitea.io/gitea/modules/private"
+ //"code.gitea.io/gitea/modules/private"
"code.gitea.io/gitea/modules/repofiles"
"code.gitea.io/gitea/modules/util"
@@ -29,8 +29,8 @@ func HookPreReceive(ctx *macaron.Context) {
newCommitID := ctx.QueryTrim("new")
refFullName := ctx.QueryTrim("ref")
userID := ctx.QueryInt64("userID")
- gitObjectDirectory := ctx.QueryTrim("gitObjectDirectory")
- gitAlternativeObjectDirectories := ctx.QueryTrim("gitAlternativeObjectDirectories")
+ //gitObjectDirectory := ctx.QueryTrim("gitObjectDirectory")
+ //gitAlternativeObjectDirectories := ctx.QueryTrim("gitAlternativeObjectDirectories")
prID := ctx.QueryInt64("prID")
branchName := strings.TrimPrefix(refFullName, git.BranchPrefix)
@@ -63,13 +63,14 @@ func HookPreReceive(ctx *macaron.Context) {
// detect force push
if git.EmptySHA != oldCommitID {
- env := append(os.Environ(),
- private.GitAlternativeObjectDirectories+"="+gitAlternativeObjectDirectories,
- private.GitObjectDirectory+"="+gitObjectDirectory,
- private.GitQuarantinePath+"="+gitObjectDirectory,
- )
-
- output, err := git.NewCommand("rev-list", "--max-count=1", oldCommitID, "^"+newCommitID).RunInDirWithEnv(repo.RepoPath(), env)
+ //env := append(os.Environ(),
+ // private.GitAlternativeObjectDirectories+"="+gitAlternativeObjectDirectories,
+ // private.GitObjectDirectory+"="+gitObjectDirectory,
+ // private.GitQuarantinePath+"="+gitObjectDirectory,
+ //)
+
+ //output, err := git.NewCommand("rev-list", "--max-count=1", oldCommitID, "^"+newCommitID).RunInDirWithEnv(repo.RepoPath(), env)
+ output, err := git.NewCommand("rev-list", "--max-count=1", oldCommitID, "^"+newCommitID).RunInDir(repo.RepoPath())
if err != nil {
log.Error("Unable to detect force push between: %s and %s in %-v Error: %v", oldCommitID, newCommitID, repo, err)
ctx.JSON(http.StatusInternalServerError, map[string]interface{}{ That solves the issue. Maybe that helps you to see where & why things are going wrong in our use case/setup... |
The workaround is similiar what I guess in #7754 (comment). @zeripath do you remember why we add those environments? |
OK, this is very confusing. This works on testing - perhaps it's a weirdness of the early git version? The internal call to the hook actually has the values passed in the GET request - this was deliberate to act as logging but you've not given us these. Do you have the ROUTER log turned off? It could be that your version of git is not setting these and therefore by us setting them that causes the problem, or it could be that git deletes them and keeps a read hold on the directory meaning that the gitea process doesn't have access to them. Were they being set at all? What was their value? Did it require removing all of these environment variables to make things work? The reasoning behind passing these in to the git process is that the head commit and the base may be in these alternative directories - I suspect that later versions of git are going to be more keen to use these alternative directories to quarantine against pollution of repositories. |
I did not deliberately turn down some logging. I will look into the available log settings. At the moment we are just happy with the poor but working workaround that restores part of the 1.8 branch logic. |
OK I've been able to replicate this with git version 1.7.2 (after fixing my problem with running test-sqlite locally) It appears the solution is to test whether those values are nil and not set them if they're empty. However, I then hit a number of other problems with the new merge commands. So I've pushed up another PR - @jdehaan would you be able to build from this and try that? |
Ok so there's a problem with that pr which is apparent on the full tests. I think I know how to fix - and it will fix a potential problem at the same time doing so. |
Yes I can build from that pr and I need the help of @sharpSteff to make the series of tests. I hope he is available for that today a couple of minutes..I will report. Thanks a bunch for your efforts until now! |
@jdehaan yes I'm available for some tests |
I don't think this is fixed. I tried using Gitea version 1.9.2 and receive an error when attempting to merge a pull request:
I am using Gitea on CentOS 7.6 with git version 1.8.3.1 (which is the standard version of Git from the yum repos). |
@shollander I think your problem is unrelated. The original poster had a problem with git finding the repository at all; your log shows that git is having trouble finding the branch, which means that the repository was found alright. I believe that there are some improvements related to your problem in 1.9.3. Try upgrading to it. |
@guillep2k I think you are right. I just tried version Gitea version 1.9.4 and the issue I was having appears to have been fixed. Thanks! |
1.9.0+3-g6d441de
1.11.5
2.7.4
LXC container on ubuntu 16.04 LTS
[x]
):Description
Whitelist-Push and MergePullrequest does not work when Branch-Protection is enabled:
Merging Pullrequests returns 500 Error
With Gitea 1.8.3+2-g11f6ed4 everything works just fine.
Screenshots
The text was updated successfully, but these errors were encountered: