浏览代码

hook: fix can’t be executed while run as service on Windows (#4207)

Unknwon 8 年之前
父节点
当前提交
e08161a302

+ 5 - 1
cmd/hook.go

@@ -117,7 +117,8 @@ func runHookPreReceive(c *cli.Context) error {
 		}
 
 		// Check force push
-		output, err := git.NewCommand("rev-list", oldCommitID, "^"+newCommitID).Run()
+		output, err := git.NewCommand("rev-list", oldCommitID, "^"+newCommitID).
+			RunInDir(models.RepoPath(os.Getenv(http.ENV_REPO_OWNER_NAME), os.Getenv(http.ENV_REPO_NAME)))
 		if err != nil {
 			fail("Internal error", "Fail to detect force push: %v", err)
 		} else if len(output) > 0 {
@@ -131,6 +132,7 @@ func runHookPreReceive(c *cli.Context) error {
 	}
 
 	hookCmd := exec.Command(customHooksPath)
+	hookCmd.Dir = models.RepoPath(os.Getenv(http.ENV_REPO_OWNER_NAME), os.Getenv(http.ENV_REPO_NAME))
 	hookCmd.Stdout = os.Stdout
 	hookCmd.Stdin = buf
 	hookCmd.Stderr = os.Stderr
@@ -159,6 +161,7 @@ func runHookUpdate(c *cli.Context) error {
 	}
 
 	hookCmd := exec.Command(customHooksPath, args...)
+	hookCmd.Dir = models.RepoPath(os.Getenv(http.ENV_REPO_OWNER_NAME), os.Getenv(http.ENV_REPO_NAME))
 	hookCmd.Stdout = os.Stdout
 	hookCmd.Stdin = os.Stdin
 	hookCmd.Stderr = os.Stderr
@@ -231,6 +234,7 @@ func runHookPostReceive(c *cli.Context) error {
 	}
 
 	hookCmd := exec.Command(customHooksPath)
+	hookCmd.Dir = models.RepoPath(os.Getenv(http.ENV_REPO_OWNER_NAME), os.Getenv(http.ENV_REPO_NAME))
 	hookCmd.Stdout = os.Stdout
 	hookCmd.Stdin = buf
 	hookCmd.Stderr = os.Stderr

+ 1 - 1
gogs.go

@@ -16,7 +16,7 @@ import (
 	"github.com/gogits/gogs/modules/setting"
 )
 
-const APP_VER = "0.10.2.0228"
+const APP_VER = "0.10.3.0228"
 
 func init() {
 	setting.AppVer = APP_VER

+ 1 - 1
templates/.VERSION

@@ -1 +1 @@
-0.10.2.0228
+0.10.3.0228

+ 0 - 0
vendor/github.com/kardianos/minwinsvc/LICENSE → vendor/github.com/gogits/minwinsvc/LICENSE


+ 0 - 0
vendor/github.com/kardianos/minwinsvc/README.md → vendor/github.com/gogits/minwinsvc/README.md


+ 0 - 0
vendor/github.com/kardianos/minwinsvc/minwinsvc.go → vendor/github.com/gogits/minwinsvc/minwinsvc.go


+ 0 - 0
vendor/github.com/kardianos/minwinsvc/svc_other.go → vendor/github.com/gogits/minwinsvc/svc_other.go


+ 3 - 1
vendor/github.com/kardianos/minwinsvc/svc_windows.go → vendor/github.com/gogits/minwinsvc/svc_windows.go

@@ -23,7 +23,9 @@ func init() {
 	if err != nil {
 		panic(err)
 	}
-	if interactive {
+	// While run as Windows service, it is not an interactive session,
+	// but we don't want hook execute to be treated as service, e.g. gogs.exe hook pre-receive.
+	if interactive || len(os.Getenv("SSH_ORIGINAL_COMMAND")) > 0 {
 		return
 	}
 	go func() {

+ 6 - 6
vendor/vendor.json

@@ -176,6 +176,12 @@
 			"revision": "cd1abbd55d09b793672732a7a1dfdaa12a40dfd0",
 			"revisionTime": "2016-11-20T02:51:54Z"
 		},
+		{
+			"checksumSHA1": "cccKtXG5TiCiCT9JA85slbJokfw=",
+			"path": "github.com/gogits/minwinsvc",
+			"revision": "95be6356811a6fbd4c2981713236971a3ccbb33a",
+			"revisionTime": "2017-03-01T03:54:11Z"
+		},
 		{
 			"checksumSHA1": "MLO0PyrK2MUO6A7Z9PxWuu43C/A=",
 			"path": "github.com/issue9/identicon",
@@ -194,12 +200,6 @@
 			"revision": "8ddce2a84170772b95dd5d576c48d517b22cac63",
 			"revisionTime": "2016-01-05T22:08:40Z"
 		},
-		{
-			"checksumSHA1": "/dBJ2h8Jo359deiC5GQ8ZYzX8M8=",
-			"path": "github.com/kardianos/minwinsvc",
-			"revision": "cad6b2b879b0970e4245a20ebf1a81a756e2bb70",
-			"revisionTime": "2015-11-22T16:33:09Z"
-		},
 		{
 			"checksumSHA1": "vfzz7zTL9TZLpFO7NC1H6/Du3+s=",
 			"path": "github.com/klauspost/compress/flate",