Commit 60fb872c authored by David Turner's avatar David Turner Committed by Nick Thomas

add GL_USERNAME

parent 3aef5f9a
......@@ -80,6 +80,10 @@ type Response struct {
// GL_ID is an environment variable used by gitlab-shell hooks during 'git
// push' and 'git pull'
GL_ID string
// GL_USERNAME holds gitlab username of the user who is taking the action causing hooks to be invoked
GL_USERNAME string
// GL_REPOSITORY is an environment variable used by gitlab-shell hooks during
// 'git push' and 'git pull'
GL_REPOSITORY string
......
......@@ -74,7 +74,7 @@ func newArchiveReader(ctx context.Context, repoPath string, format ArchiveFormat
a = &archiveReader{}
compressCmd, formatArg := parseArchiveFormat(format)
archiveCmd := gitCommand("", "", "git", "--git-dir="+repoPath, "archive", "--format="+formatArg, "--prefix="+archivePrefix+"/", commitId)
archiveCmd := gitCommandApi(nil, "git", "--git-dir="+repoPath, "archive", "--format="+formatArg, "--prefix="+archivePrefix+"/", commitId)
var archiveStdout io.ReadCloser
archiveStdout, err = archiveCmd.StdoutPipe()
......
......@@ -52,13 +52,13 @@ func handleSendBlobWithGitaly(w http.ResponseWriter, r *http.Request, params *bl
func handleSendBlobLocally(w http.ResponseWriter, r *http.Request, params *blobParams) {
log.Printf("SendBlob: sending %q for %q", params.BlobId, r.URL.Path)
sizeOutput, err := gitCommand("", "", "git", "--git-dir="+params.RepoPath, "cat-file", "-s", params.BlobId).Output()
sizeOutput, err := gitCommandApi(nil, "git", "--git-dir="+params.RepoPath, "cat-file", "-s", params.BlobId).Output()
if err != nil {
helper.Fail500(w, r, fmt.Errorf("SendBlob: get blob size: %v", err))
return
}
gitShowCmd := gitCommand("", "", "git", "--git-dir="+params.RepoPath, "cat-file", "blob", params.BlobId)
gitShowCmd := gitCommandApi(nil, "git", "--git-dir="+params.RepoPath, "cat-file", "blob", params.BlobId)
stdout, err := gitShowCmd.StdoutPipe()
if err != nil {
helper.Fail500(w, r, fmt.Errorf("SendBlob: git cat-file stdout: %v", err))
......
......@@ -2,6 +2,7 @@ package git
import (
"fmt"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/api"
"os"
"os/exec"
"syscall"
......@@ -10,7 +11,7 @@ import (
var execCommand = exec.Command
// Git subprocess helpers
func gitCommand(glId string, glRepository string, name string, args ...string) *exec.Cmd {
func gitCommandApi(a *api.Response, name string, args ...string) *exec.Cmd {
cmd := execCommand(name, args...)
// Start the command in its own process group (nice for signalling)
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
......@@ -19,12 +20,14 @@ func gitCommand(glId string, glRepository string, name string, args ...string) *
fmt.Sprintf("HOME=%s", os.Getenv("HOME")),
fmt.Sprintf("PATH=%s", os.Getenv("PATH")),
fmt.Sprintf("LD_LIBRARY_PATH=%s", os.Getenv("LD_LIBRARY_PATH")),
fmt.Sprintf("GL_ID=%s", glId),
fmt.Sprintf("GL_PROTOCOL=http"),
}
if glRepository != "" {
cmd.Env = append(cmd.Env, fmt.Sprintf("GL_REPOSITORY=%s", glRepository))
if a != nil {
cmd.Env = append(cmd.Env, fmt.Sprintf("GL_ID=%s", a.GL_ID))
cmd.Env = append(cmd.Env, fmt.Sprintf("GL_USERNAME=%s", a.GL_USERNAME))
if a.GL_REPOSITORY != "" {
cmd.Env = append(cmd.Env, fmt.Sprintf("GL_REPOSITORY=%s", a.GL_REPOSITORY))
}
}
// If we don't do something with cmd.Stderr, Git errors will be lost
cmd.Stderr = os.Stderr
......
......@@ -28,7 +28,7 @@ func (d *diff) Inject(w http.ResponseWriter, r *http.Request, sendData string) {
log.Printf("SendDiff: sending diff between %q and %q for %q", params.ShaFrom, params.ShaTo, r.URL.Path)
gitDiffCmd := gitCommand("", "", "git", "--git-dir="+params.RepoPath, "diff", params.ShaFrom, params.ShaTo)
gitDiffCmd := gitCommandApi(nil, "git", "--git-dir="+params.RepoPath, "diff", params.ShaFrom, params.ShaTo)
stdout, err := gitDiffCmd.StdoutPipe()
if err != nil {
helper.Fail500(w, r, fmt.Errorf("SendDiff: create stdout pipe: %v", err))
......
......@@ -29,7 +29,7 @@ func (p *patch) Inject(w http.ResponseWriter, r *http.Request, sendData string)
log.Printf("SendPatch: sending patch between %q and %q for %q", params.ShaFrom, params.ShaTo, r.URL.Path)
gitRange := fmt.Sprintf("%s..%s", params.ShaFrom, params.ShaTo)
gitPatchCmd := gitCommand("", "", "git", "--git-dir="+params.RepoPath, "format-patch", gitRange, "--stdout")
gitPatchCmd := gitCommandApi(nil, "git", "--git-dir="+params.RepoPath, "format-patch", gitRange, "--stdout")
stdout, err := gitPatchCmd.StdoutPipe()
if err != nil {
......
......@@ -79,7 +79,7 @@ func startGitCommand(a *api.Response, stdin io.Reader, stdout io.Writer, action
args := []string{subCommand(action), "--stateless-rpc"}
args = append(args, options...)
args = append(args, a.RepoPath)
cmd = gitCommand(a.GL_ID, a.GL_REPOSITORY, "git", args...)
cmd = gitCommandApi(a, "git", args...)
cmd.Stdin = stdin
cmd.Stdout = stdout
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment