Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cherry-pick doesn't seem to be happening at final stage, as advertised #344

Open
phlummox opened this issue Sep 16, 2021 · 4 comments
Open

Comments

@phlummox
Copy link

phlummox commented Sep 16, 2021

According to the merging rules, cherry-picking should happen as the last-but-one stage of merging. And "--cherry-pick" and "--prune" are described in the command --help as opposites of each other. However, they seem to give very different results in the following case, and whether cherry-picking is done seems to alter the behaviour of earlier stages.

Assume we have the following files:

recipe.yaml:

name: text and suet pudding
ingredients:
- 1 cup chopped suet
- 3 cups flour
- 1 cup milk
- bits_of_text:
    (( grab some_text ))
method:
- combine thoroughly
- serve with parsley garnish

text.yaml:

some_text: 
- (( grab files.lorem ))

files:
  lorem: (( file "lorem.txt" ))

and lorem.txt:

lorem ipsum dolor sit amet

If we run

$ spruce merge --prune files --prune some_text recipe.yml text.yml

then we get the expected output:

ingredients:
- 1 cup chopped suet
- 3 cups flour
- 1 cup milk
- bits_of_text:
  - |+
    lorem ipsum dolor sit amet

method:
- combine thoroughly
- serve with parsley garnish
name: text and suet pudding

But if we instead try and cherry-pick the "name", "method" and "ingredients" keys, we get quite different output, and the "file" operator in text.yml doesn't seem to have been executed at all. Executing

$ spruce merge --cherry-pick name --cherry-pick method --cherry-pick ingredients recipe.yml text.yml

gives the output:

ingredients:
- 1 cup chopped suet
- 3 cups flour
- 1 cup milk
- bits_of_text:
  - (( grab files.stack_build_script ))
method:
- combine thoroughly
- serve with parsley garnish
name: text and suet pudding

So something seems to be wrong - either the documentation isn't correct that "cherry-pick" happens at the penultimate stage, or the merge isn't being done according to the semantics given. (Or I'm encountering some sort of undefined behaviour due to misuse of the operators, but if so, that's not obvious to me.)

I'm using version 1.28.0 of spruce, downloaded from https://github.com/geofffranks/spruce/releases/download/v1.28.0/spruce-linux-amd64.

@geofffranks
Copy link
Owner

I created a sample of this on play.spruce.cf, with tracing enabled. it seems like spruce isn't recognizing that some_text is an operator.

DEBUG> running (( grab ... )) operation at $.ingredients.3.bits_of_text
 DEBUG>   arg[0]: trying to resolve reference $.some_text
 DEBUG>      [0]: resolved to a value (could be a map, a list or a scalar);
              → appending

@geofffranks
Copy link
Owner

Looks like 265eb84 solved this slightly. Older versions didn't resolve any operators. That resolved one level. Need to make it more recursive so any dependencies are pulled in.

@geofffranks
Copy link
Owner

Feel free to PR for this if you want @phlummox!

@phlummox
Copy link
Author

phlummox commented Oct 3, 2021

I'm afraid I don't know Go, so I don't think there's anything I'd be able to usefully provide in a PR. Best of luck resolving the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants