spb/spbgit Public MIT
SPB Git — the platform hosting itself
JavaScript 73.9%
CSS 11.7%
Nunjucks 11.6%
Shell 2.7%
1/**2 * ─────────────────────────────────────────────3 * SPB Git — Personal Git Platform4 * ─────────────────────────────────────────────5 * Author : Simon-Pierre Boucher6 * Contact : contact@spboucher.ai7 * File : cli/commands/pull.mjs8 * Purpose : `spbgit pull [name]|--all` — ff-only by default9 * License : MIT © Simon-Pierre Boucher10 * ─────────────────────────────────────────────11 */1213import { basename } from 'node:path';14import pc from 'picocolors';15import { requireCliConfig } from '../lib/config.mjs';16import { git } from '../lib/git.mjs';17import { mapLimit, SYM } from '../lib/ui.mjs';18import { EXIT } from '../lib/api.mjs';19import { resolveTargets } from './commit.mjs';2021export function registerPull(program) {22 program23 .command('pull [name]')24 .description('pull target repo(s) — fast-forward only by default')25 .option('--all', 'every workspace repository', false)26 .option('--rebase', 'pull with --rebase instead of --ff-only', false)27 .action(async (name, opts) => {28 const config = requireCliConfig();29 const targets = resolveTargets(config, name, opts.all);30 let failures = 0;31 await mapLimit(targets, 4, async (dir) => {32 const repo = basename(dir);33 const args = ['pull', opts.rebase ? '--rebase' : '--ff-only'];34 const result = await git(dir, args, { token: config.token });35 if (result.ok) {36 const upToDate = /Already up to date/i.test(result.stdout);37 console.log(`${upToDate ? SYM.skip : SYM.pull} ${repo} ${pc.dim(upToDate ? 'up to date' : 'updated')}`);38 } else {39 failures += 1;40 console.error(`${SYM.fail} ${repo}: ${result.stderr.trim().split('\n').pop()}`);41 }42 });43 if (failures > 0) process.exit(EXIT.PARTIAL);44 });45}46