Merge pull request #3730 from helgi/feature/gh-3682

Create index.yaml if missing when running repo index --merge
pull/3750/head
Matthew Fisher 7 years ago committed by GitHub
commit 793cda8aa0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -19,6 +19,7 @@ package main
import (
"fmt"
"io"
"os"
"path/filepath"
"github.com/spf13/cobra"
@ -86,9 +87,16 @@ func index(dir, url, mergeTo string) error {
return err
}
if mergeTo != "" {
i2, err := repo.LoadIndexFile(mergeTo)
if err != nil {
return fmt.Errorf("Merge failed: %s", err)
// if index.yaml is missing then create an empty one to merge into
var i2 *repo.IndexFile
if _, err := os.Stat(mergeTo); os.IsNotExist(err) {
i2 = repo.NewIndexFile()
i2.WriteFile(mergeTo, 0755)
} else {
i2, err = repo.LoadIndexFile(mergeTo)
if err != nil {
return fmt.Errorf("Merge failed: %s", err)
}
}
i.Merge(i2)
}

@ -112,6 +112,36 @@ func TestRepoIndexCmd(t *testing.T) {
if vs[0].Version != expectedVersion {
t.Errorf("expected %q, got %q", expectedVersion, vs[0].Version)
}
// test that index.yaml gets generated on merge even when it doesn't exist
if err := os.Remove(destIndex); err != nil {
t.Fatal(err)
}
c.ParseFlags([]string{"--merge", destIndex})
if err := c.RunE(c, []string{dir}); err != nil {
t.Error(err)
}
_, err = repo.LoadIndexFile(destIndex)
if err != nil {
t.Fatal(err)
}
// verify it didn't create an empty index.yaml and the merged happened
if len(index.Entries) != 2 {
t.Errorf("expected 2 entries, got %d: %#v", len(index.Entries), index.Entries)
}
vs = index.Entries["compressedchart"]
if len(vs) != 3 {
t.Errorf("expected 3 versions, got %d: %#v", len(vs), vs)
}
expectedVersion = "0.3.0"
if vs[0].Version != expectedVersion {
t.Errorf("expected %q, got %q", expectedVersion, vs[0].Version)
}
}
func linkOrCopy(old, new string) error {

Loading…
Cancel
Save