Skip to content
This repository has been archived by the owner on Sep 9, 2020. It is now read-only.

Commit

Permalink
gps: use commandContext
Browse files Browse the repository at this point in the history
  • Loading branch information
tamird committed Sep 18, 2017
1 parent a374f1c commit 7d388fa
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
4 changes: 4 additions & 0 deletions internal/gps/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ func (c cmd) Args() []string {
func (c cmd) SetDir(dir string) {
c.Cmd.Dir = dir
}

func (c cmd) SetEnv(env []string) {
c.Cmd.Env = env
}
33 changes: 16 additions & 17 deletions internal/gps/vcs_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"context"
"fmt"
"os"
"os/exec"
"path/filepath"
"strings"

Expand Down Expand Up @@ -142,8 +141,8 @@ func (s *gitSource) exportRevisionTo(ctx context.Context, rev Revision, to strin
defer fs.RenameWithFallback(bak, idx)

{
cmd := exec.CommandContext(ctx, "git", "read-tree", rev.String())
cmd.Dir = r.LocalPath()
cmd := commandContext(ctx, "git", "read-tree", rev.String())
cmd.SetDir(r.LocalPath())
if out, err := cmd.CombinedOutput(); err != nil {
return errors.Wrap(err, string(out))
}
Expand All @@ -161,8 +160,8 @@ func (s *gitSource) exportRevisionTo(ctx context.Context, rev Revision, to strin
// down, the sparse checkout controls, as well as restore the original
// index and HEAD.
{
cmd := exec.CommandContext(ctx, "git", "checkout-index", "-a", "--prefix="+to)
cmd.Dir = r.LocalPath()
cmd := commandContext(ctx, "git", "checkout-index", "-a", "--prefix="+to)
cmd.SetDir(r.LocalPath())
if out, err := cmd.CombinedOutput(); err != nil {
return errors.Wrap(err, string(out))
}
Expand All @@ -174,9 +173,9 @@ func (s *gitSource) exportRevisionTo(ctx context.Context, rev Revision, to strin
func (s *gitSource) listVersions(ctx context.Context) (vlist []PairedVersion, err error) {
r := s.repo

cmd := exec.CommandContext(ctx, "git", "ls-remote", r.Remote())
cmd := commandContext(ctx, "git", "ls-remote", r.Remote())
// Ensure no prompting for PWs
cmd.Env = append([]string{"GIT_ASKPASS=", "GIT_TERMINAL_PROMPT=0"}, os.Environ()...)
cmd.SetEnv(append([]string{"GIT_ASKPASS=", "GIT_TERMINAL_PROMPT=0"}, os.Environ()...))
out, err := cmd.CombinedOutput()
if err != nil {
return nil, errors.Wrap(err, string(out))
Expand Down Expand Up @@ -396,17 +395,17 @@ func (s *bzrSource) listVersions(ctx context.Context) ([]PairedVersion, error) {
}

// Now, list all the tags
tagsCmd := exec.CommandContext(ctx, "bzr", "tags", "--show-ids", "-v")
tagsCmd.Dir = r.LocalPath()
tagsCmd := commandContext(ctx, "bzr", "tags", "--show-ids", "-v")
tagsCmd.SetDir(r.LocalPath())
out, err := tagsCmd.CombinedOutput()
if err != nil {
return nil, errors.Wrap(err, string(out))
}

all := bytes.Split(bytes.TrimSpace(out), []byte("\n"))

viCmd := exec.CommandContext(ctx, "bzr", "version-info", "--custom", "--template={revision_id}", "--revision=branch:.")
viCmd.Dir = r.LocalPath()
viCmd := commandContext(ctx, "bzr", "version-info", "--custom", "--template={revision_id}", "--revision=branch:.")
viCmd.SetDir(r.LocalPath())
branchrev, err := viCmd.CombinedOutput()
if err != nil {
return nil, errors.Wrap(err, string(branchrev))
Expand Down Expand Up @@ -478,8 +477,8 @@ func (s *hgSource) listVersions(ctx context.Context) ([]PairedVersion, error) {
}

// Now, list all the tags
tagsCmd := exec.CommandContext(ctx, "hg", "tags", "--debug", "--verbose")
tagsCmd.Dir = r.LocalPath()
tagsCmd := commandContext(ctx, "hg", "tags", "--debug", "--verbose")
tagsCmd.SetDir(r.LocalPath())
out, err := tagsCmd.CombinedOutput()
if err != nil {
return nil, errors.Wrap(err, string(out))
Expand Down Expand Up @@ -514,8 +513,8 @@ func (s *hgSource) listVersions(ctx context.Context) ([]PairedVersion, error) {
// bookmarks next, because the presence of the magic @ bookmark has to
// determine how we handle the branches
var magicAt bool
bookmarksCmd := exec.CommandContext(ctx, "hg", "bookmarks", "--debug")
bookmarksCmd.Dir = r.LocalPath()
bookmarksCmd := commandContext(ctx, "hg", "bookmarks", "--debug")
bookmarksCmd.SetDir(r.LocalPath())
out, err = bookmarksCmd.CombinedOutput()
if err != nil {
// better nothing than partial and misleading
Expand Down Expand Up @@ -549,8 +548,8 @@ func (s *hgSource) listVersions(ctx context.Context) ([]PairedVersion, error) {
}
}

cmd := exec.CommandContext(ctx, "hg", "branches", "-c", "--debug")
cmd.Dir = r.LocalPath()
cmd := commandContext(ctx, "hg", "branches", "-c", "--debug")
cmd.SetDir(r.LocalPath())
out, err = cmd.CombinedOutput()
if err != nil {
// better nothing than partial and misleading
Expand Down

0 comments on commit 7d388fa

Please sign in to comment.