@@ -16,12 +16,12 @@ package chart
16
16
17
17
import (
18
18
"fmt"
19
+ "io/ioutil"
19
20
"path/filepath"
20
21
"strings"
21
22
22
- "github.com/helm/chart-testing/pkg/exec"
23
-
24
23
"github.com/helm/chart-testing/pkg/config"
24
+ "github.com/helm/chart-testing/pkg/exec"
25
25
"github.com/helm/chart-testing/pkg/tool"
26
26
"github.com/helm/chart-testing/pkg/util"
27
27
"github.com/pkg/errors"
@@ -35,9 +35,9 @@ const maxNameLength = 63
35
35
//
36
36
// Show returns the contents of file on the specified remote/branch.
37
37
//
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.
39
39
//
40
- // RemoveWorkingTree removes the working tree at the specified path.
40
+ // RemoveWorktree removes the working tree at the specified path.
41
41
//
42
42
// MergeBase returns the SHA1 of the merge base of commit1 and commit2.
43
43
//
@@ -50,8 +50,8 @@ const maxNameLength = 63
50
50
type Git interface {
51
51
FileExistsOnBranch (file string , remote string , branch string ) bool
52
52
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
55
55
MergeBase (commit1 string , commit2 string ) (string , error )
56
56
ListChangedFilesInDirs (commit string , dirs ... string ) ([]string , error )
57
57
GetUrlForRemote (remote string ) (string , error )
@@ -215,14 +215,15 @@ func NewChart(chartPath string) (*Chart, error) {
215
215
}
216
216
217
217
type 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
226
227
}
227
228
228
229
// TestResults holds results and overall status
@@ -253,12 +254,10 @@ func NewTesting(config config.Configuration) Testing {
253
254
}
254
255
}
255
256
256
- const ctPreviousRevisionTree = "ct_previous_revision"
257
-
258
257
// computePreviousRevisionPath converts any file or directory path to the same path in the
259
258
// 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 )
262
261
}
263
262
264
263
func (t * Testing ) processCharts (action func (chart * Chart ) TestResult ) ([]TestResult , error ) {
@@ -324,11 +323,20 @@ func (t *Testing) processCharts(action func(chart *Chart) TestResult) ([]TestRes
324
323
if err != nil {
325
324
return results , errors .Wrap (err , "Error identifying merge base" )
326
325
}
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 )
329
337
330
338
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 {
332
340
// Only print error (don't exit) if building dependencies for previous revision fails.
333
341
fmt .Println (errors .Wrapf (err , "Error building dependencies for previous revision of chart '%s'\n " , chart ))
334
342
}
@@ -491,7 +499,7 @@ func (t *Testing) UpgradeChart(chart *Chart) TestResult {
491
499
return result
492
500
}
493
501
494
- if oldChart , err := NewChart (computePreviousRevisionPath (chart .Path ())); err == nil {
502
+ if oldChart , err := NewChart (t . computePreviousRevisionPath (chart .Path ())); err == nil {
495
503
result .Error = t .doUpgrade (oldChart , chart , false )
496
504
}
497
505
0 commit comments