Last active
August 16, 2018 23:43
-
-
Save chhh/c4afa4de33d4239b5cbe928a9f969bf6 to your computer and use it in GitHub Desktop.
Create git repositories in all leaf directories. Useful for setting up large multi-project builds with Gradle, for example.
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
#!/bin/bash | |
startdir=`pwd` | |
# # find all the LEAF directories that don't have .git somewhere along the path | |
# selection of LEAFs is done in the awk part | |
# the output of find is read line by line, assuming filenames don't have newlines | |
# `find -print0` wouldn't work, as this would screw up the awk part | |
find . -not \( -name .git -prune \) -type d -print | sort -r | awk 'a!~"^"$0{a=$0;print}' | sort | while read -d $'\n' file | |
do | |
echo "Going to -> $file" | |
cd $file | |
echo "In: `pwd`" | |
if [ ! -d ".git" ]; then | |
echo "Initializing a new git repo" | |
git init | |
git add -A | |
git cm "Init commit" | |
else | |
echo "Already a git repo, skipping" | |
fi | |
echo "Going back to start directory" | |
cd $startdir | |
echo "----------" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment