Skip to content

Conversation

konard
Copy link
Member

@konard konard commented Sep 6, 2025

🎯 Summary

This PR implements the --pull-changes-to-fork option requested in issue #16, allowing users to synchronize their forks with the original (upstream) repositories.

📋 Issue Reference

Fixes #16

✨ What's New

New CLI Option: --pull-changes-to-fork

  • Detects which repositories are forks using GitHub API data
  • Sets up or updates upstream remote to point to the parent repository
  • Fetches latest changes from the upstream repository
  • Merges upstream changes into the local fork
  • Pushes synchronized changes back to the fork

🔧 Implementation Details

Core Changes

  • Enhanced GitHub API integration: Extended getOrganizationRepos() and getUserRepos() functions to include fork metadata (fork, parent properties)
  • New sync functions: Added syncForkWithUpstream() and syncWithUpstreamBranch() for upstream synchronization
  • Safe operation: Checks for uncommitted changes before sync, preventing data loss
  • Error handling: Graceful handling of merge conflicts with informative messages
  • Protocol support: Works with both SSH and HTTPS clone URLs

CLI Integration

  • Added --pull-changes-to-fork boolean option with proper validation
  • Updated help text and usage examples
  • Integrated into existing repository processing pipeline
  • Works with existing threading and live updates systems

Example Usage

# Sync all forks in a user account with their upstream repositories
gh-pull-all --user myusername --pull-changes-to-fork

# Sync organization forks using SSH
gh-pull-all --org myorg --pull-changes-to-fork --ssh

# Single-threaded fork sync for debugging
gh-pull-all --user myusername --pull-changes-to-fork --single-thread

🧪 Testing

  • Added comprehensive CLI tests in test-pull-changes-to-fork-cli.mjs
  • Tests validate CLI argument parsing, help output, and validation logic
  • Integrated into existing test suite (test-all.mjs)
  • All tests pass successfully

🛡️ Safety Features

  • Uncommitted changes detection: Skips repositories with uncommitted changes
  • Fork detection: Only operates on actual forks (skips regular repositories)
  • Conflict handling: Reports merge conflicts without forcing destructive operations
  • Branch fallback: Tries both main and master as default branches
  • Remote management: Properly handles existing upstream remotes

🎨 User Experience

The new option integrates seamlessly with the existing status display system:

  • Shows "Setting up upstream remote..." during remote configuration
  • Displays "Fetching upstream changes..." during upstream fetch
  • Updates with "Syncing with upstream/[branch]..." during merge
  • Reports "Fork synchronized with upstream" on success
  • Shows informative error messages for conflicts or failures

🔄 Workflow Integration

This feature works alongside existing options:

  • Compatible with --ssh for SSH URL usage
  • Works with --threads for concurrent processing
  • Integrates with --live-updates for real-time status
  • Follows same patterns as --pull-from-default and --switch-to-default

This implementation provides a complete solution for fork synchronization while maintaining the tool's existing patterns and safety standards.

Preparing to work on: #16
@konard konard self-assigned this Sep 6, 2025
…tion

- Add new CLI option --pull-changes-to-fork to sync forks with upstream repositories
- Extend GitHub API calls to include fork and parent repository information
- Implement syncForkWithUpstream function to handle upstream remote setup, fetching, and merging
- Add helper function syncWithUpstreamBranch for branch-specific sync operations
- Handle merge conflicts gracefully with informative error messages
- Support both SSH and HTTPS URLs for upstream remotes
- Add comprehensive CLI tests for the new option
- Update help text and usage examples

Fixes #16

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@konard konard changed the title [WIP] Support --pull-changes-to-fork Support --pull-changes-to-fork option for upstream sync Sep 6, 2025
@konard konard marked this pull request as ready for review September 6, 2025 22:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support --pull-changes-to-fork
1 participant