@@ -16,12 +16,12 @@ package chart
1616
1717import (
1818 "fmt"
19+ "io/ioutil"
1920 "path/filepath"
2021 "strings"
2122
22- "github.com/helm/chart-testing/pkg/exec"
23-
2423 "github.com/helm/chart-testing/pkg/config"
24+ "github.com/helm/chart-testing/pkg/exec"
2525 "github.com/helm/chart-testing/pkg/tool"
2626 "github.com/helm/chart-testing/pkg/util"
2727 "github.com/pkg/errors"
@@ -35,9 +35,9 @@ const maxNameLength = 63
3535//
3636// Show returns the contents of file on the specified remote/branch.
3737//
38- // AddWorkingTree checks out the contents of the repository at a commit ref into the specified path.
38+ // AddWorktree checks out the contents of the repository at a commit ref into the specified path.
3939//
40- // RemoveWorkingTree removes the working tree at the specified path.
40+ // RemoveWorktree removes the working tree at the specified path.
4141//
4242// MergeBase returns the SHA1 of the merge base of commit1 and commit2.
4343//
@@ -50,8 +50,8 @@ const maxNameLength = 63
5050type Git interface {
5151 FileExistsOnBranch (file string , remote string , branch string ) bool
5252 Show (file string , remote string , branch string ) (string , error )
53- AddWorkingTree (path string , ref string ) error
54- RemoveWorkingTree (path string ) error
53+ AddWorktree (path string , ref string ) error
54+ RemoveWorktree (path string ) error
5555 MergeBase (commit1 string , commit2 string ) (string , error )
5656 ListChangedFilesInDirs (commit string , dirs ... string ) ([]string , error )
5757 GetUrlForRemote (remote string ) (string , error )
@@ -215,14 +215,15 @@ func NewChart(chartPath string) (*Chart, error) {
215215}
216216
217217type Testing struct {
218- config config.Configuration
219- helm Helm
220- kubectl Kubectl
221- git Git
222- linter Linter
223- accountValidator AccountValidator
224- directoryLister DirectoryLister
225- chartUtils ChartUtils
218+ config config.Configuration
219+ helm Helm
220+ kubectl Kubectl
221+ git Git
222+ linter Linter
223+ accountValidator AccountValidator
224+ directoryLister DirectoryLister
225+ chartUtils ChartUtils
226+ previousRevisionWorktree string
226227}
227228
228229// TestResults holds results and overall status
@@ -253,12 +254,10 @@ func NewTesting(config config.Configuration) Testing {
253254 }
254255}
255256
256- const ctPreviousRevisionTree = "ct_previous_revision"
257-
258257// computePreviousRevisionPath converts any file or directory path to the same path in the
259258// previous revision's working tree.
260- func computePreviousRevisionPath (fileOrDirPath string ) string {
261- return filepath .Join (ctPreviousRevisionTree , fileOrDirPath )
259+ func ( t * Testing ) computePreviousRevisionPath (fileOrDirPath string ) string {
260+ return filepath .Join (t . previousRevisionWorktree , fileOrDirPath )
262261}
263262
264263func (t * Testing ) processCharts (action func (chart * Chart ) TestResult ) ([]TestResult , error ) {
@@ -324,11 +323,20 @@ func (t *Testing) processCharts(action func(chart *Chart) TestResult) ([]TestRes
324323 if err != nil {
325324 return results , errors .Wrap (err , "Error identifying merge base" )
326325 }
327- t .git .AddWorkingTree (ctPreviousRevisionTree , mergeBase )
328- defer t .git .RemoveWorkingTree (ctPreviousRevisionTree )
326+ // Add worktree for the target revision
327+ worktreePath , err := ioutil .TempDir ("./" , "ct_previous_revision" )
328+ if err != nil {
329+ return results , errors .Wrap (err , "Could not create previous revision directory" )
330+ }
331+ t .previousRevisionWorktree = worktreePath
332+ err = t .git .AddWorktree (worktreePath , mergeBase )
333+ if err != nil {
334+ return results , errors .Wrap (err , "Could not create worktree for previous revision" )
335+ }
336+ defer t .git .RemoveWorktree (worktreePath )
329337
330338 for _ , chart := range charts {
331- if err := t .helm .BuildDependencies (computePreviousRevisionPath (chart .Path ())); err != nil {
339+ if err := t .helm .BuildDependencies (t . computePreviousRevisionPath (chart .Path ())); err != nil {
332340 // Only print error (don't exit) if building dependencies for previous revision fails.
333341 fmt .Println (errors .Wrapf (err , "Error building dependencies for previous revision of chart '%s'\n " , chart ))
334342 }
@@ -491,7 +499,7 @@ func (t *Testing) UpgradeChart(chart *Chart) TestResult {
491499 return result
492500 }
493501
494- if oldChart , err := NewChart (computePreviousRevisionPath (chart .Path ())); err == nil {
502+ if oldChart , err := NewChart (t . computePreviousRevisionPath (chart .Path ())); err == nil {
495503 result .Error = t .doUpgrade (oldChart , chart , false )
496504 }
497505
0 commit comments