-
Notifications
You must be signed in to change notification settings - Fork 95
DOC-14109 WIP worktree support #880
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,7 +10,11 @@ const util = require('util') | |
| const exec = util.promisify(require('child_process').exec) | ||
|
|
||
| module.exports.register = function () { | ||
| this.once('playbookBuilt', async function ({ playbook }) { | ||
|
|
||
| this.once('playbookBuilt', rebuildPlaybook) | ||
|
|
||
| async function rebuildPlaybook ({ playbook }) { | ||
|
|
||
| // deep-copy playbook to allow it to be updated | ||
| const env = playbook.env | ||
| playbook = JSON.parse(JSON.stringify(playbook)) | ||
|
|
@@ -37,7 +41,7 @@ module.exports.register = function () { | |
| const sources = getSources(playbook, additionalSources) | ||
| const source = sources[args.repo] | ||
| if (! source) { | ||
| throw notfound(args) | ||
| throw notfound({goat:1, ...args}) | ||
| } | ||
|
|
||
| if (args.remote) { | ||
|
|
@@ -76,16 +80,35 @@ module.exports.register = function () { | |
| } | ||
| } | ||
|
|
||
| const mapLocalUrl = (repo, url) => (args.repoPath | ||
| .map(p => path.resolve(p, repo)) | ||
| .find(fs.existsSync) | ||
| || url) | ||
| const isMainGitDir = p => { | ||
| const pwg = `${p}/.git` | ||
| if (! fs.existsSync(pwg)) { return false } | ||
| return fs.statSync(pwg).isDirectory() | ||
| } | ||
|
|
||
| function mapLocalUrl (repo, url) { | ||
| for (const repoPath of args.repoPath) { | ||
| const p = path.resolve(repoPath, repo) | ||
| if (fs.existsSync(p)) { | ||
| if (isMainGitDir(p)) { return p } | ||
| // otherwise check if this directory contains worktrees | ||
| const subdir = | ||
| fs.readdirSync(p).find( | ||
| n => isMainGitDir(`${p}/${n}`)) | ||
| if (subdir) { | ||
| return `${p}/${subdir}` | ||
| } | ||
|
||
| } | ||
| } | ||
|
|
||
|
osfameron marked this conversation as resolved.
|
||
| // fallback to the original (remote) url | ||
| return url | ||
| } | ||
|
|
||
| const basePath = path.resolve( | ||
| mapLocalUrl(args.repo, 'UNEXPECTED'), | ||
| args.startPath || source.start_path || '') | ||
| const antoraYmlPath = `${basePath}/antora.yml` | ||
| console.log(antoraYmlPath) | ||
|
|
||
| const readYaml = (path) => | ||
| fs.existsSync(path) && yaml.parse(fs.readFileSync(path).toString()) | ||
|
|
@@ -118,6 +141,7 @@ module.exports.register = function () { | |
| const urlMapper = ([k,v]) => { | ||
| if (! v.url) { | ||
| throw notfound({...args, | ||
| goat: 2, | ||
| repo: k, | ||
| githubRemote: undefined, | ||
| branch: undefined, | ||
|
|
@@ -133,8 +157,6 @@ module.exports.register = function () { | |
| Object.entries(updatedSources) | ||
| .map(urlMapper))) | ||
|
|
||
| console.dir(mappedSources, {depth: 5}) | ||
|
|
||
| const startPage = | ||
| { site: | ||
| { startPage: | ||
|
|
@@ -152,11 +174,11 @@ module.exports.register = function () { | |
| playbook.asciidoc.attributes['page-watermark'] = | ||
| `${date} ${args.repo} ${watermark_branch}` | ||
|
|
||
| // console.dir(playbook, {depth: 5}); process.exit(1) | ||
| // reinflate .env before updating | ||
| playbook.env = env | ||
|
|
||
| this.updateVariables({ playbook }) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| function notfound(args) { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.