Skip to content

Commit

Permalink
head:true handling
Browse files Browse the repository at this point in the history
  • Loading branch information
osfameron committed Jun 8, 2023
1 parent e05b7bf commit c24f1f0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 17 deletions.
1 change: 1 addition & 0 deletions patch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ content:
$local: # only the ones we have checked out locally in ../
paths: ..
only: true
head: true # only use [HEAD] branch

$filter: # restrict to certain tags
tags: mobile
Expand Down
44 changes: 27 additions & 17 deletions playbook.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,14 @@ function $filter (orig, param) {
* @param {Object} config
* @param {Array.<string>} config.paths - array of local filesystem paths to check for the git repo
* @param {boolean} config.only - if true, filter out all non-local sources
* @param {boolean} config.head - if true, only use HEAD
*
* We try to play nice with Author-mode by substituting HEAD if it matches a branch, or prepending it otherwise.
* We try to play nice with Author-mode by substituting HEAD if it matches a
* branch, or prepending it otherwise.
* BUT this doesn't work great with feature-branches (really, we should check the antora.yml version)
* In the meantime, use config.head as workaround
*/
async function $local (orig, {paths, only}) {
async function $local (orig, {paths, only, head}) {
const repoPaths = toArray(paths ?? ['..'])
const withLocal = await Promise.all(
orig.map(async item => {
Expand All @@ -74,21 +78,27 @@ async function $local (orig, {paths, only}) {
try {
fs.accessSync(newPath, fs.constants.R_OK)

const HEAD = (await $`git -C ${newPath} rev-parse HEAD`).stdout.trim()

const b1 = await Promise.all(branches.map(async b => {
try {
const ref = (await $`git -C ${newPath} rev-parse ${b}`).stdout.trim()
return (ref === HEAD) ? 'HEAD' : b
}
catch (e) {
// filter this one out as presumably it doesn't exist locally
return
}
}))
const b2 = b1.filter(a=>a !== undefined)
const b3 = b2.includes('HEAD') ? b2 : ['HEAD', ...b2]
return {...item, url: newPath, branches: b3, local: true}
if (head) {
return {...item, url: newPath, branches: ['HEAD'], local: true}
}
else {
// cleverness to try to match branches to HEAD
const HEAD = (await $`git -C ${newPath} rev-parse HEAD`).stdout.trim()

const b1 = await Promise.all(branches.map(async b => {
try {
const ref = (await $`git -C ${newPath} rev-parse ${b}`).stdout.trim()
return (ref === HEAD) ? 'HEAD' : b
}
catch (e) {
// filter this one out as presumably it doesn't exist locally
return
}
}))
const b2 = b1.filter(a=>a !== undefined)
const b3 = b2.includes('HEAD') ? b2 : ['HEAD', ...b2]
return {...item, url: newPath, branches: b3, local: true}
}
}
catch(e) {
continue
Expand Down

0 comments on commit c24f1f0

Please sign in to comment.