forked from google/adk-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit_tool_tui.sh
More file actions
executable file
·138 lines (131 loc) · 4.34 KB
/
Copy pathgit_tool_tui.sh
File metadata and controls
executable file
·138 lines (131 loc) · 4.34 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
#!/bin/bash
while true; do
echo "========================================"
echo " Git 操作選單"
echo "========================================"
echo "1) 初始化主專案 remote 與 submodules(已 clone)"
echo "2) 初始化 submodules(含檢查)"
echo "3) 從 upstream 更新(含 submodules)"
echo "4) 推送至 GitHub(含 submodules)"
echo "X) 離開"
echo "========================================"
read -p "請輸入操作項目: " choice
case "$choice" in
1)
echo "[INFO] 設定主 repo upstream..."
if ! git remote get-url upstream > /dev/null 2>&1; then
read -p "請輸入 upstream URL: " upstreamURL
git remote add upstream "$upstreamURL"
else
echo "[INFO] upstream 已存在,略過。"
fi
if [ -f "submodules_config.txt" ]; then
echo "[INFO] 初始化 submodules..."
while read -r line; do
set -- $line
subPath="$1"
originURL="$2"
upstreamURL="$3"
if [ -z "$(git config -f .gitmodules --get submodule.${subPath}.url)" ]; then
git submodule add "$originURL" "$subPath"
else
echo "[INFO] submodule $subPath 已存在,略過。"
fi
done < submodules_config.txt
git submodule init
git submodule update --remote --merge
else
echo "[INFO] 無 submodules_config.txt,略過。"
fi
;;
2)
if [ -f ".gitmodules" ]; then
read -p "[INFO] 偵測到 submodule 記錄,是否重新初始化?(Y/N): " redo
if [[ ! "$redo" =~ ^[Yy]$ ]]; then
echo "[INFO] 已取消初始化。"
continue
fi
fi
if [ -f "submodules_config.txt" ]; then
echo "[INFO] 開始初始化 submodules..."
while read -r line; do
set -- $line
subPath="$1"
originURL="$2"
upstreamURL="$3"
if [ -z "$(git config -f .gitmodules --get submodule.${subPath}.url)" ]; then
git submodule add "$originURL" "$subPath"
fi
done < submodules_config.txt
git submodule init
git submodule update --remote --merge
else
echo "[INFO] 未找到 submodules_config.txt"
fi
;;
3)
echo "[INFO] 更新主專案..."
if ! git remote get-url upstream > /dev/null 2>&1; then
read -p "請輸入 upstream URL: " upstreamURL
git remote add upstream "$upstreamURL"
fi
git fetch upstream
git pull upstream main --allow-unrelated-histories
if [ -f "submodules_config.txt" ]; then
while read -r line; do
set -- $line
subPath="$1"
originURL="$2"
upstreamURL="$3"
if [ -d "$subPath" ]; then
cd "$subPath"
git remote set-url origin "$originURL"
if ! git remote get-url upstream > /dev/null 2>&1; then
git remote add upstream "$upstreamURL"
else
git remote set-url upstream "$upstreamURL"
fi
git checkout main
git fetch upstream
git pull upstream main
cd ..
fi
done < submodules_config.txt
fi
;;
4)
read -p "請輸入 commit 訊息(預設:更新): " commitMsg
[ -z "$commitMsg" ] && commitMsg="更新"
timestamp=$(date "+%Y-%m-%d_%H-%M")
echo "Commit Log - $timestamp" > commit_log.txt
echo "-------------------------" >> commit_log.txt
if [ -f "submodules_config.txt" ]; then
echo "[INFO] 推送 submodules..."
while read -r line; do
set -- $line
subPath="$1"
if [ -d "$subPath" ]; then
cd "$subPath"
git add .
git commit -m "$commitMsg - $timestamp" 2>/dev/null
git push origin main
echo "[submodule] $subPath 已提交:$commitMsg - $timestamp" >> ../commit_log.txt
cd ..
fi
done < submodules_config.txt
fi
echo "[INFO] 提交主專案"
git add .
git commit -m "$commitMsg - $timestamp" 2>/dev/null
git push origin main
echo "[main] 主專案已提交:$commitMsg - $timestamp" >> commit_log.txt
;;
X|x)
echo "👋 Bye!"
break
;;
*)
echo "❌ 無效的選項,請重新選擇"
;;
esac
done