Skip to content

Instantly share code, notes, and snippets.

@jeeftor
Created July 6, 2019 17:35
Show Gist options
  • Save jeeftor/e7a07f10a38be1b7fa20e41fae88a4bc to your computer and use it in GitHub Desktop.
Save jeeftor/e7a07f10a38be1b7fa20e41fae88a4bc to your computer and use it in GitHub Desktop.
Sub Module Log
#!/bin/bash
# This function will parse out the gitModules file to extrac the list of sub module names
function getSubs () {
git config --file=.gitmodules -l | cut -d '.' -f2 | sort -u | xargs
}
# Get a list of all the sub modules
SUBS=$(getSubs) #$(git config --file=.gitmodules -l | cut -d '.' -f2 | sort -u | xargs)
function getSubLog {
# This takes two paramaters a submodule name and an output variable to store the log in
# You call with getSubLog sub_module result_var
# https://www.linuxjournal.com/content/return-values-bash-functions
sub=$1
local __resultvar=$2
local ret=''
local sub_branch=$(git config --file=.gitmodules --get submodule.$sub.branch)
local sub_url=$(git config --file=.gitmodules --get submodule.$sub.url)
local sub_path=$(git config --file=.gitmodules --get submodule.$sub.path)
local remote_sha=$(git ls-remote -q $sub_url $sub_branch | xargs | cut -d" " -f1)
local local_sha=$(git submodule status $sub_path | tr + " " | tr - " " | xargs | cut -d" " -f1)
if [ "$remote_sha" != "$local_sha" ]; then
pwd=$(pwd)
cd $sub_path
echo "*[ $sub : $sub_branch ]*"
git fetch -q -p --all
git log --pretty="tformat:* %s (%ae) _%h_" $remote_sha...$local_sha
cd $pwd
fi;
}
# Add a blank link for kicks
echo ""
for sub in $SUBS; do
getSubLog $sub
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment