diff --git a/src/internal/context.go b/src/internal/context.go index ea47ee1..ea806f8 100644 --- a/src/internal/context.go +++ b/src/internal/context.go @@ -14,27 +14,6 @@ var None = Context{ Mounts: make(map[string]string), } -// Commented Load because we don't load a context from a file but will read a contextFile to get our Contexts - -// Load loads the context from given file -// func Load(file string) (Context, error) { -// var context Context -// if !helpers.PathExists(file) { -// return context, nil -// } - -// buf, err := ioutil.ReadFile(file) -// if err != nil { -// return context, fmt.Errorf("loading context file: %w", err) -// } -// err = yaml.Unmarshal(buf, &context) -// if err != nil { -// return context, fmt.Errorf("unmarshalling yaml of context file %q: %w", file, err) -// } - -// return context, nil -// } - // Clone returns a deep-copy of this context func (c Context) Clone() Context { clone := c diff --git a/src/internal/contextFile.go b/src/internal/contextFile.go index fc4f2fd..38c460e 100644 --- a/src/internal/contextFile.go +++ b/src/internal/contextFile.go @@ -47,21 +47,18 @@ func Load(file string) (ContextFile, error) { // Clone returns a deep-copy of this context func (cf ContextFile) Clone() ContextFile { - contextFile := ContextFile{ - Version: cf.Version, - Parent: cf.Parent, - } + clone := cf for key, value := range cf.NamedContexts { - contextFile.NamedContexts[key] = value.Clone() + clone.NamedContexts[key] = value.Clone() } - return contextFile + return clone } // Merge creates a deep-copy of this context and copies values from given source context on top of it func (cf ContextFile) Merge(source ContextFile) ContextFile { clone := cf.Clone() - if source.Version != 0 { - clone.Version = source.Version + if source.Version != clone.Version { + panic(fmt.Errorf("trying to merge contexts with incompatible versions %d and %d", clone.Version, source.Version)) } if source.Parent != "" { clone.Parent = source.Parent