moon icon indicating copy to clipboard operation
moon copied to clipboard

[bug] Git revision is not working for templates

Open codrin-iftimie opened this issue 10 months ago • 6 comments

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

  1. moon generate test returns this error: No template with the name test could be found at any of the configured template locations.

  2. When I do ls -l ~/.moon/templates/git/github.com/facebook/react I 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

[email protected]

codrin-iftimie avatar Jun 11 '25 10:06 codrin-iftimie

@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

milesj avatar Jun 11 '25 15:06 milesj

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.

codrin-iftimie avatar Jun 11 '25 19:06 codrin-iftimie

Reworked the git commands in v1.37.2

milesj avatar Jun 15 '25 21:06 milesj

@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.

codrin-iftimie avatar Jun 16 '25 12:06 codrin-iftimie

I suppose I can just remove the depth.

milesj avatar Jun 16 '25 16:06 milesj

Removed the depth.

milesj avatar Jun 17 '25 17:06 milesj

Have you had a chance to try this?

milesj avatar Jun 24 '25 23:06 milesj

@milesj Thank you. It is working!

codrin-iftimie avatar Jul 02 '25 21:07 codrin-iftimie