1 Star 0 Fork 1

Mayfool/gitbash

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
batch_get_remote.sh 1.75 KB
一键复制 编辑 原始数据 按行查看 历史
Mayfool 提交于 2024-07-28 21:31 . 1、修改git目录获取
#!/usr/bin/env bash
# -*- coding: utf-8 -*-
#
# 获取文件夹内所有git项目的remote url并生成文件remote.txt
# @author: 徐宙
# @date: 2020-12-08
# 获取脚本的全路径
script_path="$(realpath $0)"
# 提取脚本所在的目录
bash_dir="$(dirname $script_path)"
base_dir=$(pwd)
source "$bash_dir/git_common.sh"
source "$bash_dir/task_common.sh"
flag=0
projects=()
# 初始化结果文件
res_file=remote.txt
echo >$res_file
function usage() {
cat "$bash_dir/usage/batch_pull.usage"
}
function get_remote_with_project() {
project=$1
# 打开文件夹
cd "$base_dir/$project" || return $FAILED
curr_dir=$(pwd)
success_log "当前目录:$curr_dir"
# 查看当前分支
remote_url=`git_get_remote`
if [ $? != $SUCCESS ]; then
return $FAILED
fi
if [ "$remote_url" == '' ]; then
error_log "无远程仓库"
return $FAILED
fi
echo "$remote_url"
echo "$(basename "$project") $remote_url" >>"$base_dir/$res_file"
}
function batch_get_remote() {
for i in "${!projects[@]}";
do
project=${projects[$i]}
get_remote_with_project $project
success_log "-----------------------"
success_log
done
cat "$base_dir/$res_file" | sort | uniq>"$base_dir/$res_file"
success_log $base_dir"/"$res_file"内容如下"
cat "$base_dir/$res_file"
}
function main() {
# 解析参数
parameters=`getopt -o hy -n "$0" -- "$@"`
[ $? != 0 ] && exit 1
eval set -- "$parameters"
while true ; do
case "$1" in
-h) usage; exit 0 ;;
-y) flag=1; shift ;;
--) shift; break ;;
*) usage; exit 1 ;;
esac
done
projects=($(git_directories))
batch_get_remote
exit 0
}
main "$@"
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Shell
1
https://gitee.com/mayfool/gitbash.git
git@gitee.com:mayfool/gitbash.git
mayfool
gitbash
gitbash
master

搜索帮助