-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_repo.sh
More file actions
87 lines (70 loc) · 1.95 KB
/
Copy pathcreate_repo.sh
File metadata and controls
87 lines (70 loc) · 1.95 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
#!/bin/bash
# Check if repo list file is provided
if [ $# -ne 2 ]; then
echo "Usage: $0 <repo_list_file> <organization_name>"
exit 1
fi
REPO_FILE=$1
ORG_NAME=$2
# Check if repo file exists
if [ ! -f "$REPO_FILE" ]; then
echo "Error: File '$REPO_FILE' not found!"
exit 1
fi
# Prompt for GitHub username
read -p "Enter GitHub Username: " USERNAME
# Prompt for GitHub token (hidden)
read -s -p "Enter GitHub Token: " TOKEN
echo ""
# Save current directory
BASE_DIR=$(pwd)
# Arrays to track success and failures
success_repos=()
failed_repos=()
while IFS= read -r REPO
do
# Skip empty lines
[ -z "$REPO" ] && continue
echo "----------------------------------"
echo "Processing repository: $REPO"
# Remove trailing .git if already present for constructing URL
if [[ "$REPO" == *.git ]]; then
REMOTE_REPO="${REPO%.git}"
else
REMOTE_REPO="$REPO"
fi
# Check if local directory exists
if [ ! -d "$BASE_DIR/$REPO" ]; then
echo "ERROR: Local directory '$REPO' does not exist"
failed_repos+=("$REPO (local missing)")
continue
fi
cd "$BASE_DIR/$REPO" || {
echo "ERROR: Cannot cd into '$REPO'"
failed_repos+=("$REPO (cd failed)")
continue
}
# Push all branches, tags, and refs
git push --mirror "https://$USERNAME:$TOKEN@github.com/$ORG_NAME/$REMOTE_REPO.git"
if [ $? -eq 0 ]; then
echo "SUCCESS: '$REPO' pushed successfully"
success_repos+=("$REPO")
else
echo "FAILED: '$REPO' push failed"
failed_repos+=("$REPO (push failed)")
fi
# Return to base directory
cd "$BASE_DIR"
done < "$REPO_FILE"
# Summary
echo "=================================="
echo "PROCESS COMPLETED"
echo "Successful repositories:"
for repo in "${success_repos[@]}"; do
echo " - $repo"
done
echo "Failed repositories:"
for repo in "${failed_repos[@]}"; do
echo " - $repo"
done
echo "=================================="