Skip to content

Commit

Permalink
Merge pull request moby#19385 from runcom/better-git-error
Browse files Browse the repository at this point in the history
api: client: build: do not fall through if git isn't installed
  • Loading branch information
thaJeztah committed Jan 19, 2016
2 parents 30e42a2 + 167cc42 commit 4b63689
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
8 changes: 4 additions & 4 deletions api/client/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,6 @@ func (cli *DockerCli) CmdBuild(args ...string) error {
err error
)

_, err = exec.LookPath("git")
hasGit := err == nil

specifiedContext := cmd.Arg(0)

var (
Expand All @@ -104,7 +101,7 @@ func (cli *DockerCli) CmdBuild(args ...string) error {
switch {
case specifiedContext == "-":
context, relDockerfile, err = getContextFromReader(cli.in, *dockerfileName)
case urlutil.IsGitURL(specifiedContext) && hasGit:
case urlutil.IsGitURL(specifiedContext):
tempDir, relDockerfile, err = getContextFromGitURL(specifiedContext, *dockerfileName)
case urlutil.IsURL(specifiedContext):
context, relDockerfile, err = getContextFromURL(progBuff, specifiedContext, *dockerfileName)
Expand Down Expand Up @@ -503,6 +500,9 @@ func getContextFromReader(r io.ReadCloser, dockerfileName string) (out io.ReadCl
// path of the dockerfile in that context directory, and a non-nil error on
// success.
func getContextFromGitURL(gitURL, dockerfileName string) (absContextDir, relDockerfile string, err error) {
if _, err := exec.LookPath("git"); err != nil {
return "", "", fmt.Errorf("unable to find 'git': %v", err)
}
if absContextDir, err = gitutils.Clone(gitURL); err != nil {
return "", "", fmt.Errorf("unable to 'git clone' to temporary context directory: %v", err)
}
Expand Down
15 changes: 15 additions & 0 deletions integration-cli/docker_cli_build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6632,3 +6632,18 @@ func (s *DockerSuite) TestBuildCacheRootSource(c *check.C) {

c.Assert(out, checker.Not(checker.Contains), "Using cache")
}

// #19375
func (s *DockerSuite) TestBuildFailsGitNotCallable(c *check.C) {
cmd := exec.Command(dockerBinary, "build", "github.com/docker/v1.10-migrator.git")
cmd.Env = append(cmd.Env, "PATH=")
out, _, err := runCommandWithOutput(cmd)
c.Assert(err, checker.NotNil)
c.Assert(out, checker.Contains, "unable to prepare context: unable to find 'git': ")

cmd = exec.Command(dockerBinary, "build", "https://github.com/docker/v1.10-migrator.git")
cmd.Env = append(cmd.Env, "PATH=")
out, _, err = runCommandWithOutput(cmd)
c.Assert(err, checker.NotNil)
c.Assert(out, checker.Contains, "unable to prepare context: unable to find 'git': ")
}

0 comments on commit 4b63689

Please sign in to comment.