Skip to content

Commit 5da974c

Browse files
fix(lint): honor the --since flag when checking for version increment
Signed-off-by: Alexandre-P <[email protected]>
1 parent 89d3494 commit 5da974c

File tree

3 files changed

+15
-12
lines changed

3 files changed

+15
-12
lines changed

pkg/chart/chart.go

+9-6
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ const maxNameLength = 63
5050
// ValidateRepository checks that the current working directory is a valid git repository,
5151
// and returns nil if valid.
5252
type Git interface {
53-
FileExistsOnBranch(file string, remote string, branch string) bool
54-
Show(file string, remote string, branch string) (string, error)
53+
FileExistsOnBranch(commit string, file string) bool
54+
Show(file string, commit string) (string, error)
5555
AddWorktree(path string, ref string) error
5656
RemoveWorktree(path string) error
5757
MergeBase(commit1 string, commit2 string) (string, error)
@@ -820,15 +820,18 @@ func (t *Testing) checkBreakingChangeAllowed(chart *Chart) (allowed bool, err er
820820

821821
// GetOldChartVersion gets the version of the old Chart.yaml file from the target branch.
822822
func (t *Testing) GetOldChartVersion(chartPath string) (string, error) {
823-
cfg := t.config
823+
mergeBase, err := t.computeMergeBase()
824+
if err != nil {
825+
return "", err
826+
}
824827

825828
chartYamlFile := filepath.Join(chartPath, "Chart.yaml")
826-
if !t.git.FileExistsOnBranch(chartYamlFile, cfg.Remote, cfg.TargetBranch) {
827-
fmt.Printf("Unable to find chart on %s. New chart detected.\n", cfg.TargetBranch)
829+
if !t.git.FileExistsOnBranch(mergeBase, chartYamlFile) {
830+
fmt.Printf("Unable to find chart on commit %s. New chart detected.\n", mergeBase)
828831
return "", nil
829832
}
830833

831-
chartYamlContents, err := t.git.Show(chartYamlFile, cfg.Remote, cfg.TargetBranch)
834+
chartYamlContents, err := t.git.Show(mergeBase, chartYamlFile)
832835
if err != nil {
833836
return "", fmt.Errorf("failed reading old Chart.yaml: %w", err)
834837
}

pkg/chart/chart_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ import (
2727

2828
type fakeGit struct{}
2929

30-
func (g fakeGit) FileExistsOnBranch(file string, remote string, branch string) bool {
30+
func (g fakeGit) FileExistsOnBranch(commit string, file string) bool {
3131
return true
3232
}
3333

34-
func (g fakeGit) Show(file string, remote string, branch string) (string, error) {
34+
func (g fakeGit) Show(commit string, file string) (string, error) {
3535
return "", nil
3636
}
3737

pkg/tool/git.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ func NewGit(exec exec.ProcessExecutor) Git {
3131
}
3232
}
3333

34-
func (g Git) FileExistsOnBranch(file string, remote string, branch string) bool {
35-
fileSpec := fmt.Sprintf("%s/%s:%s", remote, branch, file)
34+
func (g Git) FileExistsOnBranch(commit string, file string) bool {
35+
fileSpec := fmt.Sprintf("%s:%s", commit, file)
3636
_, err := g.exec.RunProcessAndCaptureOutput("git", "cat-file", "-e", fileSpec)
3737
return err == nil
3838
}
@@ -45,8 +45,8 @@ func (g Git) RemoveWorktree(path string) error {
4545
return g.exec.RunProcess("git", "worktree", "remove", path)
4646
}
4747

48-
func (g Git) Show(file string, remote string, branch string) (string, error) {
49-
fileSpec := fmt.Sprintf("%s/%s:%s", remote, branch, file)
48+
func (g Git) Show(commit string, file string) (string, error) {
49+
fileSpec := fmt.Sprintf("%s:%s", commit, file)
5050
return g.exec.RunProcessAndCaptureOutput("git", "show", fileSpec)
5151
}
5252

0 commit comments

Comments
 (0)