-
Notifications
You must be signed in to change notification settings - Fork 2
/
origin_gitee.sh
31 lines (31 loc) · 1.26 KB
/
origin_gitee.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
dir=$(pwd)
echo "[echo] --------$dir-----------"
# 检查是否存在.git目录或.git配置文件
if [ -d ".git" ] || [ -f ".git" ]; then
#如果pushgitee不存在,则先补充pushgitee
is_pushgitee_exist=$(git config --get alias.pushgitee)
if [ -z "$is_pushgitee_exist" ]; then
echo "[echo] 不存在[alias]:pushgitee"
currentProject=$(basename "$(pwd)")
git config alias.pushgitee "push --force git@gitee.com:neat-logic/$currentProject.git"
fi
# 获取origin的URL和pushgitee的URL
origin_url=$(git remote get-url origin)
pushgitee_url=$(git config alias.pushgitee | sed 's/push --force //')
#如果origin不是gitee
pattern="git@gitee.com"
if [[ ! $origin_url == *$pattern* ]]; then
# 如果这两个URL都存在,则交换它们
if [ ! -z "$origin_url" ] && [ ! -z "$pushgitee_url" ]; then
git remote set-url origin "$pushgitee_url"
git config alias.pushgitee "push --force $origin_url"
echo "[echo] origin_url: $origin_url"
echo "[echo] pushgitee_url: $pushgitee_url"
else
echo "[echo] Missing origin or pushgitee URL in $dir"
fi
fi
else
echo "[echo] No git repository in $dir"
fi
echo "[echo] ----------------------"