From 4d6653ecc3506d237c8f8eb9152e610bf84ca7be Mon Sep 17 00:00:00 2001 From: William Hilton Date: Sun, 29 Nov 2015 21:45:54 -0500 Subject: [PATCH] Initial support for git submodules. --- bin/get | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/bin/get b/bin/get index 6656824..0ae69c3 100755 --- a/bin/get +++ b/bin/get @@ -9,6 +9,10 @@ list_remote_branches() { git for-each-ref refs/heads --format="%(refname:short)" } +git_root() { + git rev-parse --show-toplevel +} + case "$1" in '?' | status) # TODO: Display help if not inside a repo @@ -300,6 +304,34 @@ git log --color \ --abbrev-commit -10 "${@:2}" ;; +submodule) +CWD=$(pwd) +gitroot=$(git_root) +shopt -s globstar +# For every git repository found within... +for dir in $gitroot/*/**/.git +do + cd "$dir" + # Get relative directory name + reldir=${dir#$gitroot/} + reldir=${reldir%/.git} + echo "[submodule \"$reldir\"]" + # Get local branch name + local_branch=$(git rev-parse --abbrev-ref HEAD) + # Get associated remote + remote=$(git config --get branch.$local_branch.remote) + # Get url of remote + url=$(git config --get remote.$remote.url) + echo "url = $url" + cd "$gitroot" + git submodule add "$url" "$reldir" + echo '' +done +cd "$gitroot" +git submodule init +cd "$CWD" +;; + *) echo "Passing args straight to git..." git $@