mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Do not try to shallow git history when the protocol doesn't allow it.
This only happens with the old git http dumb protocol, but that's what we use in our integration tests.
We check the Content-Type header advertised in http requests to make sure the http transport is the git smart transport:
See this commit as a reference:
4656bf47fc
Signed-off-by: David Calavera <david.calavera@gmail.com>
This commit is contained in:
parent
36fbf4b864
commit
9fb7204a41
1 changed files with 22 additions and 1 deletions
|
@ -5,6 +5,7 @@ import (
|
|||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
|
@ -114,7 +115,9 @@ func Build(d *daemon.Daemon, buildConfig *Config) error {
|
|||
}
|
||||
defer os.RemoveAll(root)
|
||||
|
||||
if output, err := exec.Command("git", "clone", "--depth", "1", "--recursive", buildConfig.RemoteURL, root).CombinedOutput(); err != nil {
|
||||
clone := cloneArgs(buildConfig.RemoteURL, root)
|
||||
|
||||
if output, err := exec.Command("git", clone...).CombinedOutput(); err != nil {
|
||||
return fmt.Errorf("Error trying to use git: %s (%s)", err, output)
|
||||
}
|
||||
|
||||
|
@ -239,3 +242,21 @@ func Commit(d *daemon.Daemon, name string, c *daemon.ContainerCommitConfig) (str
|
|||
|
||||
return img.ID, nil
|
||||
}
|
||||
|
||||
func cloneArgs(remoteURL, root string) []string {
|
||||
args := []string{"clone", "--recursive"}
|
||||
shallow := true
|
||||
|
||||
if strings.HasPrefix(remoteURL, "http") {
|
||||
res, err := http.Head(fmt.Sprintf("%s/info/refs?service=git-upload-pack", remoteURL))
|
||||
if err != nil || res.Header.Get("Content-Type") != "application/x-git-upload-pack-advertisement" {
|
||||
shallow = false
|
||||
}
|
||||
}
|
||||
|
||||
if shallow {
|
||||
args = append(args, "--depth", "1")
|
||||
}
|
||||
|
||||
return append(args, remoteURL, root)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue