Skip to content

Commit 1dc2b53

Browse files
Skip fetching newly cloned repos
This makes sure we don't fetch repo that has just been cloned.
1 parent 0db6dbc commit 1dc2b53

File tree

2 files changed

+35
-12
lines changed

2 files changed

+35
-12
lines changed

newt/downloader/downloader.go

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,12 @@ type Downloader interface {
110110
// Returns the branch that contains the YAML control files; this option
111111
// allows implementers to override "master" as the main branch.
112112
MainBranch() string
113+
114+
// Returns formatted string with repo details
115+
String() string
116+
117+
// Returns if repository was already fetched
118+
IsFetched() bool
113119
}
114120

115121
type Commit struct {
@@ -814,6 +820,10 @@ func (gd *GenericDownloader) LatestRc(path string,
814820
return bestStr, nil
815821
}
816822

823+
func (gd *GenericDownloader) IsFetched() bool {
824+
return gd.fetched
825+
}
826+
817827
func (gd *GithubDownloader) Fetch(repoDir string) error {
818828
return gd.cachedFetch(func() error {
819829
util.StatusMessage(util.VERBOSITY_VERBOSE, "Fetching repo %s\n",
@@ -921,11 +931,7 @@ func (gd *GithubDownloader) setRemoteAuth(path string) error {
921931
func (gd *GithubDownloader) Clone(commit string, dstPath string) error {
922932
branch := gd.MainBranch()
923933

924-
url, publicUrl := gd.remoteUrls()
925-
926-
util.StatusMessage(util.VERBOSITY_DEFAULT,
927-
"Downloading repository %s (commit: %s) from %s\n",
928-
gd.Repo, commit, publicUrl)
934+
url, _ := gd.remoteUrls()
929935

930936
gp, err := gitPath()
931937
if err != nil {
@@ -960,6 +966,8 @@ func (gd *GithubDownloader) Clone(commit string, dstPath string) error {
960966
return err
961967
}
962968

969+
gd.fetched = true
970+
963971
return nil
964972
}
965973

@@ -987,6 +995,12 @@ func (gd *GithubDownloader) MainBranch() string {
987995
}
988996
}
989997

998+
func (gd *GithubDownloader) String() string {
999+
_, publicUrl := gd.remoteUrls()
1000+
1001+
return publicUrl
1002+
}
1003+
9901004
func NewGithubDownloader() *GithubDownloader {
9911005
return &GithubDownloader{}
9921006
}
@@ -1024,9 +1038,6 @@ func (gd *GitDownloader) FetchFile(
10241038
func (gd *GitDownloader) Clone(commit string, dstPath string) error {
10251039
branch := gd.MainBranch()
10261040

1027-
util.StatusMessage(util.VERBOSITY_DEFAULT,
1028-
"Downloading repository %s (commit: %s)\n", gd.Url, commit)
1029-
10301041
gp, err := gitPath()
10311042
if err != nil {
10321043
return err
@@ -1059,6 +1070,8 @@ func (gd *GitDownloader) Clone(commit string, dstPath string) error {
10591070
return err
10601071
}
10611072

1073+
gd.fetched = true
1074+
10621075
return nil
10631076
}
10641077

@@ -1084,6 +1097,10 @@ func (gd *GitDownloader) MainBranch() string {
10841097
}
10851098
}
10861099

1100+
func (gd *GitDownloader) String() string {
1101+
return gd.Url
1102+
}
1103+
10871104
func NewGitDownloader() *GitDownloader {
10881105
return &GitDownloader{}
10891106
}
@@ -1118,9 +1135,6 @@ func (ld *LocalDownloader) Checkout(path string, commit string) error {
11181135
}
11191136

11201137
func (ld *LocalDownloader) Clone(commit string, dstPath string) error {
1121-
util.StatusMessage(util.VERBOSITY_DEFAULT,
1122-
"Downloading local repository %s\n", ld.Path)
1123-
11241138
if err := util.CopyDir(ld.Path, dstPath); err != nil {
11251139
return err
11261140
}
@@ -1140,6 +1154,10 @@ func (gd *LocalDownloader) MainBranch() string {
11401154
return "master"
11411155
}
11421156

1157+
func (ld *LocalDownloader) String() string {
1158+
return ld.Path
1159+
}
1160+
11431161
func NewLocalDownloader() *LocalDownloader {
11441162
return &LocalDownloader{}
11451163
}

newt/repo/repo.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,9 @@ func (r *Repo) downloadRepo(commit string) error {
260260
}
261261
defer os.RemoveAll(tmpdir)
262262

263+
util.StatusMessage(util.VERBOSITY_DEFAULT,
264+
"Cloning %s (%s)\n", r.Name(), dl.String())
265+
263266
// Download the git repo, returns the git repo, checked out to that commit
264267
if err := dl.Clone(commit, tmpdir); err != nil {
265268
return util.FmtNewtError("Error downloading repository %s: %s",
@@ -382,7 +385,9 @@ func (r *Repo) UpdateDesc() (bool, error) {
382385
return false, nil
383386
}
384387

385-
util.StatusMessage(util.VERBOSITY_DEFAULT, "Fetching %s\n", r.Name())
388+
if !r.downloader.IsFetched() {
389+
util.StatusMessage(util.VERBOSITY_DEFAULT, "Fetching %s\n", r.Name())
390+
}
386391

387392
// Make sure the repo's "origin" remote points to the correct URL. This is
388393
// necessary in case the user changed his `project.yml` file to point to a

0 commit comments

Comments
 (0)