summaryrefslogtreecommitdiff
path: root/test/setup_test_repos.sh
blob: 786b3f3e532283b3c9bb39ab1f372940b4b58676 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
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"