From aedb2ed810ecee8c6eea5f4e1ba9e8c16d455a05 Mon Sep 17 00:00:00 2001
From: Simon <oehrl@vr.rwth-aachen.de>
Date: Wed, 15 Jan 2020 16:06:46 +0100
Subject: [PATCH] Add/remove submodules
---
setup.sh | 42 ++++++++++++++++++++++++++++++++++++++----
1 file changed, 38 insertions(+), 4 deletions(-)
diff --git a/setup.sh b/setup.sh
index 79e41a3d..12de8b71 100644
--- a/setup.sh
+++ b/setup.sh
@@ -194,15 +194,49 @@ function manage_plugins() {
clear
mkdir -p Plugins
cd Plugins
- echo "Adding plugins..."
-
+ echo "Adding/updating plugins..."
for i in ${!plugins[@]}
do
+ # Check if plugin is already present
+ repo_name_with_extension=${plugin_repositories[$i]##*/}
+ repo_name=${repo_name_with_extension%*.git}
+ path=$(git config -f .gitmodules --get "submodule.Plugins/${repo_name}.path")
+ if [ $? -ne 0 ]
+ then
+ plugin_present=true
+ else
+ plugin_present=false
+ fi
+
if [ -n "${plugin_branches[$i]}" ]
then
- echo "${plugins[$i]}"
- git submodule add -b ${plugin_branches[$i]} ${plugin_repositories[$i]}
+ if [ "$plugin_present" == false ]
+ then
+ # Plugin was not yet added, call git submodule add
+ echo "Add new plugin: ${plugins[$i]}"
+ git submodule add -b ${plugin_branches[$i]} ${plugin_repositories[$i]}
+ else
+ # Updating existing plugin
+ echo "Update plugin: ${plugins[$i]}"
+ cd $repo_name
+ git fetch
+ git checkout ${plugin_branches[$i]}
+ git pull
+ cd ..
+ fi
+ else
+ if [ "$plugin_present" == true ]
+ then
+ # Remove plugin!
+ git submodule deinit -f "$repo_name"
+ git rm -f "$repo_name"
+
+ git config -f ../.gitmodules --remove-section "submodule.Plugins/${repo_name}"
+ if [ -z "$(cat ../.gitmodules)" ]; then
+ git rm -f ../.gitmodules
+ fi
+ fi
fi
done
cd ..
--
GitLab