#!/bin/bash add-git-folder() { if [[ -z "$1" ]]; then echo '$1/url is empty.' exit fi if [[ -z "$2" ]]; then echo '$2/branch is empty.' exit fi if [[ -z "$3" ]]; then echo '$3/path is empty.' exit fi local url="$1" local branch="$2" local path="$3" local current_branch=$(git -C "$path" rev-parse --abbrev-ref HEAD) if [[ "$current_branch" != "$branch" ]]; then echo "Error: Repository is on branch '$current_branch', expected '$branch'" exit 1 fi # Add entry to .gitmodules git config -f .gitmodules submodule."$path".path "$path" git config -f .gitmodules submodule."$path".url "$url" git config -f .gitmodules submodule."$path".branch "$branch" # Save commit ref save-git-folder }