subgit-init (1153B)
1#!/bin/bash 2 3if [ "$1" = "-r" ]; then 4 recursive=-r 5 shift 6fi 7 8[ $# -ne 0 ] && die "Usage: subgit init" 9 10repo=$(realpath "$(git rev-parse --show-toplevel)") 11source "$repo/.subgitrc" 12 13for subrepo in ${!subgit[@]}; do 14 path="$repo/.subgit/$subrepo" 15 [ -d "$repo/$subrepo" ] || mkdir -p "$repo/$subrepo" 16 if [ ! -d "$path" ]; then 17 mkdir -p "$(dirname "$path")" 18 branch_args=() 19 if [ ! -z "${subgitinfo[$subrepo/branch]}" ]; then 20 branch_args+=(--single-branch -b "${subgitinfo[$subrepo/branch]}") 21 fi 22 git clone --bare "${branch_args[@]}" \ 23 "${subgitinfo[$subrepo/remote]}" "$path" 24 git -C "$path" config --local --bool core.bare false 25 subgit -C "$repo/$subrepo" -- git reset --hard "${subgitinfo[$subrepo/commit]}" 26 elif [ ! -z "${subgitinfo[$subrepo/branch]}" ]; then 27 subgit -C "$repo/$subrepo" -- git checkout "${subgitinfo[$subrepo/branch]}" 28 subgit -C "$repo/$subrepo" -- git reset "${subgitinfo[$subrepo/commit]}" 29 else 30 subgit -C "$repo/$subrepo" -- git checkout "${subgitinfo[$subrepo/commit]}" 31 fi 32 if [ ! -z "$recursive" -a -e "$repo/$subrepo/.subgitrc" ]; then 33 subgit -C "$repo/$subrepo" -- subgit init "$recursive" 34 fi 35done