OverviewFilesCommitsIssuesDocsReleasesPeers

pgh / lib / commands / push.js

44 lines · javascript ref:
/**
 * pgh push — `git push` with pear-remote auto-detect.
 *
 *   pgh push                     # auto-detect pear remote, push current branch
 *   pgh push main                # auto-detect remote, push main
 *   pgh push origin main         # explicit remote, no auto-detect
 *   pgh push --force main        # flags pass through
 *
 * Auto-detects a remote with a pear-style URL (pear://, punch://,
 * git+pear://) or a remote literally named `pear`. If multiple are
 * present, prefers the one named `pear`, else the first.
 *
 * Pure local — does not connect to the v3 daemon.
 */

import { detectPearRemote, runGit } from './_git-helpers.js'

export const usage = `pgh push — 'git push' with pear-remote auto-detect

  pgh push                                 Auto-detect pear remote, push branch
  pgh push main                            Auto-detect remote, push main
  pgh push origin main                     Explicit remote (no auto-detect)
  pgh push --force main                    Flags pass through to git

Auto-detects a remote with a pear:// / punch:// / git+pear:// URL (or one
literally named 'pear'). Pure local — does not connect to the daemon.`

export async function run (client, args) {
  return runGitWithRemote('push', args)
}

async function runGitWithRemote (subcommand, args) {
  const userSuppliedRemote = args.length > 0 && !args[0].startsWith('-')
  let finalArgs
  if (userSuppliedRemote) {
    finalArgs = [subcommand, ...args]
  } else {
    const remote = detectPearRemote()
    finalArgs = [subcommand, remote, ...args]
  }
  await runGit(finalArgs)
  return null
}