Skip to main content

A CLI tool to synchronize projects with their templates.

Project description

sync-template

sync-template is a CLI tool designed for managing and synchronizing projects derived from template repositories. It helps you seamlessly merge updates from the template project into your existing project while protecting your local modifications using .syncignore.

Core Features

  • Rapid Initialization: Quickly create new projects from a template repository using git clone --depth 1.
  • Auto-configuration: Automatically sets the template repository as a remote named template.
  • Smart Synchronization: Fetches and merges updates from the template repository via git fetch and git merge.
  • .syncignore Protection: Automatically applies ignore rules after merging to ensure specific files or directories remain in their local state (supports recursive directories).
  • Safety Checks: Automatically verifies the working tree for uncommitted or untracked files before syncing to prevent accidental data loss.

Installation

Ensure your system has Python 3.13+ and Git installed.

To install via pip (after publishing):

pip install sync-template

To install from source (using Poetry):

git clone https://github.com/your-username/sync-template.git
cd sync-template
poetry install

Usage

1. Initialize a New Project

Create a new project from a Git template repository:

sync-template init https://github.com/user/my-python-template.git my-new-project

This will:

  • Clone the template into my-new-project.
  • Rename/set the remote origin to template.

2. Configure Ignore Rules

Create a .syncignore file in the project root. The syntax is identical to .gitignore.

Example:

# Ignore configuration files
config.json
# Ignore the entire content directory (including additions, modifications, and deletions)
content/
# Ignore specific local-only scripts
scripts/local_only.sh

3. Sync Updates

When the template repository has updates, run the following in your project root:

sync-template sync

By default, it syncs the main branch. To sync a different branch, use the --branch parameter:

sync-template sync --branch develop

How It Works

  1. Workflow Check: Ensures there are no uncommitted or untracked changes in the current branch.
  2. Fetch Updates: Executes git fetch template.
  3. Merge Attempt: Executes git merge --no-commit template/<branch>.
  4. Apply Ignore Logic:
    • Traverses all paths matched by .syncignore.
    • If a path existed before the sync, it uses git checkout HEAD to restore its content and automatically resolve conflicts.
    • If a path was added by the template, it physically removes the file and clears it from the Git index.
    • Automatic Cleanup: Recursively cleans up empty directories left behind by the removal process.
  5. Finalization: Prompts the user to review the merge result and commit.

Development & Contribution

This project uses Poetry for dependency management.

  • Run Tests: poetry run pytest
  • Linting Check: poetry run ruff check .
  • Format Code: poetry run ruff format .

License

This project is licensed under the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sync_template-0.1.1.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sync_template-0.1.1-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

Details for the file sync_template-0.1.1.tar.gz.

File metadata

  • Download URL: sync_template-0.1.1.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for sync_template-0.1.1.tar.gz
Algorithm Hash digest
SHA256 18a782c91f2a0ac5b70d38d5353e05e0bb15ed8ef859b35a387401f199281291
MD5 8d1954449d6c8659e74c02c4c401cd9a
BLAKE2b-256 42d79f762f4f10e16af45891d1352725949ae963826d142264bc3de8d36b4767

See more details on using hashes here.

Provenance

The following attestation bundles were made for sync_template-0.1.1.tar.gz:

Publisher: publish.yml on XXCC-Unicorn-Press/sync-template

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sync_template-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: sync_template-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 6.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for sync_template-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a62984d3978e4beb05ebff239f69f3e2ad062d58fafd46673d198cc46eb4bf95
MD5 15992597035ecd5892dcbc0d4a9bd840
BLAKE2b-256 fe76f245dad8ab2224a0c15dc85d2e6b2d86d255b518c1d9db4ef164716172b2

See more details on using hashes here.

Provenance

The following attestation bundles were made for sync_template-0.1.1-py3-none-any.whl:

Publisher: publish.yml on XXCC-Unicorn-Press/sync-template

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page