[bug] Git revision is not working for templates
Describe the bug I'm just taking a random commit from a public registry. While I know there are no templates in this example, I'm just providing it as an example
$schema: 'https://moonrepo.dev/schemas/workspace.json'
projects:
- 'apps/*'
- 'packages/*'
generator:
templates:
- 'git://github.com/facebook/react#12adaffef7105e2714f82651ea51936c563fe15c'
Steps to reproduce
-
moon generate testreturns this error:No template with the name test could be found at any of the configured template locations. -
When I do
ls -l ~/.moon/templates/git/github.com/facebook/reactI see the files from the main branch, not from the specific commit.
I tried tags https://github.com/facebook/react/releases/tag/v17.0.2 (points to the same commit) as well
The file structure for these would not have the ReactVersions.js file present in the ~/.moon/templates/git/github.com/facebook/react directory, for example
Expected behavior
The git templates should honor the revision.
Environment
@codrin-iftimie If you cd into ~/.moon/templates/git/github.com/facebook/react, what branch/revision does it show it as?
We do the checkout here after cloning: https://github.com/moonrepo/moon/blob/master/crates/codegen/src/codegen.rs#L355
Sorry, I didn't dig too much into it. Yes, the branch says 12adaffef7105e2714f82651ea51936c563fe15c, but this is a commit ID, so it should not be a branch.
Here is how I do it manually
git clone [email protected]:facebook/react.git
git checkout 12adaffef7105e2714f82651ea51936c563fe15c
# or git checkout v17.0.2
shows as
~/Work/react @12adaffe
vs
~/.moon/templates/git/github.com/facebook/react 12adaffef7105e2714f82651ea51936c563fe15c*
The problem with the code is that it considers all revisions as branches.
I can replicate it (forcing it to a branch) when I'm adding the -B option. git log confirms my suspicion, in regular checkout it shows a commit from 2021, while then -B is provided, it shows the latest commit.
Also, you might want to take look at the tags case as well, from that ~/.moon/templates directory, I was not able to move to a tag; I had to git pull --tags, after deleting the branch created when testing the config.
Reworked the git commands in v1.37.2
@milesj Thank you. I'm trying with this new version, but I haven't managed to get it working.
From what I could find, the error is coming from https://github.com/moonrepo/moon/blob/master/crates/codegen/src/codegen.rs#L352
This depth is the culprit here, or not specifying the branch along with the depth.
git://github.com/facebook/react#rm-renderable-ctx-flag is not working, even though it's a valid branch, I'm getting the following
× Process git failed: exit code 1
│
│ error: pathspec 'rm-renderable-ctx-flag' did not match any file(s) known to git
Used GPT and it suggested that it is a better alternative:
git clone --branch rm-renderable-ctx-flag --depth 1 [email protected]:facebook/react.git
This keeps the initial speed, and the checkout would no longer be needed. It works for tags as well, but not for commits. Noticed that commits are no longer mentioned in the docs, so this might not be an issue.
I suppose I can just remove the depth.
Removed the depth.
Have you had a chance to try this?
@milesj Thank you. It is working!