summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2022-07-02 19:33:11 +0300
committerPaul Buetow <paul@buetow.org>2022-07-02 19:33:11 +0300
commitb733f1860f00c61eb33ff33c4368201a4c8161d9 (patch)
treee8c35461bc445e4b57d9fa68566301f84c251a12 /lib
parent30f00fa694280a7eaa23c20affba22bd14b91739 (diff)
add new git options
Diffstat (limited to 'lib')
-rw-r--r--lib/git.source.sh55
1 files changed, 55 insertions, 0 deletions
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 -
+}
+