Skip to content

Instantly share code, notes, and snippets.

@Skitionek
Last active March 16, 2018 13:08
Show Gist options
  • Save Skitionek/48877928b008f1e37e0922c944779be1 to your computer and use it in GitHub Desktop.
Save Skitionek/48877928b008f1e37e0922c944779be1 to your computer and use it in GitHub Desktop.
Recursive traverse folders finding the git repositories and listing the uncommitted changes. Additionally, if the pair with the same name was found compare them with git diff.
#!/usr/local/bin/bash
clear
# just for formatting
b=$(tput bold)
n=$(tput sgr0)
declare -A reppos
find . -name .git -print0 | xargs -0 -n1 dirname | sort --unique | while read -r dir
do
reppo="${dir##*/}"
echo "-- ${dir%/*}/${b}${reppo}${n} --"
if [ ${reppos[$reppo]+_} ]
then
echo "Found another copy of this reppo in ${reppos[$reppo]}."
diff=$(git diff --shortstat ${reppos[$reppo]} ${dir})
if [[ -z "${diff// }" ]]
then
echo "The copies are identical."
else
echo "Comparing these two yield: ${diff}";
fi
else
reppos[$reppo]=${dir}
fi
dir=${dir%*/}
{
(cd ${dir} && git status -s)
} || {
echo "Repository error!"
}
echo
done
@Skitionek
Copy link
Author

Skitionek commented Mar 16, 2018

Example output:

-- ./dashboard-backend --
 M dashboard-visualization
 M graphql-data-interface
 M package-lock.json
 M package.json

-- ./dashboard-backend/dashboard-visualization --

-- ./dashboard-backend/graphql-data-interface --

-- ./dashboard-backend/thrift-model-interface --

-- ./dashboard-backend/graphql-data-interface/dependencies/information-system --

-- ./dashboard-backend/graphql-data-interface/dependencies/thrift-model-interface --
Found another copy of this reppo in ./dashboard-backend/graphql-data-interface/dependencies/thrift-model-interface.
Comparing these two yield:  12683 files changed, 2132259 insertions(+), 524 deletions(-)

-- ./dashboard-backend/thrift-model-interface/dependencies/information-system --
Found another copy of this reppo in ./dashboard-backend/graphql-data-interface/dependencies/information-system.
The copies are identical.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment