Skip to content

Commit

Permalink
Improve serialization of documents consisting only of comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
felixfontein committed Jan 6, 2021
1 parent 37f3196 commit 0163f93
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion stores/yaml/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,9 +355,13 @@ func (store *Store) EmitPlainFile(branches sops.TreeBranches) ([]byte, error) {
// Add global mapping
var mapping = yaml.Node{}
mapping.Kind = yaml.MappingNode
doc.Content = append(doc.Content, &mapping)
// Marshal branch to global mapping node
store.appendTreeBranch(branch, &mapping)
if len(mapping.Content) == 0 {
doc.HeadComment = mapping.HeadComment
} else {
doc.Content = append(doc.Content, &mapping)
}
// Encode YAML
err := e.Encode(&doc)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion stores/yaml/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ prometheus-node-exporter:
`)

var COMMENT_4 = []byte(`# foo
{}
`)

func TestUnmarshalMetadataFromNonSOPSFile(t *testing.T) {
Expand Down

0 comments on commit 0163f93

Please sign in to comment.