2023-01-20 19:17:51 +00:00
|
|
|
#!/bin/sh
|
|
|
|
# If no project name is given
|
|
|
|
if [ $# -eq 0 ]; then
|
|
|
|
# Display usage and stop
|
2023-05-23 20:12:58 +00:00
|
|
|
echo "Usage: git-setup.sh <console,website>"
|
2023-01-20 19:17:51 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
2023-01-23 23:05:53 +00:00
|
|
|
# Get remote url to support either https or ssh
|
|
|
|
remote_url=$(echo $(git config --get remote.origin.url) | sed 's![^/]*$!!')
|
2023-01-20 19:17:51 +00:00
|
|
|
# Loop through the requested modules
|
|
|
|
for module in "$@"; do
|
|
|
|
echo "Setting up '$module' module..."
|
|
|
|
# Set the project git URL
|
2023-01-23 23:05:53 +00:00
|
|
|
project=$remote_url$module.git
|
2023-01-20 19:17:51 +00:00
|
|
|
# Check if we have access to the module
|
|
|
|
if [ "$(git ls-remote "$project" 2>/dev/null)" ]; then
|
|
|
|
echo "You have access to '${module}'"
|
|
|
|
# Create the .gitmodules file if it doesn't exist
|
|
|
|
([ -e ".gitmodules" ] || touch ".gitmodules") && [ ! -w ".gitmodules" ] && echo cannot write to .gitmodules && exit 1
|
|
|
|
# Prevents duplicate entries
|
|
|
|
git config -f .gitmodules --unset-all "submodule.apps/$module.branch"
|
|
|
|
# Add the submodule
|
2023-01-23 23:05:53 +00:00
|
|
|
git submodule add --force $project "apps/$module"
|
2023-01-20 19:17:51 +00:00
|
|
|
# Set the default branch to main
|
|
|
|
git config -f .gitmodules --add "submodule.apps/$module.branch" main
|
2023-05-12 16:20:32 +00:00
|
|
|
|
|
|
|
# Update to the latest from main in that submodule
|
|
|
|
cd apps/$module && git pull origin main && cd ../..
|
|
|
|
|
|
|
|
# We forcefully added the subdmoule which was in .gitignore, so unstage it.
|
|
|
|
git restore --staged apps/$module
|
2023-01-20 19:17:51 +00:00
|
|
|
else
|
2023-05-23 20:12:58 +00:00
|
|
|
echo "You don't have access to: '${module}' module."
|
2023-01-20 19:17:51 +00:00
|
|
|
fi
|
|
|
|
done
|
2023-05-12 16:20:32 +00:00
|
|
|
git restore --staged .gitmodules
|