forked from finos/git-proxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit-repos.sh
More file actions
149 lines (121 loc) · 3.92 KB
/
Copy pathinit-repos.sh
File metadata and controls
149 lines (121 loc) · 3.92 KB
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/bin/bash
set -e # Exit on any error
# Create the git repositories directories for multiple owners
BASE_DIR="${BASE_DIR:-"/var/git"}"
OWNERS=("test-owner" "e2e-org")
TEMP_DIR="/tmp/git-init"
# Create base directory and owner subdirectories
mkdir -p "$BASE_DIR"
mkdir -p "$TEMP_DIR"
for owner in "${OWNERS[@]}"; do
mkdir -p "$BASE_DIR/$owner"
done
echo "Creating git repositories in $BASE_DIR for owners: ${OWNERS[*]}"
# Set git configuration for commits
export GIT_AUTHOR_NAME="Git Server"
export GIT_AUTHOR_EMAIL="git@example.com"
export GIT_COMMITTER_NAME="Git Server"
export GIT_COMMITTER_EMAIL="git@example.com"
# Function to create a bare repository in a specific owner directory
create_bare_repo() {
local owner="$1"
local repo_name="$2"
local repo_dir="$BASE_DIR/$owner"
echo "Creating $repo_name in $owner's directory..."
cd "$repo_dir" || exit 1
git init --bare --initial-branch=main "$repo_name"
# Configure for HTTP access
cd "$repo_dir/$repo_name" || exit 1
git config http.receivepack true
git config http.uploadpack true
# Set HEAD to point to main branch
git symbolic-ref HEAD refs/heads/main
cd "$repo_dir" || exit 1
}
# Function to add content to a repository
add_content_to_repo() {
local owner="$1"
local repo_name="$2"
local repo_path="$BASE_DIR/$owner/$repo_name"
local work_dir="$TEMP_DIR/${owner}-${repo_name%-.*}-work"
echo "Adding content to $owner/$repo_name..."
cd "$TEMP_DIR" || exit 1
git clone "$repo_path" "$work_dir"
cd "$work_dir" || exit 1
}
# Create repositories with simple content
echo "=== Creating test-owner/test-repo.git ==="
create_bare_repo "test-owner" "test-repo.git"
add_content_to_repo "test-owner" "test-repo.git"
# Create a simple README
cat > README.md << 'EOF'
# Test Repository
A dummy repository used for GitProxy end-to-end testing.
EOF
# Create a simple text file
cat > hello.txt << 'EOF'
Hello World from test-repo!
EOF
git add .
git commit -m "Initial commit with basic content"
git push origin main
echo "=== Creating e2e-org/sample-repo.git ==="
create_bare_repo "e2e-org" "sample-repo.git"
add_content_to_repo "e2e-org" "sample-repo.git"
# Create a simple README
cat > README.md << 'EOF'
# Sample Repository
A dummy repository used for GitProxy end-to-end testing.
EOF
# Create a simple package.json to simulate a project structure
cat > package.json << 'EOF'
{
"name": "sample-repo",
"version": "1.0.0",
"description": "A sample project for e2e testing",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": ["git", "proxy", "test"],
"author": "Test",
"license": "Apache-2.0"
}
EOF
# Create a simple LICENSE file
cat > LICENSE << 'EOF'
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
SPDX-License-Identifier: Apache-2.0
EOF
git add .
git commit -m "Initial commit with project structure"
git push origin main
echo "=== Repository creation complete ==="
# No copying needed since we're creating specific repos for specific owners
# Clean up temporary directory
echo "Cleaning up temporary files..."
rm -rf "$TEMP_DIR"
echo "=== Repository Summary ==="
for owner in "${OWNERS[@]}"; do
echo "Owner: $owner"
ls -la "$BASE_DIR/$owner"
echo ""
done
# Set proper ownership (only if www-data user exists)
if id www-data >/dev/null 2>&1; then
echo "Setting ownership to www-data..."
chown -R www-data:www-data "$BASE_DIR"
else
echo "www-data user not found, skipping ownership change"
fi
echo "=== Final repository listing with permissions ==="
for owner in "${OWNERS[@]}"; do
echo "Owner: $owner ($BASE_DIR/$owner)"
ls -la "$BASE_DIR/$owner"
echo ""
done
echo "Successfully initialized Git repositories in $BASE_DIR"
echo "Owners created: ${OWNERS[*]}"
echo "Total repositories: $(find $BASE_DIR -name "*.git" -type d | wc -l)"