diff options
| author | Paul Buetow <paul@buetow.org> | 2025-06-23 17:36:03 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2025-06-23 17:36:03 +0300 |
| commit | 8706e6a82819c0c16a0c157283de2f14af2664c3 (patch) | |
| tree | bacf3d7f61e14d0400cb541e36f5ab49de6d7a33 /test | |
| parent | 60691a6fb610cb7f7290d6ab3a26bc74f95af611 (diff) | |
Add repository synchronization functionality
- Create sync package to handle git repository synchronization
- Implement multi-organization sync with branch tracking
- Add merge conflict detection and error handling
- Support cloning, fetching, merging, and pushing across all remotes
- Add --sync flag to synchronize repositories
- Add --work-dir flag for working directory specification
- Create test infrastructure with setup and conflict test scripts
- Update config validation to support file:// URLs
- Add comprehensive .gitignore entries for test artifacts
The sync package automatically:
- Clones repositories if not present
- Fetches updates from all configured organizations
- Merges changes from all remotes for each branch
- Pushes synchronized changes to all organizations
- Detects and reports merge conflicts for manual resolution
Test with: ./test/setup_test_repos.sh && ./gitsyncer --config test/test-config.json --sync test-repo
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
Diffstat (limited to 'test')
| -rwxr-xr-x | test/setup_test_repos.sh | 107 | ||||
| -rwxr-xr-x | test/test_conflict.sh | 42 |
2 files changed, 149 insertions, 0 deletions
diff --git a/test/setup_test_repos.sh b/test/setup_test_repos.sh new file mode 100755 index 0000000..786b3f3 --- /dev/null +++ b/test/setup_test_repos.sh @@ -0,0 +1,107 @@ +#!/bin/bash + +# Setup script for creating test git repositories +set -e + +echo "Setting up test repositories..." + +# Create test directory structure +TEST_DIR="$(cd "$(dirname "$0")" && pwd)" +REPOS_DIR="$TEST_DIR/repos" +mkdir -p "$REPOS_DIR" + +# Create two bare repositories (simulating remote repos) +REPO1_DIR="$REPOS_DIR/org1" +REPO2_DIR="$REPOS_DIR/org2" + +# Clean up if they exist +rm -rf "$REPO1_DIR" "$REPO2_DIR" +mkdir -p "$REPO1_DIR" "$REPO2_DIR" + +# Initialize bare repositories +echo "Creating bare repository in org1..." +cd "$REPO1_DIR" +git init --bare test-repo.git + +echo "Creating bare repository in org2..." +cd "$REPO2_DIR" +git init --bare test-repo.git + +# Create a temporary working directory to add initial content +WORK_DIR="$REPOS_DIR/work" +rm -rf "$WORK_DIR" +mkdir -p "$WORK_DIR" + +# Clone from org1 and add initial content +echo "Adding initial content..." +cd "$WORK_DIR" +git clone "$REPO1_DIR/test-repo.git" +cd test-repo + +# Create initial files +echo "# Test Repository" > README.md +echo "This is a test repository for gitsyncer" >> README.md + +mkdir -p src +echo "package main + +import \"fmt\" + +func main() { + fmt.Println(\"Hello from test repo!\") +}" > src/main.go + +# Create initial commit +git add . +git commit -m "Initial commit" + +# Create develop branch +git checkout -b develop +echo "Development branch" > DEVELOP.md +git add DEVELOP.md +git commit -m "Add develop branch marker" + +# Create feature branch +git checkout -b feature/test-feature +echo "Feature content" > feature.txt +git add feature.txt +git commit -m "Add feature" + +# Push all branches to org1 +git push origin main +git push origin develop +git push origin feature/test-feature + +# Add org2 as remote and push only main branch initially +git remote add org2 "$REPO2_DIR/test-repo.git" +git checkout main +git push org2 main + +# Clean up work directory +cd "$TEST_DIR" +rm -rf "$WORK_DIR" + +# Create test config file +echo "Creating test configuration..." +cat > "$TEST_DIR/test-config.json" << EOF +{ + "organizations": [ + { + "host": "file://$REPO1_DIR", + "name": "" + }, + { + "host": "file://$REPO2_DIR", + "name": "" + } + ] +} +EOF + +echo "Test setup complete!" +echo "" +echo "Repository structure:" +echo "- org1/test-repo.git: Has main, develop, and feature/test-feature branches" +echo "- org2/test-repo.git: Has only main branch" +echo "" +echo "Test config file created at: $TEST_DIR/test-config.json"
\ No newline at end of file diff --git a/test/test_conflict.sh b/test/test_conflict.sh new file mode 100755 index 0000000..d63375c --- /dev/null +++ b/test/test_conflict.sh @@ -0,0 +1,42 @@ +#!/bin/bash + +# Test script to demonstrate merge conflict handling +set -e + +echo "Testing merge conflict detection..." + +TEST_DIR="$(cd "$(dirname "$0")" && pwd)" +REPOS_DIR="$TEST_DIR/repos" +WORK_DIR="$REPOS_DIR/conflict-work" + +# Clean up and create work directories +rm -rf "$WORK_DIR" +mkdir -p "$WORK_DIR" + +# Clone both repos to create conflicting changes +echo "Creating conflicting changes in org1..." +cd "$WORK_DIR" +git clone "$REPOS_DIR/org1/test-repo.git" work1 +cd work1 +echo "Change from org1" > conflict.txt +git add conflict.txt +git commit -m "Add conflict.txt from org1" +git push origin main + +echo "Creating conflicting changes in org2..." +cd "$WORK_DIR" +git clone "$REPOS_DIR/org2/test-repo.git" work2 +cd work2 +echo "Different change from org2" > conflict.txt +git add conflict.txt +git commit -m "Add conflict.txt from org2" +git push origin main + +# Clean up work directories +cd "$TEST_DIR" +rm -rf "$WORK_DIR" + +echo "" +echo "Conflicting changes created!" +echo "Now run gitsyncer to see conflict detection:" +echo " ./gitsyncer --config test/test-config.json --sync test-repo --work-dir test/work-conflict"
\ No newline at end of file |
