Thank you for your interest in contributing to Twin! This guide covers development setup, testing, and contribution guidelines.
- bash
- rsync
- python3
- git
- make
- SSH access to a test remote (for integration tests)
git clone https://github.com/your-username/twin.git
cd twinYou can test Twin without installing it system-wide:
# Run from source
./twin -h
# Test with local remote (same machine)
./twin localhost ~/test-targetTwin includes multiple test suites to ensure reliability.
Before running tests, configure your test environment:
# Copy example environment file
cp .env.example .env
# Edit .env and set your test remote
nano .envSet the following variable:
TWIN_TEST_REMOTE=your-test-serverexport TWIN_TEST_REMOTE=your-test-serverEnsure you have SSH access to the test remote:
# Should connect without password
ssh your-test-server exit
# Configure in ~/.ssh/config if needed
Host your-test-server
HostName example.com
User testuser
IdentityFile ~/.ssh/id_ed25519Tests basic functionality without requiring remote access:
make testTests include:
- Installation/uninstallation
- Argument parsing
- Error handling
- Flag combinations
- Help text generation
Expected output:
=== Twin Test Suite ===
[PASS] make install should succeed
[PASS] twin binary should exist after install
...
Total tests: 8
Passed: 12
Failed: 0
Tests real rsync operations with a remote server:
make test-integrationRequirements:
TWIN_TEST_REMOTEenvironment variable set- SSH access to test remote
- Write permissions on test remote
Tests include:
- Basic file synchronization
- Directory sync
- Pull-back functionality
- Custom rsync flags
- Remote directory creation
Expected output:
=== Integration Tests ===
[PASS] Files sync correctly
[PASS] Directories sync correctly
...
Tests configuration file functionality:
./test_config.shTests include:
- Config file creation
- Saved paths and flags
- Multiple directory pairings
- Config persistence
Tests git remote setup functionality:
./test_git.shTests include:
- Git repository detection
- Remote setup and configuration
- Conflict handling
- SSH config parsing
- Non-git directory handling
- Config persistence
Expected output:
======================================
Twin Git Integration Test Suite
======================================
[PASS] Git repository detection - local
[PASS] Configuration schema - git integration fields
...
Total tests: 10
Passed: 15
Failed: 0
All tests passed!
# Unit tests only
make test
# Include integration tests (requires test remote)
make test && make test-integration && ./test_config.sh && ./test_git.shtwin/
├── twin # Main bash script (sync logic, git integration)
├── twin-config # Python config manager (JSON read/write)
├── test_twin.sh # Unit tests
├── test_integration.sh # Integration tests
├── test_config.sh # Config persistence tests
├── test_git.sh # Git integration tests
├── Makefile # Installation and test targets
├── README.md # User-facing documentation
├── CONTRIBUTING.md # This file
└── docs/ # Detailed documentation
├── git-integration.md
├── advanced-usage.md
├── ssh-setup.md
└── troubleshooting.md
The main twin bash script is organized into sections:
- Default values (lines 12-24): Configuration variables
- Helper functions (lines 26-221): Git detection, SSH parsing, prompts
- show_help() (lines 223-257): Help text
- Argument parsing (lines 259-325): Command-line flags
- Configuration loading (lines 337-363): Read saved config
- SSH testing (lines 370-376): Verify connection
- Git integration (lines 390-452): Set up git remotes
- Rsync execution (lines 454-468): Perform sync
Python script for JSON configuration management:
- get_config_filename(): Generate config filename
- read_config(): Read JSON from file
- write_config(): Write/update JSON
- main(): CLI argument handling
-
Create feature branch:
git checkout -b feature/my-feature
-
Make changes:
- Edit
twinfor bash functionality - Edit
twin-configfor config management - Add tests for new features
- Edit
-
Test changes:
make test ./test_git.sh # Test manually ./twin -h
-
Commit changes:
git add . git commit -m "feat: Add new feature"
- Indent with 4 spaces
- Use meaningful variable names
- Add comments for complex logic
- Quote variables:
"$VARIABLE" - Use
set -efor error handling - Functions before usage
Example:
# Good
check_remote_git_repo() {
local remote="$1"
local path="$2"
ssh "$remote" "[ -d '$path/.git' ]" 2>/dev/null
}
# Avoid
check_remote_git_repo() {
local remote=$1; local path=$2
ssh $remote [ -d $path/.git ] 2>/dev/null
}- Follow PEP 8
- Use 4-space indentation
- Add docstrings to functions
- Type hints encouraged
Example:
def read_config(remote: str, directory: str = None) -> dict:
"""Read configuration for a remote from the current or specified directory"""
# Implementation- Add unit tests to
test_twin.sh - Add integration tests if feature uses SSH/rsync
- Add git tests to
test_git.shif feature affects git integration - Document in appropriate docs file
When adding features:
- Update README.md if core functionality changes
- Add to appropriate guide:
- Git features →
docs/git-integration.md - Advanced rsync →
docs/advanced-usage.md - SSH config →
docs/ssh-setup.md
- Git features →
- Update help text in
twinscript - Add examples showing usage
-
Run all tests:
make test ./test_config.sh ./test_git.sh -
Check for shellcheck warnings (if available):
shellcheck twin
-
Test manually:
# Test basic functionality ./twin -h ./twin testserver /tmp/test -
Update documentation
-
Push to your fork:
git push origin feature/my-feature
-
Create pull request on GitHub
-
Describe changes:
- What problem does it solve?
- How does it work?
- Any breaking changes?
- Test coverage
-
Link related issues
- Tests pass
- Code follows style guidelines
- Documentation updated
- No breaking changes (or clearly documented)
- Commit messages are clear
- Feature is backwards compatible
We review PRs for:
- Functionality: Does it work as intended?
- Tests: Are there adequate tests?
- Documentation: Is it documented?
- Code quality: Is it readable and maintainable?
- Compatibility: Does it work across environments?
(For maintainers)
- Update version number
- Update CHANGELOG.md
- Tag release:
git tag v1.2.3 - Push tag:
git push origin v1.2.3 - Create GitHub release
- Open an issue for bugs or feature requests
- Start a discussion for questions
- Check existing issues before creating new ones
Thank you for contributing to Twin!