1
0
Fork 0
dispatcher/bash_scripts/repo_local.tmpl.sh
2025-02-28 19:13:07 +03:00

38 lines
2.1 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/false
if [[ -z "$domain" || -z "$owner" || -z "$repo" || -z "$dir" ]]; then
echo "Не указаны обязательные параметры." && exit 1
fi
echo "Создание локального репозитория, подключение к удалённому и передача данных."
time_ms="$(date '+%s%3N')"
# строка исключений для "find" из списка неотслеживаемых файлов ".gitignore"
exclusions="-not -path '*/.git/*' $(sed -E "s|^(.*)$|-not -path '*/\1*'|" .gitignore | tr '\n' ' ')"
# перевести размеры файла в человеко-читаемую строку, отбросить нули из дробной части и добавить пробел
function BKM { numfmt --to=iec --format="%.2f" --suffix="B" "$1" | sed -r 's|,{,1}0{,2}([BKM])| \1|'; }
rm -rf .git
git init -b master
git remote add "$domain" "git@$domain:$owner/$repo.git"
git add .git*
git commit -m "Инициализация / $dir"
if [ "$domain" == "hub.mos.ru" ]; then
echo "Второй пуш, потому что лингвист с первого раза не срабатывает."
git push -u "$domain" master
fi
find . -type f | grep -E 'CONTRIBUTING|LICENSE' | xargs git add
git commit -m "Открытая лицензия РФ"
find . -type f -name '*.md' | grep -E 'TREE|WIKI|README|VIEW' | xargs git add
git commit -m "Описание проекта"
find . -type f | grep -E '(yml|Gemfile.*|gemspec|robots.txt)$' | xargs git add
git commit -m "Настройки"
git add \*.sh
git commit -m "Скрипты bash"
find . -type f | grep -E '(min.css|min.js|woff)$' | xargs git add
git commit -m "Сторонние материалы"
find . -type f | grep -E '(bmp|gif|ico|jpg|png|svg)$' | xargs git add
git commit -m "Картинки"
while read -r file size; do
echo "Обработка: $file"
git add "$file"
git commit -m "${file#*/} / $(BKM "$size")"
done < <(eval "find . -type f $exclusions -printf '%p %s\n'" | LC_COLLATE=C sort -r)
git push -u "$domain" master
echo "Общее время выполнения: $(($(date '+%s%3N') - time_ms)) мс."