Skip to content

Commit

Permalink
feat: rejoin splits
Browse files Browse the repository at this point in the history
  • Loading branch information
absporl committed Nov 13, 2023
1 parent 6848b3b commit 01ad4f4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
14 changes: 11 additions & 3 deletions src/helpers/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,17 @@ async function tagExists(tag: string, directory: string): Promise<boolean> {
}

async function publishSubSplit(binary: string, target: string, branch: string, name: string, directory: string): Promise<void> {
let hash = await getExecOutput(binary, [`--prefix=${directory}`, `--origin=origin/${branch}`]);

await exec('git', ['push', target, `${hash.trim()}:refs/heads/${branch}`, '-f']);
const hash = (await getExecOutput(binary, [`--prefix=${directory}`, `--origin=origin/${branch}`])).trim();
const isAncestor = await exec('git', ['merge-base', '--is-ancestor', hash, 'HEAD'], {ignoreReturnCode: true});
if (isAncestor !== 0) {
const tree_hash = (await getExecOutput('git', ['write-tree'])).trim();
const message = `Split '${target}' into commit '${hash}'`;
// Note: if we do more than one split, we can merge all of these join commits into a single one
const merged_hash = await getExecOutput('git', ['commit-tree', '-p', 'HEAD', '-p', hash.trim(), '-m', message, tree_hash]);
await exec('git', ['reset', '--hard', merged_hash]);
await exec('git', ['push']);
}
await exec('git', ['push', target, `${hash}:refs/heads/${branch}`, '-f']);
}

async function commitHashHasTag(hash: string, clonePath: string) {
Expand Down
7 changes: 5 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,12 @@ async function promiseAllInBatches(subtreeSplits: subtreeSplit[], batchSize: num
}

// On push sync commits
await promiseAllInBatches(subtreeSplits, batchSize, async (split: subtreeSplit) => {
for (let split of subtreeSplits) {
await publishSubSplit(splitshPath, split.name, branch, split.name, split.directory);
});
}
// await promiseAllInBatches(subtreeSplits, batchSize, async (split: subtreeSplit) => {
// await publishSubSplit(splitshPath, split.name, branch, split.name, split.directory);
// });
} else if (context.eventName === 'create') {
// Tag created
let event = context.payload as CreateEvent;
Expand Down

0 comments on commit 01ad4f4

Please sign in to comment.