2018-02-05 16:05:59 -05:00
|
|
|
package git // import "github.com/docker/docker/builder/remotecontext/git"
|
2015-04-21 17:24:29 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2015-04-24 18:12:45 -04:00
|
|
|
"io/ioutil"
|
2015-04-21 17:24:29 -04:00
|
|
|
"net/http"
|
|
|
|
"net/http/httptest"
|
|
|
|
"net/url"
|
2015-04-24 18:12:45 -04:00
|
|
|
"os"
|
2017-12-07 16:44:08 -05:00
|
|
|
"os/exec"
|
2015-04-24 18:12:45 -04:00
|
|
|
"path/filepath"
|
2016-02-11 21:19:17 -05:00
|
|
|
"runtime"
|
2016-05-31 22:36:25 -04:00
|
|
|
"strings"
|
2015-04-21 17:24:29 -04:00
|
|
|
"testing"
|
2017-06-01 17:15:13 -04:00
|
|
|
|
2017-12-22 16:30:49 -05:00
|
|
|
"github.com/google/go-cmp/cmp"
|
2018-03-13 15:28:34 -04:00
|
|
|
"github.com/gotestyourself/gotestyourself/assert"
|
|
|
|
is "github.com/gotestyourself/gotestyourself/assert/cmp"
|
2015-04-21 17:24:29 -04:00
|
|
|
)
|
|
|
|
|
Fix handling of remote "git@" notation
`docker build` accepts remote repositories
using either the `git://` notation, or `git@`.
Docker attempted to parse both as an URL, however,
`git@` is not an URL, but an argument to `git clone`.
Go 1.7 silently ignored this, and managed to
extract the needed information from these
remotes, however, Go 1.8 does a more strict
validation, and invalidated these.
This patch adds a different path for `git@` remotes,
to prevent them from being handled as URL (and
invalidated).
A test is also added, because there were no
tests for handling of `git@` remotes.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2017-06-15 10:29:18 -04:00
|
|
|
func TestParseRemoteURL(t *testing.T) {
|
|
|
|
dir, err := parseRemoteURL("git://github.com/user/repo.git")
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2017-12-22 16:30:49 -05:00
|
|
|
assert.Check(t, is.DeepEqual(gitRepo{"git://github.com/user/repo.git", "master", ""}, dir, cmpGitRepoOpt))
|
Fix handling of remote "git@" notation
`docker build` accepts remote repositories
using either the `git://` notation, or `git@`.
Docker attempted to parse both as an URL, however,
`git@` is not an URL, but an argument to `git clone`.
Go 1.7 silently ignored this, and managed to
extract the needed information from these
remotes, however, Go 1.8 does a more strict
validation, and invalidated these.
This patch adds a different path for `git@` remotes,
to prevent them from being handled as URL (and
invalidated).
A test is also added, because there were no
tests for handling of `git@` remotes.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2017-06-15 10:29:18 -04:00
|
|
|
|
|
|
|
dir, err = parseRemoteURL("git://github.com/user/repo.git#mybranch:mydir/mysubdir/")
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2017-12-22 16:30:49 -05:00
|
|
|
assert.Check(t, is.DeepEqual(gitRepo{"git://github.com/user/repo.git", "mybranch", "mydir/mysubdir/"}, dir, cmpGitRepoOpt))
|
Fix handling of remote "git@" notation
`docker build` accepts remote repositories
using either the `git://` notation, or `git@`.
Docker attempted to parse both as an URL, however,
`git@` is not an URL, but an argument to `git clone`.
Go 1.7 silently ignored this, and managed to
extract the needed information from these
remotes, however, Go 1.8 does a more strict
validation, and invalidated these.
This patch adds a different path for `git@` remotes,
to prevent them from being handled as URL (and
invalidated).
A test is also added, because there were no
tests for handling of `git@` remotes.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2017-06-15 10:29:18 -04:00
|
|
|
|
|
|
|
dir, err = parseRemoteURL("https://github.com/user/repo.git")
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2017-12-22 16:30:49 -05:00
|
|
|
assert.Check(t, is.DeepEqual(gitRepo{"https://github.com/user/repo.git", "master", ""}, dir, cmpGitRepoOpt))
|
Fix handling of remote "git@" notation
`docker build` accepts remote repositories
using either the `git://` notation, or `git@`.
Docker attempted to parse both as an URL, however,
`git@` is not an URL, but an argument to `git clone`.
Go 1.7 silently ignored this, and managed to
extract the needed information from these
remotes, however, Go 1.8 does a more strict
validation, and invalidated these.
This patch adds a different path for `git@` remotes,
to prevent them from being handled as URL (and
invalidated).
A test is also added, because there were no
tests for handling of `git@` remotes.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2017-06-15 10:29:18 -04:00
|
|
|
|
|
|
|
dir, err = parseRemoteURL("https://github.com/user/repo.git#mybranch:mydir/mysubdir/")
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2017-12-22 16:30:49 -05:00
|
|
|
assert.Check(t, is.DeepEqual(gitRepo{"https://github.com/user/repo.git", "mybranch", "mydir/mysubdir/"}, dir, cmpGitRepoOpt))
|
Fix handling of remote "git@" notation
`docker build` accepts remote repositories
using either the `git://` notation, or `git@`.
Docker attempted to parse both as an URL, however,
`git@` is not an URL, but an argument to `git clone`.
Go 1.7 silently ignored this, and managed to
extract the needed information from these
remotes, however, Go 1.8 does a more strict
validation, and invalidated these.
This patch adds a different path for `git@` remotes,
to prevent them from being handled as URL (and
invalidated).
A test is also added, because there were no
tests for handling of `git@` remotes.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2017-06-15 10:29:18 -04:00
|
|
|
|
|
|
|
dir, err = parseRemoteURL("git@github.com:user/repo.git")
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2017-12-22 16:30:49 -05:00
|
|
|
assert.Check(t, is.DeepEqual(gitRepo{"git@github.com:user/repo.git", "master", ""}, dir, cmpGitRepoOpt))
|
Fix handling of remote "git@" notation
`docker build` accepts remote repositories
using either the `git://` notation, or `git@`.
Docker attempted to parse both as an URL, however,
`git@` is not an URL, but an argument to `git clone`.
Go 1.7 silently ignored this, and managed to
extract the needed information from these
remotes, however, Go 1.8 does a more strict
validation, and invalidated these.
This patch adds a different path for `git@` remotes,
to prevent them from being handled as URL (and
invalidated).
A test is also added, because there were no
tests for handling of `git@` remotes.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2017-06-15 10:29:18 -04:00
|
|
|
|
|
|
|
dir, err = parseRemoteURL("git@github.com:user/repo.git#mybranch:mydir/mysubdir/")
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2017-12-22 16:30:49 -05:00
|
|
|
assert.Check(t, is.DeepEqual(gitRepo{"git@github.com:user/repo.git", "mybranch", "mydir/mysubdir/"}, dir, cmpGitRepoOpt))
|
Fix handling of remote "git@" notation
`docker build` accepts remote repositories
using either the `git://` notation, or `git@`.
Docker attempted to parse both as an URL, however,
`git@` is not an URL, but an argument to `git clone`.
Go 1.7 silently ignored this, and managed to
extract the needed information from these
remotes, however, Go 1.8 does a more strict
validation, and invalidated these.
This patch adds a different path for `git@` remotes,
to prevent them from being handled as URL (and
invalidated).
A test is also added, because there were no
tests for handling of `git@` remotes.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2017-06-15 10:29:18 -04:00
|
|
|
}
|
|
|
|
|
2017-12-22 16:30:49 -05:00
|
|
|
var cmpGitRepoOpt = cmp.AllowUnexported(gitRepo{})
|
|
|
|
|
2015-04-21 17:24:29 -04:00
|
|
|
func TestCloneArgsSmartHttp(t *testing.T) {
|
|
|
|
mux := http.NewServeMux()
|
|
|
|
server := httptest.NewServer(mux)
|
|
|
|
serverURL, _ := url.Parse(server.URL)
|
|
|
|
|
|
|
|
serverURL.Path = "/repo.git"
|
|
|
|
|
|
|
|
mux.HandleFunc("/repo.git/info/refs", func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
q := r.URL.Query().Get("service")
|
|
|
|
w.Header().Set("Content-Type", fmt.Sprintf("application/x-%s-advertisement", q))
|
|
|
|
})
|
|
|
|
|
Fix handling of remote "git@" notation
`docker build` accepts remote repositories
using either the `git://` notation, or `git@`.
Docker attempted to parse both as an URL, however,
`git@` is not an URL, but an argument to `git clone`.
Go 1.7 silently ignored this, and managed to
extract the needed information from these
remotes, however, Go 1.8 does a more strict
validation, and invalidated these.
This patch adds a different path for `git@` remotes,
to prevent them from being handled as URL (and
invalidated).
A test is also added, because there were no
tests for handling of `git@` remotes.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2017-06-15 10:29:18 -04:00
|
|
|
args := fetchArgs(serverURL.String(), "master")
|
2017-12-07 16:44:08 -05:00
|
|
|
exp := []string{"fetch", "--depth", "1", "origin", "master"}
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.Check(t, is.DeepEqual(exp, args))
|
2015-04-21 17:24:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestCloneArgsDumbHttp(t *testing.T) {
|
|
|
|
mux := http.NewServeMux()
|
|
|
|
server := httptest.NewServer(mux)
|
|
|
|
serverURL, _ := url.Parse(server.URL)
|
|
|
|
|
|
|
|
serverURL.Path = "/repo.git"
|
|
|
|
|
|
|
|
mux.HandleFunc("/repo.git/info/refs", func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
w.Header().Set("Content-Type", "text/plain")
|
|
|
|
})
|
|
|
|
|
Fix handling of remote "git@" notation
`docker build` accepts remote repositories
using either the `git://` notation, or `git@`.
Docker attempted to parse both as an URL, however,
`git@` is not an URL, but an argument to `git clone`.
Go 1.7 silently ignored this, and managed to
extract the needed information from these
remotes, however, Go 1.8 does a more strict
validation, and invalidated these.
This patch adds a different path for `git@` remotes,
to prevent them from being handled as URL (and
invalidated).
A test is also added, because there were no
tests for handling of `git@` remotes.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2017-06-15 10:29:18 -04:00
|
|
|
args := fetchArgs(serverURL.String(), "master")
|
2017-12-07 16:44:08 -05:00
|
|
|
exp := []string{"fetch", "origin", "master"}
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.Check(t, is.DeepEqual(exp, args))
|
2015-04-21 17:24:29 -04:00
|
|
|
}
|
2015-04-24 18:12:45 -04:00
|
|
|
|
2015-04-21 17:24:29 -04:00
|
|
|
func TestCloneArgsGit(t *testing.T) {
|
Fix handling of remote "git@" notation
`docker build` accepts remote repositories
using either the `git://` notation, or `git@`.
Docker attempted to parse both as an URL, however,
`git@` is not an URL, but an argument to `git clone`.
Go 1.7 silently ignored this, and managed to
extract the needed information from these
remotes, however, Go 1.8 does a more strict
validation, and invalidated these.
This patch adds a different path for `git@` remotes,
to prevent them from being handled as URL (and
invalidated).
A test is also added, because there were no
tests for handling of `git@` remotes.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2017-06-15 10:29:18 -04:00
|
|
|
args := fetchArgs("git://github.com/docker/docker", "master")
|
2017-12-07 16:44:08 -05:00
|
|
|
exp := []string{"fetch", "--depth", "1", "origin", "master"}
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.Check(t, is.DeepEqual(exp, args))
|
2015-04-24 18:12:45 -04:00
|
|
|
}
|
|
|
|
|
2016-05-31 22:36:25 -04:00
|
|
|
func gitGetConfig(name string) string {
|
|
|
|
b, err := git([]string{"config", "--get", name}...)
|
|
|
|
if err != nil {
|
|
|
|
// since we are interested in empty or non empty string,
|
|
|
|
// we can safely ignore the err here.
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
return strings.TrimSpace(string(b))
|
|
|
|
}
|
|
|
|
|
2015-04-24 18:12:45 -04:00
|
|
|
func TestCheckoutGit(t *testing.T) {
|
|
|
|
root, err := ioutil.TempDir("", "docker-build-git-checkout")
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2015-04-24 18:12:45 -04:00
|
|
|
defer os.RemoveAll(root)
|
|
|
|
|
2016-05-31 22:36:25 -04:00
|
|
|
autocrlf := gitGetConfig("core.autocrlf")
|
|
|
|
if !(autocrlf == "true" || autocrlf == "false" ||
|
|
|
|
autocrlf == "input" || autocrlf == "") {
|
|
|
|
t.Logf("unknown core.autocrlf value: \"%s\"", autocrlf)
|
|
|
|
}
|
2016-02-11 21:19:17 -05:00
|
|
|
eol := "\n"
|
2016-05-31 22:36:25 -04:00
|
|
|
if autocrlf == "true" {
|
2016-02-11 21:19:17 -05:00
|
|
|
eol = "\r\n"
|
|
|
|
}
|
|
|
|
|
2015-04-24 18:12:45 -04:00
|
|
|
gitDir := filepath.Join(root, "repo")
|
|
|
|
_, err = git("init", gitDir)
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2015-04-24 18:12:45 -04:00
|
|
|
|
2017-06-01 17:15:13 -04:00
|
|
|
_, err = gitWithinDir(gitDir, "config", "user.email", "test@docker.com")
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2015-04-24 18:12:45 -04:00
|
|
|
|
2017-06-01 17:15:13 -04:00
|
|
|
_, err = gitWithinDir(gitDir, "config", "user.name", "Docker test")
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2015-04-24 18:12:45 -04:00
|
|
|
|
2017-06-01 17:15:13 -04:00
|
|
|
err = ioutil.WriteFile(filepath.Join(gitDir, "Dockerfile"), []byte("FROM scratch"), 0644)
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2015-04-24 18:12:45 -04:00
|
|
|
|
|
|
|
subDir := filepath.Join(gitDir, "subdir")
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, os.Mkdir(subDir, 0755))
|
2015-04-24 18:12:45 -04:00
|
|
|
|
2017-06-01 17:15:13 -04:00
|
|
|
err = ioutil.WriteFile(filepath.Join(subDir, "Dockerfile"), []byte("FROM scratch\nEXPOSE 5000"), 0644)
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2015-04-24 18:12:45 -04:00
|
|
|
|
2016-02-11 21:19:17 -05:00
|
|
|
if runtime.GOOS != "windows" {
|
|
|
|
if err = os.Symlink("../subdir", filepath.Join(gitDir, "parentlink")); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2015-06-01 14:41:45 -04:00
|
|
|
|
2016-02-11 21:19:17 -05:00
|
|
|
if err = os.Symlink("/subdir", filepath.Join(gitDir, "absolutelink")); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2015-06-01 14:41:45 -04:00
|
|
|
}
|
|
|
|
|
2017-06-01 17:15:13 -04:00
|
|
|
_, err = gitWithinDir(gitDir, "add", "-A")
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2015-04-24 18:12:45 -04:00
|
|
|
|
2017-06-01 17:15:13 -04:00
|
|
|
_, err = gitWithinDir(gitDir, "commit", "-am", "First commit")
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2015-04-24 18:12:45 -04:00
|
|
|
|
2017-06-01 17:15:13 -04:00
|
|
|
_, err = gitWithinDir(gitDir, "checkout", "-b", "test")
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2015-04-24 18:12:45 -04:00
|
|
|
|
2017-06-01 17:15:13 -04:00
|
|
|
err = ioutil.WriteFile(filepath.Join(gitDir, "Dockerfile"), []byte("FROM scratch\nEXPOSE 3000"), 0644)
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2015-04-24 18:12:45 -04:00
|
|
|
|
2017-06-01 17:15:13 -04:00
|
|
|
err = ioutil.WriteFile(filepath.Join(subDir, "Dockerfile"), []byte("FROM busybox\nEXPOSE 5000"), 0644)
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2015-04-24 18:12:45 -04:00
|
|
|
|
2017-06-01 17:15:13 -04:00
|
|
|
_, err = gitWithinDir(gitDir, "add", "-A")
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2015-04-24 18:12:45 -04:00
|
|
|
|
2017-06-01 17:15:13 -04:00
|
|
|
_, err = gitWithinDir(gitDir, "commit", "-am", "Branch commit")
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2015-04-24 18:12:45 -04:00
|
|
|
|
2017-06-01 17:15:13 -04:00
|
|
|
_, err = gitWithinDir(gitDir, "checkout", "master")
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2015-04-24 18:12:45 -04:00
|
|
|
|
2017-12-07 16:44:08 -05:00
|
|
|
// set up submodule
|
|
|
|
subrepoDir := filepath.Join(root, "subrepo")
|
|
|
|
_, err = git("init", subrepoDir)
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2017-12-07 16:44:08 -05:00
|
|
|
|
|
|
|
_, err = gitWithinDir(subrepoDir, "config", "user.email", "test@docker.com")
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2017-12-07 16:44:08 -05:00
|
|
|
|
|
|
|
_, err = gitWithinDir(subrepoDir, "config", "user.name", "Docker test")
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2017-12-07 16:44:08 -05:00
|
|
|
|
|
|
|
err = ioutil.WriteFile(filepath.Join(subrepoDir, "subfile"), []byte("subcontents"), 0644)
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2017-12-07 16:44:08 -05:00
|
|
|
|
|
|
|
_, err = gitWithinDir(subrepoDir, "add", "-A")
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2017-12-07 16:44:08 -05:00
|
|
|
|
|
|
|
_, err = gitWithinDir(subrepoDir, "commit", "-am", "Subrepo initial")
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2017-12-07 16:44:08 -05:00
|
|
|
|
|
|
|
cmd := exec.Command("git", "submodule", "add", subrepoDir, "sub") // this command doesn't work with --work-tree
|
|
|
|
cmd.Dir = gitDir
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, cmd.Run())
|
2017-12-07 16:44:08 -05:00
|
|
|
|
|
|
|
_, err = gitWithinDir(gitDir, "add", "-A")
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2017-12-07 16:44:08 -05:00
|
|
|
|
|
|
|
_, err = gitWithinDir(gitDir, "commit", "-am", "With submodule")
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2017-12-07 16:44:08 -05:00
|
|
|
|
2016-02-11 21:19:17 -05:00
|
|
|
type singleCase struct {
|
2017-12-07 16:44:08 -05:00
|
|
|
frag string
|
|
|
|
exp string
|
|
|
|
fail bool
|
|
|
|
submodule bool
|
2016-02-11 21:19:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
cases := []singleCase{
|
2017-12-07 16:44:08 -05:00
|
|
|
{"", "FROM scratch", false, true},
|
|
|
|
{"master", "FROM scratch", false, true},
|
|
|
|
{":subdir", "FROM scratch" + eol + "EXPOSE 5000", false, false},
|
|
|
|
{":nosubdir", "", true, false}, // missing directory error
|
|
|
|
{":Dockerfile", "", true, false}, // not a directory error
|
|
|
|
{"master:nosubdir", "", true, false},
|
|
|
|
{"master:subdir", "FROM scratch" + eol + "EXPOSE 5000", false, false},
|
|
|
|
{"master:../subdir", "", true, false},
|
|
|
|
{"test", "FROM scratch" + eol + "EXPOSE 3000", false, false},
|
|
|
|
{"test:", "FROM scratch" + eol + "EXPOSE 3000", false, false},
|
|
|
|
{"test:subdir", "FROM busybox" + eol + "EXPOSE 5000", false, false},
|
2016-02-11 21:19:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if runtime.GOOS != "windows" {
|
|
|
|
// Windows GIT (2.7.1 x64) does not support parentlink/absolutelink. Sample output below
|
|
|
|
// git --work-tree .\repo --git-dir .\repo\.git add -A
|
|
|
|
// error: readlink("absolutelink"): Function not implemented
|
|
|
|
// error: unable to index file absolutelink
|
|
|
|
// fatal: adding files failed
|
|
|
|
cases = append(cases, singleCase{frag: "master:absolutelink", exp: "FROM scratch" + eol + "EXPOSE 5000", fail: false})
|
|
|
|
cases = append(cases, singleCase{frag: "master:parentlink", exp: "FROM scratch" + eol + "EXPOSE 5000", fail: false})
|
2015-04-24 18:12:45 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, c := range cases {
|
2017-04-10 20:11:28 -04:00
|
|
|
ref, subdir := getRefAndSubdir(c.frag)
|
2017-12-07 16:44:08 -05:00
|
|
|
r, err := cloneGitRepo(gitRepo{remote: gitDir, ref: ref, subdir: subdir})
|
2015-04-24 18:12:45 -04:00
|
|
|
|
|
|
|
if c.fail {
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.Check(t, is.ErrorContains(err, ""))
|
2015-04-24 18:12:45 -04:00
|
|
|
continue
|
2017-12-08 14:51:10 -05:00
|
|
|
}
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2017-12-08 14:51:10 -05:00
|
|
|
defer os.RemoveAll(r)
|
|
|
|
if c.submodule {
|
|
|
|
b, err := ioutil.ReadFile(filepath.Join(r, "sub/subfile"))
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.Check(t, is.Equal("subcontents", string(b)))
|
2017-12-08 14:51:10 -05:00
|
|
|
} else {
|
|
|
|
_, err := os.Stat(filepath.Join(r, "sub/subfile"))
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.Assert(t, is.ErrorContains(err, ""))
|
|
|
|
assert.Assert(t, os.IsNotExist(err))
|
2015-04-24 18:12:45 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
b, err := ioutil.ReadFile(filepath.Join(r, "Dockerfile"))
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.Check(t, is.Equal(c.exp, string(b)))
|
2015-04-24 18:12:45 -04:00
|
|
|
}
|
|
|
|
}
|
2017-06-26 13:07:04 -04:00
|
|
|
|
|
|
|
func TestValidGitTransport(t *testing.T) {
|
|
|
|
gitUrls := []string{
|
|
|
|
"git://github.com/docker/docker",
|
|
|
|
"git@github.com:docker/docker.git",
|
|
|
|
"git@bitbucket.org:atlassianlabs/atlassian-docker.git",
|
|
|
|
"https://github.com/docker/docker.git",
|
|
|
|
"http://github.com/docker/docker.git",
|
|
|
|
"http://github.com/docker/docker.git#branch",
|
|
|
|
"http://github.com/docker/docker.git#:dir",
|
|
|
|
}
|
|
|
|
incompleteGitUrls := []string{
|
|
|
|
"github.com/docker/docker",
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, url := range gitUrls {
|
|
|
|
if !isGitTransport(url) {
|
|
|
|
t.Fatalf("%q should be detected as valid Git prefix", url)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, url := range incompleteGitUrls {
|
|
|
|
if isGitTransport(url) {
|
|
|
|
t.Fatalf("%q should not be detected as valid Git prefix", url)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|