Skip to content

Commit def8484

Browse files
zeripathlafriks
authored andcommitted
Attempt to fix hook problem (#7854)
1 parent 7eed11e commit def8484

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

cmd/hook.go

+1
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ func runHookPreReceive(c *cli.Context) error {
9696
UserID: userID,
9797
GitAlternativeObjectDirectories: os.Getenv(private.GitAlternativeObjectDirectories),
9898
GitObjectDirectory: os.Getenv(private.GitObjectDirectory),
99+
GitQuarantinePath: os.Getenv(private.GitQuarantinePath),
99100
ProtectedBranchID: prID,
100101
})
101102
switch statusCode {

modules/private/hook.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,13 @@ type HookOptions struct {
2929
UserName string
3030
GitObjectDirectory string
3131
GitAlternativeObjectDirectories string
32+
GitQuarantinePath string
3233
ProtectedBranchID int64
3334
}
3435

3536
// HookPreReceive check whether the provided commits are allowed
3637
func HookPreReceive(ownerName, repoName string, opts HookOptions) (int, string) {
37-
reqURL := setting.LocalURL + fmt.Sprintf("api/internal/hook/pre-receive/%s/%s?old=%s&new=%s&ref=%s&userID=%d&gitObjectDirectory=%s&gitAlternativeObjectDirectories=%s&prID=%d",
38+
reqURL := setting.LocalURL + fmt.Sprintf("api/internal/hook/pre-receive/%s/%s?old=%s&new=%s&ref=%s&userID=%d&gitObjectDirectory=%s&gitAlternativeObjectDirectories=%s&gitQuarantinePath=%s&prID=%d",
3839
url.PathEscape(ownerName),
3940
url.PathEscape(repoName),
4041
url.QueryEscape(opts.OldCommitID),
@@ -43,6 +44,7 @@ func HookPreReceive(ownerName, repoName string, opts HookOptions) (int, string)
4344
opts.UserID,
4445
url.QueryEscape(opts.GitObjectDirectory),
4546
url.QueryEscape(opts.GitAlternativeObjectDirectories),
47+
url.QueryEscape(opts.GitQuarantinePath),
4648
opts.ProtectedBranchID,
4749
)
4850

routers/private/hook.go

+14-5
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ func HookPreReceive(ctx *macaron.Context) {
3131
userID := ctx.QueryInt64("userID")
3232
gitObjectDirectory := ctx.QueryTrim("gitObjectDirectory")
3333
gitAlternativeObjectDirectories := ctx.QueryTrim("gitAlternativeObjectDirectories")
34+
gitQuarantinePath := ctx.QueryTrim("gitQuarantinePath")
3435
prID := ctx.QueryInt64("prID")
3536

3637
branchName := strings.TrimPrefix(refFullName, git.BranchPrefix)
@@ -63,11 +64,19 @@ func HookPreReceive(ctx *macaron.Context) {
6364

6465
// detect force push
6566
if git.EmptySHA != oldCommitID {
66-
env := append(os.Environ(),
67-
private.GitAlternativeObjectDirectories+"="+gitAlternativeObjectDirectories,
68-
private.GitObjectDirectory+"="+gitObjectDirectory,
69-
private.GitQuarantinePath+"="+gitObjectDirectory,
70-
)
67+
env := os.Environ()
68+
if gitAlternativeObjectDirectories != "" {
69+
env = append(env,
70+
private.GitAlternativeObjectDirectories+"="+gitAlternativeObjectDirectories)
71+
}
72+
if gitObjectDirectory != "" {
73+
env = append(env,
74+
private.GitObjectDirectory+"="+gitObjectDirectory)
75+
}
76+
if gitQuarantinePath != "" {
77+
env = append(env,
78+
private.GitQuarantinePath+"="+gitQuarantinePath)
79+
}
7180

7281
output, err := git.NewCommand("rev-list", "--max-count=1", oldCommitID, "^"+newCommitID).RunInDirWithEnv(repo.RepoPath(), env)
7382
if err != nil {

0 commit comments

Comments
 (0)