Skip to content

Commit a61de44

Browse files
committed
Add [-k|--keep] option to git_matrix.sh for keep the current commit of each submodule
1 parent e956ba8 commit a61de44

File tree

1 file changed

+43
-11
lines changed

1 file changed

+43
-11
lines changed

git_matrix.sh

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,35 @@ ENV_BRANCHES=(develop master)
1212
NUM_BRANCHES=${#ENV_BRANCHES[@]}
1313

1414
#
15-
# Initial checks and preparations
15+
# Function for print the script execution mode
16+
#
17+
print_exec_mode ()
18+
{
19+
$ECHO "\n\tEXECUTION MODE =>\t$0 [-h|--help] [-k|--keep]"
20+
$ECHO "\n\tOptions:"
21+
$ECHO "\t\t-h, --help\tShow this help message and exit"
22+
$ECHO "\t\t-k, --keep\tKeep the current commit of each submodule"
23+
$ECHO "\t\t\t\t(no effect on the first environment branch of the project)\n"
24+
}
25+
26+
#
27+
# Check the execution procedure used
28+
#
29+
if [[ $1 == '-h' || $1 == '--help' ]]
30+
then
31+
print_exec_mode
32+
exit 0
33+
fi
34+
35+
if [[ $1 == '-k' || $1 == '--keep' ]]
36+
then
37+
UPDATE_SUBMODULES=0
38+
else
39+
UPDATE_SUBMODULES=1
40+
fi
41+
42+
#
43+
# Initial checks and provisions
1644
#
1745

1846
# Change position to the project root folder
@@ -104,19 +132,23 @@ else
104132
$ECHO "${OPTION}) $BRANCH_INFO"
105133
OPTION=${OPTION}+1
106134
done
107-
$ECHO "${OPTION}) Keep the current commit"
108135

109-
$ECHO "\n$(tput bold)Select the number of branch to activate:$(tput sgr0) [$DEF_OPTION] \c"
110-
read SELECTION
111-
if [[ -z $SELECTION || $SELECTION -lt 1 || $SELECTION -gt $OPTION ]]
136+
if [[ $UPDATE_SUBMODULES -eq 1 ]]
112137
then
113-
SELECTION=$DEF_OPTION
114-
fi
138+
$ECHO "${OPTION}) Keep the current commit"
115139

116-
for ((i=1; i<$OPTION; i++))
117-
do
118-
[[ $SELECTION -eq $i ]] && git checkout ${ENV_BRANCHES[${i}-1]}
119-
done
140+
$ECHO "\n$(tput bold)Select the number of branch to activate:$(tput sgr0) [$DEF_OPTION] \c"
141+
read SELECTION
142+
if [[ -z $SELECTION || $SELECTION -lt 1 || $SELECTION -gt $OPTION ]]
143+
then
144+
SELECTION=$DEF_OPTION
145+
fi
146+
147+
for ((i=1; i<$OPTION; i++))
148+
do
149+
[[ $SELECTION -eq $i ]] && git checkout ${ENV_BRANCHES[${i}-1]}
150+
done
151+
fi
120152

121153
for FOLDER in $(echo $SUBMODULE |sed "s/\// /g")
122154
do

0 commit comments

Comments
 (0)