-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathforce-push_helper.sh
136 lines (118 loc) Β· 5.48 KB
/
force-push_helper.sh
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
#!/bin/bash
declare -A REPOS=(
["build/make"]="[email protected]:P-404/android_build.git"
["build/soong"]="[email protected]:P-404/android_build_soong.git"
["bootable/recovery"]="[email protected]:P-404/android_bootable_recovery.git"
["bionic"]="[email protected]:P-404/android_bionic.git"
["device/qcom/common"]="[email protected]:P-404/android_device_qcom_common.git"
["device/404/sepolicy"]="[email protected]:P-404/android_device_404_sepolicy.git"
["device/qcom/sepolicy_vndr"]="[email protected]:P-404/android_device_qcom_sepolicy_vndr.git"
["device/qcom/kernelscripts"]="[email protected]:P-404/android_kernel_build.git"
["external/fastrpc"]="[email protected]:P-404/android_external_fastrpc.git"
["external/json-c"]="[email protected]:P-404/android_external_json-c.git"
["external/tinycompress"]="[email protected]:P-404/android_external_tinycompress.git"
["hardware/libhardware"]="[email protected]:P-404/android_hardware_libhardware.git"
["hardware/qcom/wlan"]="[email protected]:P-404/android_hardware_qcom_wlan.git"
["hardware/st/nfc"]="[email protected]:P-404/android_hardware_st_nfc.git"
["hardware/lineage/compat"]="[email protected]:P-404/android_hardware_lineage_compat.git"
["manifest"]="[email protected]:P-404/android_manifest.git"
["system/core"]="[email protected]:P-404/android_system_core.git"
["vendor/qcom/opensource/softap"]="[email protected]:P-404/android_vendor_qcom_opensource_softap.git"
["vendor/404"]="[email protected]:P-404/android_vendor_404.git"
["vendor/overlays/404"]="[email protected]:P-404/android_vendor_overlays_404.git"
["vendor/qcom/common"]="[email protected]:P-404/proprietary_vendor_qcom_common.git"
["vendor/qcom/sdclang"]="[email protected]:P-404/proprietary_vendor_qcom_sdclang.git"
["vendor/qcom/opensource/commonsys-intf/display"]="[email protected]:P-404/android_vendor_qcom_opensource_commonsys-intf_display.git"
["vendor/qcom/opensource/commonsys/display"]="[email protected]:P-404/android_vendor_qcom-opensource_display-commonsys.git"
["vendor/qcom/opensource/commonsys-intf/bluetooth"]="[email protected]:P-404/android_vendor_qcom-opensource_bluetooth-commonsys-intf.git"
["vendor/qcom/opensource/commonsys-intf/wfd"]="[email protected]:P-404/android_vendor_qcom_opensource_commonsys-intf_wfd.git"
["vendor/qcom/opensource/data-ipa-cfg-mgr"]="[email protected]:P-404/android_vendor_qcom_opensource_data-ipa-cfg-mgr.git"
["vendor/qcom/opensource/data-ipa-cfg-mgr-legacy"]="[email protected]:P-404/android_vendor_qcom_opensource_data-ipa-cfg-mgr.git"
["vendor/qcom/opensource/power"]="[email protected]:P-404/android_vendor_qcom-opensource_power.git"
["vendor/qcom/opensource/dataservices"]="[email protected]:P-404/android_vendor_qcom-opensource_dataservices.git"
["vendor/qcom/opensource/vibrator"]="[email protected]:P-404/android_vendor_qcom-opensource_vibrator.git"
)
GREEN='\033[0;32m'
RED='\033[0;31m'
NC='\033[0m'
REMOTE_NAME="404"
REVISION="vito"
echo -n "Enter the branch name you want to create and force push: "
read BRANCH_NAME
if [ -z "$BRANCH_NAME" ]; then
echo -e "${RED}Error: Branch name cannot be empty${NC}"
exit 1
fi
success_count=0
failed_count=0
failed_paths=()
for path in "${!REPOS[@]}"; do
echo -e "\n${GREEN}Processing: $path${NC}"
if [ ! -d "$path" ]; then
mkdir -p "$path"
git clone "${REPOS[$path]}" "$path"
if [ $? -ne 0 ]; then
echo -e "${RED}Failed to clone repository for $path${NC}"
((failed_count++))
failed_paths+=("$path")
continue
fi
fi
cd "$path" || {
echo -e "${RED}Failed to change directory to $path${NC}"
((failed_count++))
failed_paths+=("$path")
continue
}
# Remove existing remotes and add new one
git remote remove origin 2>/dev/null
git remote remove 404 2>/dev/null
if ! git remote add "${REMOTE_NAME}" "${REPOS[$path]}"; then
echo -e "${RED}Failed to set remote for $path${NC}"
((failed_count++))
failed_paths+=("$path")
cd - > /dev/null
continue
fi
# Fetch from new remote
git fetch "${REMOTE_NAME}" || {
echo -e "${RED}Failed to fetch from remote for $path${NC}"
((failed_count++))
failed_paths+=("$path")
cd - > /dev/null
continue
}
# Try to checkout vito branch first
git checkout "${REMOTE_NAME}/${REVISION}" 2>/dev/null || {
echo -e "${RED}Failed to checkout ${REVISION} branch for $path${NC}"
((failed_count++))
failed_paths+=("$path")
cd - > /dev/null
continue
}
if ! git checkout -b "$BRANCH_NAME" 2>/dev/null; then
if ! git checkout "$BRANCH_NAME" 2>/dev/null; then
echo -e "${RED}Failed to create/checkout branch $BRANCH_NAME${NC}"
((failed_count++))
failed_paths+=("$path")
cd - > /dev/null
continue
fi
fi
if git push -f "${REMOTE_NAME}" "$BRANCH_NAME"; then
echo -e "${GREEN}Successfully processed $path${NC}"
((success_count++))
else
echo -e "${RED}Failed to force push in $path${NC}"
((failed_count++))
failed_paths+=("$path")
fi
cd - > /dev/null
done
echo -e "\n${GREEN}=== Operation Summary ===${NC}"
echo -e "${GREEN}Successfully processed: $success_count repositories${NC}"
echo -e "${RED}Failed: $failed_count repositories${NC}"
if [ ${#failed_paths[@]} -gt 0 ]; then
echo -e "\n${RED}Failed paths:${NC}"
printf '%s\n' "${failed_paths[@]}"
fi