Created
September 10, 2011 21:10
-
-
Save AndrewRayCode/1208792 to your computer and use it in GitHub Desktop.
Git is_submodule function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function is_submodule() { | |
# Find out if the parent directory of our current git repo is also a git repo | |
parent_git=`cd "$_git_dir/.." && git rev-parse --show-toplevel 2> /dev/null` | |
if [[ -n $parent_git ]]; then | |
# If it is, list all submodules of the parent | |
submodules=`cd $parent_git && git submodule --quiet foreach 'echo $path'` | |
for line in $submodules; do | |
# cd to each directory, if it matches our current git repo then we are in a submodule | |
cd "$parent_git/$line" | |
if [[ `pwd` = $_git_dir ]]; then return 0; fi | |
done | |
fi | |
return 1 | |
} | |
# Usage | |
if is_submodule; then | |
echo "In a submodule!" | |
else | |
echo "Not in a submodule" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment