make repospec memebers public

This commit is contained in:
jingfangliu
2019-07-23 16:29:39 -07:00
parent c23039c07a
commit a279c08f7d
3 changed files with 37 additions and 37 deletions

View File

@@ -35,14 +35,14 @@ func ClonerUsingGitExec(repoSpec *RepoSpec) error {
if err != nil { if err != nil {
return errors.Wrap(err, "no 'git' program on path") return errors.Wrap(err, "no 'git' program on path")
} }
repoSpec.cloneDir, err = fs.NewTmpConfirmedDir() repoSpec.Dir, err = fs.NewTmpConfirmedDir()
if err != nil { if err != nil {
return err return err
} }
cmd := exec.Command( cmd := exec.Command(
gitProgram, gitProgram,
"init", "init",
repoSpec.cloneDir.String()) repoSpec.Dir.String())
var out bytes.Buffer var out bytes.Buffer
cmd.Stdout = &out cmd.Stdout = &out
err = cmd.Run() err = cmd.Run()
@@ -50,7 +50,7 @@ func ClonerUsingGitExec(repoSpec *RepoSpec) error {
return errors.Wrapf( return errors.Wrapf(
err, err,
"trouble initializing empty git repo in %s", "trouble initializing empty git repo in %s",
repoSpec.cloneDir.String()) repoSpec.Dir.String())
} }
cmd = exec.Command( cmd = exec.Command(
@@ -60,7 +60,7 @@ func ClonerUsingGitExec(repoSpec *RepoSpec) error {
"origin", "origin",
repoSpec.CloneSpec()) repoSpec.CloneSpec())
cmd.Stdout = &out cmd.Stdout = &out
cmd.Dir = repoSpec.cloneDir.String() cmd.Dir = repoSpec.Dir.String()
err = cmd.Run() err = cmd.Run()
if err != nil { if err != nil {
return errors.Wrapf( return errors.Wrapf(
@@ -68,20 +68,20 @@ func ClonerUsingGitExec(repoSpec *RepoSpec) error {
"trouble adding remote %s", "trouble adding remote %s",
repoSpec.CloneSpec()) repoSpec.CloneSpec())
} }
if repoSpec.ref == "" { if repoSpec.Ref == "" {
repoSpec.ref = "master" repoSpec.Ref = "master"
} }
cmd = exec.Command( cmd = exec.Command(
gitProgram, gitProgram,
"fetch", "fetch",
"--depth=1", "--depth=1",
"origin", "origin",
repoSpec.ref) repoSpec.Ref)
cmd.Stdout = &out cmd.Stdout = &out
cmd.Dir = repoSpec.cloneDir.String() cmd.Dir = repoSpec.Dir.String()
err = cmd.Run() err = cmd.Run()
if err != nil { if err != nil {
return errors.Wrapf(err, "trouble fetching %s", repoSpec.ref) return errors.Wrapf(err, "trouble fetching %s", repoSpec.Ref)
} }
cmd = exec.Command( cmd = exec.Command(
@@ -90,11 +90,11 @@ func ClonerUsingGitExec(repoSpec *RepoSpec) error {
"--hard", "--hard",
"FETCH_HEAD") "FETCH_HEAD")
cmd.Stdout = &out cmd.Stdout = &out
cmd.Dir = repoSpec.cloneDir.String() cmd.Dir = repoSpec.Dir.String()
err = cmd.Run() err = cmd.Run()
if err != nil { if err != nil {
return errors.Wrapf( return errors.Wrapf(
err, "trouble hard resetting empty repository to %s", repoSpec.ref) err, "trouble hard resetting empty repository to %s", repoSpec.Ref)
} }
return nil return nil
} }
@@ -105,7 +105,7 @@ func ClonerUsingGitExec(repoSpec *RepoSpec) error {
// used in a test. // used in a test.
func DoNothingCloner(dir fs.ConfirmedDir) Cloner { func DoNothingCloner(dir fs.ConfirmedDir) Cloner {
return func(rs *RepoSpec) error { return func(rs *RepoSpec) error {
rs.cloneDir = dir rs.Dir = dir
return nil return nil
} }
} }

View File

@@ -39,36 +39,36 @@ type RepoSpec struct {
raw string raw string
// Host, e.g. github.com // Host, e.g. github.com
host string Host string
// orgRepo name (organization/repoName), // orgRepo name (organization/repoName),
// e.g. kubernetes-sigs/kustomize // e.g. kubernetes-sigs/kustomize
orgRepo string OrgRepo string
// ConfirmedDir where the orgRepo is cloned to. // Dir where the orgRepo is cloned to.
cloneDir fs.ConfirmedDir Dir fs.ConfirmedDir
// Relative path in the repository, and in the cloneDir, // Relative path in the repository, and in the cloneDir,
// to a Kustomization. // to a Kustomization.
path string Path string
// Branch or tag reference. // Branch or tag reference.
ref string Ref string
// e.g. .git or empty in case of _git is present // e.g. .git or empty in case of _git is present
gitSuffix string GitSuffix string
} }
// CloneSpec returns a string suitable for "git clone {spec}". // CloneSpec returns a string suitable for "git clone {spec}".
func (x *RepoSpec) CloneSpec() string { func (x *RepoSpec) CloneSpec() string {
if isAzureHost(x.host) || isAWSHost(x.host) { if isAzureHost(x.Host) || isAWSHost(x.Host) {
return x.host + x.orgRepo return x.Host + x.OrgRepo
} }
return x.host + x.orgRepo + x.gitSuffix return x.Host + x.OrgRepo + x.GitSuffix
} }
func (x *RepoSpec) CloneDir() fs.ConfirmedDir { func (x *RepoSpec) CloneDir() fs.ConfirmedDir {
return x.cloneDir return x.Dir
} }
func (x *RepoSpec) Raw() string { func (x *RepoSpec) Raw() string {
@@ -76,11 +76,11 @@ func (x *RepoSpec) Raw() string {
} }
func (x *RepoSpec) AbsPath() string { func (x *RepoSpec) AbsPath() string {
return x.cloneDir.Join(x.path) return x.Dir.Join(x.Path)
} }
func (x *RepoSpec) Cleaner(fSys fs.FileSystem) func() error { func (x *RepoSpec) Cleaner(fSys fs.FileSystem) func() error {
return func() error { return fSys.RemoveAll(x.cloneDir.String()) } return func() error { return fSys.RemoveAll(x.Dir.String()) }
} }
// From strings like git@github.com:someOrg/someRepo.git or // From strings like git@github.com:someOrg/someRepo.git or
@@ -98,8 +98,8 @@ func NewRepoSpecFromUrl(n string) (*RepoSpec, error) {
return nil, fmt.Errorf("url lacks host: %s", n) return nil, fmt.Errorf("url lacks host: %s", n)
} }
return &RepoSpec{ return &RepoSpec{
raw: n, host: host, orgRepo: orgRepo, raw: n, Host: host, OrgRepo: orgRepo,
cloneDir: notCloned, path: path, ref: gitRef, gitSuffix: gitSuffix}, nil Dir: notCloned, Path: path, Ref: gitRef, GitSuffix: gitSuffix}, nil
} }
const ( const (

View File

@@ -72,17 +72,17 @@ func TestNewRepoSpecFromUrl(t *testing.T) {
if err != nil { if err != nil {
t.Errorf("problem %v", err) t.Errorf("problem %v", err)
} }
if rs.host != hostSpec { if rs.Host != hostSpec {
bad = append(bad, []string{"host", uri, rs.host, hostSpec}) bad = append(bad, []string{"host", uri, rs.Host, hostSpec})
} }
if rs.orgRepo != orgRepo { if rs.OrgRepo != orgRepo {
bad = append(bad, []string{"orgRepo", uri, rs.orgRepo, orgRepo}) bad = append(bad, []string{"orgRepo", uri, rs.OrgRepo, orgRepo})
} }
if rs.path != pathName { if rs.Path != pathName {
bad = append(bad, []string{"path", uri, rs.path, pathName}) bad = append(bad, []string{"path", uri, rs.Path, pathName})
} }
if rs.ref != hrefArg { if rs.Ref != hrefArg {
bad = append(bad, []string{"ref", uri, rs.ref, hrefArg}) bad = append(bad, []string{"ref", uri, rs.Ref, hrefArg})
} }
} }
} }
@@ -201,9 +201,9 @@ func TestNewRepoSpecFromUrl_CloneSpecs(t *testing.T) {
t.Errorf("AbsPath expected to be %v, but got %v on %s", t.Errorf("AbsPath expected to be %v, but got %v on %s",
testcase.absPath, rs.AbsPath(), testcase.input) testcase.absPath, rs.AbsPath(), testcase.input)
} }
if rs.ref != testcase.ref { if rs.Ref != testcase.ref {
t.Errorf("ref expected to be %v, but got %v on %s", t.Errorf("ref expected to be %v, but got %v on %s",
testcase.ref, rs.ref, testcase.input) testcase.ref, rs.Ref, testcase.input)
} }
} }
} }