Skip to content

Commit

Permalink
Tools:Added Git submodule checking that obeys GIT_SUBMODULES_ARE_EVIL
Browse files Browse the repository at this point in the history
  • Loading branch information
David Sidrane committed Jul 5, 2018
1 parent f6b273d commit 1492677
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 18 deletions.
7 changes: 1 addition & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,5 @@ $(LIBOPENCM3): checksubmodules
${MAKE} -C $(LIBOPENCM3) lib

.PHONY: checksubmodules
checksubmodules: updatesubmodules
checksubmodules:
$(Q) ($(BL_BASE)/Tools/check_submodules.sh)

.PHONY: updatesubmodules
updatesubmodules:
$(Q) (git submodule init)
$(Q) (git submodule update)
58 changes: 47 additions & 11 deletions Tools/check_submodules.sh
Original file line number Diff line number Diff line change
@@ -1,27 +1,63 @@
#!/bin/sh
#!/usr/bin/env bash

if [ -d libopencm3 ];
[ -n "$GIT_SUBMODULES_ARE_EVIL" ] && {
# GIT_SUBMODULES_ARE_EVIL is set, meaning user doesn't want submodules
echo "Skipping submodules."
exit 0
}

GITSTATUS=$(git status)

function check_git_submodule {

if [ -d $1 ];
then
STATUSRETVAL=$(git submodule summary | grep -A20 -i "libopencm3" | grep "<")
SUBMODULE_STATUS=$(git submodule summary "$1")
STATUSRETVAL=$(echo $SUBMODULE_STATUS | grep -A20 -i "$1" | grep "<")
if [ -z "$STATUSRETVAL" ]; then
echo "Checked libopencm3 submodule, correct version found"
echo "Checked $1 submodule, correct version found"
else
echo -e "\033[31mChecked $1 submodule, ACTION REQUIRED:\033[0m"
echo ""
echo -e "New commits required:"
echo -e "$SUBMODULE_STATUS"
echo ""
echo " libopencm3 sub repo not at correct version. Try 'git submodule update'"
echo " or follow instructions on http://px4.io/dev/git/submodules"
echo ""
echo " DO NOT FORGET TO RUN 'make clean' AFTER EACH libopencm3 UPDATE!"
echo -e " *******************************************************************************"
echo -e " * \033[31mIF YOU DID NOT CHANGE THIS FILE (OR YOU DON'T KNOW WHAT A SUBMODULE IS):\033[0m *"
echo -e " * \033[31mHit 'u' and <ENTER> to update ALL submodules and resolve this.\033[0m *"
echo -e " * (performs \033[94mgit submodule update --init --recursive\033[0m) *"
echo -e " *******************************************************************************"
echo ""
echo ""
echo "New commits required:"
echo "$(git submodule summary)"
echo -e " Only for EXPERTS:"
echo -e " $1 submodule is not in the recommended version."
echo -e " Hit 'y' and <ENTER> to continue the build with this version. Hit <ENTER> to resolve manually."
echo -e " Use \033[94mgit add $1 && git commit -m 'Updated $1'\033[0m to choose this version (careful!)"
echo ""
exit 1
read user_cmd
if [ "$user_cmd" == "y" ]
then
echo "Continuing build with manually overridden submodule.."
else
if [ "$user_cmd" == "u" ]
then
git submodule update --init --recursive
echo "Submodule fixed, continuing build.."
else
echo "Build aborted."
exit 1
fi
fi
fi
else
git submodule init;
git submodule update --init --recursive;
git submodule update;
fi

}

check_git_submodule libopencm3
check_git_submodule lib/kinetis/NXP_Kinetis_Bootloader_2_0_0

exit 0
2 changes: 1 addition & 1 deletion Tools/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ fi
# Check for code style, only in changed files
for i in `git diff --cached --name-only --diff-filter=ACM`
do
./Tools/astyle/files_to_check_code_style.sh $i | xargs -n 1 -P 8 -I % ./Tools/astyle/check_code_style.sh %
./Tools/files_to_check_code_style.sh $i | xargs -n 1 -P 8 -I % ./Tools/check_code_style.sh %
if [ $? -ne 0 ]
then
exit 1
Expand Down

0 comments on commit 1492677

Please sign in to comment.