UNPKG

git-bolt

Version:

Git utilities for faster development

51 lines (42 loc) 1.52 kB
import chalk from 'chalk'; import fs from 'fs'; import git from 'isomorphic-git'; import http from 'isomorphic-git/http/node/index.js'; import { getGitHubToken } from '../utils/auth.js'; async function fetchCommand(options) { try { // Load GitHub token const token = getGitHubToken(); if (!token) { console.error(chalk.red('Error: GitHub token not found')); console.log('Set it using:'); console.log(' - The GITHUB_TOKEN environment variable'); console.log(' - A .env file with GITHUB_TOKEN=your_token'); process.exit(1); } // Get current branch or use the branch specified as option const branch = options.branch || await git.currentBranch({ fs, dir: '.' }); if (!branch) { console.error(chalk.red('Error: Could not determine current branch and no branch specified')); console.log('Use: npx git-bolt fetch -b <branch-name>'); process.exit(1); } console.log(chalk.blue(`Fetching from origin, branch: ${branch}`)); await git.fetch({ fs, http, dir: '.', remote: 'origin', ref: branch, singleBranch: true, tags: true, onAuth: () => ({ username: token }) }); console.log(chalk.green('Fetch completed successfully')); console.log(chalk.blue(`To merge these changes, run: npx git-bolt branch ${branch}`)); } catch (error) { console.error(chalk.red('Error during fetch:'), error.message); process.exit(1); } } export { fetchCommand };