subgit

Git-submodule alternative with vendoring and multiple remotes
git clone https://git.sinitax.com/sinitax/subgit
Log | Files | Refs | sfeed.txt

subgit-add (987B)


      1#!/bin/bash
      2
      3[ $# -lt 2 ] && die "Usage: subgit clone [GIT-OPT..] REMOTE PATH"
      4
      5repo=$(realpath "$(git rev-parse --show-toplevel)")
      6subrepo=$(realpath "${@: -1}")
      7subrepo=${subrepo#$repo/}
      8
      9[ ! -z "$subrepo" -a "$subrepo" != "/" ]
     10
     11if [ -e "$repo/.subgitrc" ]; then
     12	source "$repo/.subgitrc"
     13else
     14	declare -A subgit subgitinfo
     15fi
     16
     17[ -e "$repo/$subrepo" ] && die "Subrepo $subrepo already exists"
     18
     19trap '[ ! -z "$repo" -a ! -z "$subrepo" ] && rm -rf "$repo/$subrepo"' exit
     20git clone "$@"
     21
     22[ ! -e "$repo/$subrepo" ] && die "Subrepo $subrepo missing"
     23
     24mkdir -p $(dirname "$repo/.subgit/$subrepo")
     25rm -rf "$repo/.subgit/$subrepo"
     26mv "$repo/$subrepo/.git" "$repo/.subgit/$subrepo"
     27
     28subgit[$subrepo]=1
     29subgitinfo[$subrepo/remote]=$(git -C "$repo/.subgit/$subrepo" remote get-url origin)
     30subgitinfo[$subrepo/branch]=$(git -C "$repo/.subgit/$subrepo" branch --show-current)
     31subgitinfo[$subrepo/commit]=$(git -C "$repo/.subgit/$subrepo" rev-parse --verify HEAD)
     32
     33source subgit-write
     34
     35trap - exit