From b733f1860f00c61eb33ff33c4368201a4c8161d9 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sat, 2 Jul 2022 19:33:11 +0300 Subject: add new git options --- lib/git.source.sh | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 lib/git.source.sh (limited to 'lib/git.source.sh') diff --git a/lib/git.source.sh b/lib/git.source.sh new file mode 100644 index 0000000..67dc93e --- /dev/null +++ b/lib/git.source.sh @@ -0,0 +1,55 @@ +git::_content_dirs_in_git () { + find "$CONTENT_BASE_DIR" -maxdepth 1 -mindepth 1 -type d | + while read -r content_dir; do + if [ -d "$content_dir/.git" ]; then + echo "$content_dir" + fi + done +} + +git::add_all () { + local message="$1"; shift + if [ -z "$message" ]; then + message='Update content' + fi + + git::_content_dirs_in_git | while read -r content_dir; do + log INFO "Adding content from $content_dir to git" + git::_add_all "$message" "$content_dir" & + done + wait +} + +git::_add_all () { + local -r message="$1"; shift + local -r content_dir="$1"; shift + cd "$content_dir" + + find . -type f -not -path '*/\.git*' | while read -r file; do + git add "$file" + done + + local -r format="$(basename "$content_dir")" + git commit -a -m "$message for $format" + + cd - +} + +git::sync_all () { + git::_content_dirs_in_git | while read -r content_dir; do + log INFO "Synchronizing content from $content_dir with remote git" + git::_sync_all "$content_dir" + done +} + +git::_sync_all () { + local -r content_dir="$1"; shift + cd "$content_dir" + + git pull + git push + git status + + cd - +} + -- cgit v1.2.3