Files snapshot from mithril-server-side-rendering
Goal: Repoviewer should clone its own copy of the repository in a "before" hook, instead of an "after" hook. Then it should use that copy of the repo for all of its operations when generating the site. This is also the point where it can figure out which branches match the user's provided branch glob names. (See branch globs project.)
main.ts in an eleventyConfig.on("eleventy.after") callbackeleventyConfig.on("eleventy.before") that you can use
Places that mention git -C. Check if these need to be replaced:
git -C ${location} fetch origin ${branch}:${branch}).join('; ')${fetchCommands} && git -C ${location} update-server-info)git -C ${eleventyConfig.dir.output + reposPath + "/" + gitRepoName} update-server-info)git -C ${location} symbolic-ref HEAD refs/heads/${repoConfig.defaultBranch})git -C ${tempDirRepoPath} checkout ${branch})git -C ${location} show ${branch}:${filename}git -C ${location} show ${branchName}:README.mdgit -C ${repoLocation} show-ref refs/heads/${branchName})git -C ${repoLocation} ls-tree -r --name-only ${branchName}git -C ${repoLocation} rev-list --count ${branchName})git -C ${repoLocation} log ${branchName} -p -n 10 --skip ${i})git -C ${repoLocation} blame --porcelain ${branch} ${filename}^ Most of those were fixed by changing what repo location is found in
getLocation.
Seems like a plugin actually can't make its before hook get triggered before the site generation happens.
Because the plugin is now exclusively reading things from the cloned repository, and not the source repo on the computer, the before hook really does need to happen before the site generation happens. Apparently it wasn't happening before, but this wasn't an issue because the plugin was just reading directly from the source repo.
I've worked around this by not calling the eleventyConfig.on("eleventy.before") in the plugin, but rather,
exporting a function that the user will need to call as a before hook in their own eleventy config. Also, it needs
to be "beforeConfig" instead of just "before" -- seems like plugins are executed as part of the config step.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
b3ebf3 Tucker McKnight
b3ebf3 Tucker McKnight
b3ebf3 Tucker McKnight
b3ebf3 Tucker McKnight
b3ebf3 Tucker McKnight
b3ebf3 Tucker McKnight
b3ebf3 Tucker McKnight
b3ebf3 Tucker McKnight
3820b5 Tucker McKnight
3820b5 Tucker McKnight
3820b5 Tucker McKnight
3820b5 Tucker McKnight
3820b5 Tucker McKnight
3820b5 Tucker McKnight
3820b5 Tucker McKnight
2ecee5 Tucker McKnight
2ecee5 Tucker McKnight
2ecee5 Tucker McKnight
2ecee5 Tucker McKnight
2ecee5 Tucker McKnight
2ecee5 Tucker McKnight
2ecee5 Tucker McKnight
2ecee5 Tucker McKnight
2ecee5 Tucker McKnight
2ecee5 Tucker McKnight
2ecee5 Tucker McKnight
2ecee5 Tucker McKnight
2ecee5 Tucker McKnight
2ecee5 Tucker McKnight
2ecee5 Tucker McKnight
2ecee5 Tucker McKnight
2ecee5 Tucker McKnight
2ecee5 Tucker McKnight
2ecee5 Tucker McKnight
2ecee5 Tucker McKnight
2ecee5 Tucker McKnight
2ecee5 Tucker McKnight
2ecee5 Tucker McKnight
2ecee5 Tucker McKnight
2ecee5 Tucker McKnight
2ecee5 Tucker McKnight
2ecee5 Tucker McKnight
2ecee5 Tucker McKnight
2ecee5 Tucker McKnight
2ecee5 Tucker McKnight
2ecee5 Tucker McKnight
2ecee5 Tucker McKnight
2ecee5 Tucker McKnight
2ecee5 Tucker McKnight
2ecee5 Tucker McKnight
2ecee5 Tucker McKnight
2ecee5 Tucker McKnight
2ecee5 Tucker McKnight
# Clone Early
> Goal: Repoviewer should clone its own copy of the repository in
> a "before" hook, instead of an "after" hook. Then it should use
> that copy of the repo for all of its operations when generating
> the site. This is also the point where it can figure out which
> branches match the user's provided branch glob names. (See
> [branch globs project](./branch-globs.md.html).)
## Brainstorming Jan 10, 2026
- Where to do this?
- Currently, repo is clone in `main.ts` in an `eleventyConfig.on("eleventy.after")` callback
- There is also an `eleventyConfig.on("eleventy.before")` that you can use
- this was surprisingly easy; just changing eleventy.before to eleventy.after
seems to have worked for doing the clone before the site generation.
- the build steps happen in their own, separate eleventy.after callback
now. Which also works, and might have fixed a race condition where it was
sometimes running the build steps before the cloned repo was available.
- Next step: do not reference the original repository after the clone happens.
Always reference the cloned repo instead.
Places that mention `git -C`. Check if these need to be replaced:
- [x] main.ts: const fetchCommands = repoConfig.branchesToPull.map(branch => `git -C ${location} fetch origin ${branch}:${branch}`).join('; ')
- [x] main.ts: await exec(`${fetchCommands} && git -C ${location} update-server-info`)
- [x] main.ts: await exec(`git -C ${eleventyConfig.dir.output + reposPath + "/" + gitRepoName} update-server-info`)
- [x] main.ts: await exec(`git -C ${location} symbolic-ref HEAD refs/heads/${repoConfig.defaultBranch}`)
- [x] main.ts: await exec(`git -C ${tempDirRepoPath} checkout ${branch}`)
- [x] main.ts: const command = `git -C ${location} show ${branch}:${filename}`
- [x] main.ts: const command = `git -C ${location} show ${branchName}:README.md`
- [x] src/repos.ts: const branchHeadRes = await exec(`git -C ${repoLocation} show-ref refs/heads/${branchName}`)
- [x] src/vcses/git/operations.ts: const command = `git -C ${repoLocation} ls-tree -r --name-only ${branchName}`
- [x] src/vcses/git/operations.ts: const totalPatchesCountRes = await exec(`git -C ${repoLocation} rev-list --count ${branchName}`)
- [x] src/vcses/git/operations.ts: const gitLogSubsetRes = await exec(`git -C ${repoLocation} log ${branchName} -p -n 10 --skip ${i}`)
- [x] src/vcses/git/operations.ts: const command = `git -C ${repoLocation} blame --porcelain ${branch} ${filename}`
^ Most of those were fixed by changing what repo location is found in
`getLocation`.
### Before hook issue
Seems like a plugin actually can't make its before hook get triggered before the site generation happens.
Because the plugin is now exclusively reading things from the _cloned_ repository, and not the source repo
on the computer, the before hook really does need to happen before the site generation happens. Apparently
it wasn't happening before, but this wasn't an issue because the plugin was just reading directly from the
source repo.
I've worked around this by not calling the `eleventyConfig.on("eleventy.before")` _in_ the plugin, but rather,
exporting a function that the user will need to call as a before hook in their own eleventy config. Also, it needs
to be `"beforeConfig"` instead of just `"before"` -- seems like plugins are executed as part of the config step.