Skip to content

Commit

Permalink
Merge pull request #41 from nulab/issue-40/add-env-var-field-to-ctx
Browse files Browse the repository at this point in the history
add environment variable field to context (#40)
  • Loading branch information
vvatanabe authored Sep 22, 2018
2 parents 3f35dbe + d968a05 commit 7563f67
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 12 deletions.
1 change: 1 addition & 0 deletions addon/handler/archive/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func (ghx *gitHTTPXfer) Archive(ctx githttpxfer.Context) {

args := []string{"archive", "--format=" + format, "--prefix=" + repoName + "-" + tree + "/", tree}
cmd := ghx.Git.GitCommand(repoPath, args...)
cmd.Env = ctx.Env()

stdout, err := cmd.StdoutPipe()
if err != nil {
Expand Down
11 changes: 11 additions & 0 deletions githttpxfer/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@ type (
SetRepoPath(repoPath string)
FilePath() string
SetFilePath(filePath string)
Env() []string
SetEnv(env []string)
}

context struct {
response *Response
request *http.Request
repoPath string
filePath string
env []string
}
)

Expand Down Expand Up @@ -59,3 +62,11 @@ func (c *context) FilePath() string {
func (c *context) SetFilePath(filePath string) {
c.filePath = filePath
}

func (c *context) Env() []string {
return c.env
}

func (c *context) SetEnv(env []string) {
c.env = env
}
10 changes: 0 additions & 10 deletions githttpxfer/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,6 @@ func (g *git) Exists(repoPath string) bool {
return true
}

func (g *git) GetInfoRefs(repoPath, serviceName string) ([]byte, error) {
args := []string{serviceName, "--stateless-rpc", "--advertise-refs", "."}
return g.GitCommand(repoPath, args...).Output()
}

func (g *git) UpdateServerInfo(repoPath string) ([]byte, error) {
args := []string{"update-server-info"}
return g.GitCommand(repoPath, args...).Output()
}

func (g *git) GitCommand(repoPath string, args ...string) *exec.Cmd {
command := exec.Command(g.binPath, args...)
command.Dir = g.GetAbsolutePath(repoPath)
Expand Down
11 changes: 9 additions & 2 deletions githttpxfer/githttpxfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ func (ghx *GitHTTPXfer) serviceRPC(ctx Context, rpc string) {

args := []string{rpc, "--stateless-rpc", "."}
cmd := ghx.Git.GitCommand(repoPath, args...)
cmd.Env = ctx.Env()

stdin, err := cmd.StdinPipe()
if err != nil {
Expand Down Expand Up @@ -325,15 +326,21 @@ func (ghx *GitHTTPXfer) getInfoRefs(ctx Context) {

serviceName := getServiceType(req)
if !ghx.Git.HasAccess(req, serviceName, false) {
ghx.Git.UpdateServerInfo(repoPath)
args := []string{"update-server-info"}
cmd := ghx.Git.GitCommand(repoPath, args...)
cmd.Env = ctx.Env()
cmd.Output()
res.HdrNocache()
if err := ghx.sendFile("text/plain; charset=utf-8", ctx); err != nil {
RenderNotFound(res.Writer)
return
}
}

refs, err := ghx.Git.GetInfoRefs(repoPath, serviceName)
args := []string{serviceName, "--stateless-rpc", "--advertise-refs", "."}
cmd := ghx.Git.GitCommand(repoPath, args...)
cmd.Env = ctx.Env()
refs, err := cmd.Output()
if err != nil {
RenderNotFound(ctx.Response().Writer)
return
Expand Down

0 comments on commit 7563f67

Please sign in to comment.