Attempt to fix hook problem (#7854)
This commit is contained in:
parent
7eed11e5e9
commit
def84840db
3 changed files with 18 additions and 6 deletions
|
@ -96,6 +96,7 @@ func runHookPreReceive(c *cli.Context) error {
|
||||||
UserID: userID,
|
UserID: userID,
|
||||||
GitAlternativeObjectDirectories: os.Getenv(private.GitAlternativeObjectDirectories),
|
GitAlternativeObjectDirectories: os.Getenv(private.GitAlternativeObjectDirectories),
|
||||||
GitObjectDirectory: os.Getenv(private.GitObjectDirectory),
|
GitObjectDirectory: os.Getenv(private.GitObjectDirectory),
|
||||||
|
GitQuarantinePath: os.Getenv(private.GitQuarantinePath),
|
||||||
ProtectedBranchID: prID,
|
ProtectedBranchID: prID,
|
||||||
})
|
})
|
||||||
switch statusCode {
|
switch statusCode {
|
||||||
|
|
|
@ -29,12 +29,13 @@ type HookOptions struct {
|
||||||
UserName string
|
UserName string
|
||||||
GitObjectDirectory string
|
GitObjectDirectory string
|
||||||
GitAlternativeObjectDirectories string
|
GitAlternativeObjectDirectories string
|
||||||
|
GitQuarantinePath string
|
||||||
ProtectedBranchID int64
|
ProtectedBranchID int64
|
||||||
}
|
}
|
||||||
|
|
||||||
// HookPreReceive check whether the provided commits are allowed
|
// HookPreReceive check whether the provided commits are allowed
|
||||||
func HookPreReceive(ownerName, repoName string, opts HookOptions) (int, string) {
|
func HookPreReceive(ownerName, repoName string, opts HookOptions) (int, string) {
|
||||||
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",
|
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",
|
||||||
url.PathEscape(ownerName),
|
url.PathEscape(ownerName),
|
||||||
url.PathEscape(repoName),
|
url.PathEscape(repoName),
|
||||||
url.QueryEscape(opts.OldCommitID),
|
url.QueryEscape(opts.OldCommitID),
|
||||||
|
@ -43,6 +44,7 @@ func HookPreReceive(ownerName, repoName string, opts HookOptions) (int, string)
|
||||||
opts.UserID,
|
opts.UserID,
|
||||||
url.QueryEscape(opts.GitObjectDirectory),
|
url.QueryEscape(opts.GitObjectDirectory),
|
||||||
url.QueryEscape(opts.GitAlternativeObjectDirectories),
|
url.QueryEscape(opts.GitAlternativeObjectDirectories),
|
||||||
|
url.QueryEscape(opts.GitQuarantinePath),
|
||||||
opts.ProtectedBranchID,
|
opts.ProtectedBranchID,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,7 @@ func HookPreReceive(ctx *macaron.Context) {
|
||||||
userID := ctx.QueryInt64("userID")
|
userID := ctx.QueryInt64("userID")
|
||||||
gitObjectDirectory := ctx.QueryTrim("gitObjectDirectory")
|
gitObjectDirectory := ctx.QueryTrim("gitObjectDirectory")
|
||||||
gitAlternativeObjectDirectories := ctx.QueryTrim("gitAlternativeObjectDirectories")
|
gitAlternativeObjectDirectories := ctx.QueryTrim("gitAlternativeObjectDirectories")
|
||||||
|
gitQuarantinePath := ctx.QueryTrim("gitQuarantinePath")
|
||||||
prID := ctx.QueryInt64("prID")
|
prID := ctx.QueryInt64("prID")
|
||||||
|
|
||||||
branchName := strings.TrimPrefix(refFullName, git.BranchPrefix)
|
branchName := strings.TrimPrefix(refFullName, git.BranchPrefix)
|
||||||
|
@ -63,11 +64,19 @@ func HookPreReceive(ctx *macaron.Context) {
|
||||||
|
|
||||||
// detect force push
|
// detect force push
|
||||||
if git.EmptySHA != oldCommitID {
|
if git.EmptySHA != oldCommitID {
|
||||||
env := append(os.Environ(),
|
env := os.Environ()
|
||||||
private.GitAlternativeObjectDirectories+"="+gitAlternativeObjectDirectories,
|
if gitAlternativeObjectDirectories != "" {
|
||||||
private.GitObjectDirectory+"="+gitObjectDirectory,
|
env = append(env,
|
||||||
private.GitQuarantinePath+"="+gitObjectDirectory,
|
private.GitAlternativeObjectDirectories+"="+gitAlternativeObjectDirectories)
|
||||||
)
|
}
|
||||||
|
if gitObjectDirectory != "" {
|
||||||
|
env = append(env,
|
||||||
|
private.GitObjectDirectory+"="+gitObjectDirectory)
|
||||||
|
}
|
||||||
|
if gitQuarantinePath != "" {
|
||||||
|
env = append(env,
|
||||||
|
private.GitQuarantinePath+"="+gitQuarantinePath)
|
||||||
|
}
|
||||||
|
|
||||||
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).RunInDirWithEnv(repo.RepoPath(), env)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in a new issue