#!/usr/bin/env bash

set -e

while read -r git_folder; do
	repo_folder=$(dirname $git_folder)
	full_path=$(realpath $repo_folder)
	repo_name=$(basename "$full_path")
	# Un-comment the following for a visual representation of what the above shit do
	# echo "┌────────────────┬────────────────────────────────┐"
	# echo "│ Variable Name  │ Variable Result                │"
	# echo "├────────────────┼────────────────────────────────┘"
	# echo "│ git_folder     │ $git_folder"
	# echo "│ repo_folder    │ $repo_folder"
	# echo "│ full_path      │ $full_path"
	# echo "│ repo_name      │ $repo_name"
	# echo "└────────────────┘"
	(
		output=$(
			{
				echo "──────────────── ℹ️  Pulling $repo_name ℹ️  ────────────────"
				git -C "$full_path" add .
				git -C "$full_path" status
				echo "──────────────── ℹ️  Pulled $repo_name ℹ️  ─────────────────"
			} 2>&1
		)
		echo "$output"
	) &
done < <(find . -name ".git" -type d)

wait
