Skip to content

Commit 14d1385

Browse files
author
Jared Murrell
committed
updated logic to the main script instead of functions
1 parent 9ed1a1b commit 14d1385

2 files changed

Lines changed: 71 additions & 69 deletions

File tree

_functions.sh

Lines changed: 64 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -203,81 +203,78 @@ function _discover_submodules()
203203
unset IGNORE_DIRS SUBMODULES ACTIONS SELECTION SUBDIRS choices options MENU FLAGS
204204
_get_svn_layout
205205
clear
206-
if [[ ${ENABLE_SUBMODULES} ]]
206+
echo "Discovering potential submodule candidates..."
207+
# Get the potential list of submodules, with branches, tags and trunk
208+
svn -R list ${REPO_URL} ${SVN_OPTIONS}|grep -E '(/trunk/$|/branches/$|/tags/$)' > /tmp/submodules.txt
209+
# it turns out, some folks have .git in their repos, and this falsely
210+
# identifies those as submodules. Let's remove those entries and not
211+
# present the user with the option to migrate them
212+
sed -i 's/\/.git\//d' /tmp/submodules.txt
213+
# Remove empty "trunk", "tags" and "branches" from the list of potentials
214+
for DIR in $(cat /tmp/submodules.txt);
215+
do
216+
FILES=$(svn list ${REPO_URL}/${DIR} ${SVN_OPTIONS})
217+
if [[ ${#FILES} -le 1 ]]
218+
then
219+
sed -i "s/${DIR}/d" /tmp/submodules.txt
220+
fi
221+
done
222+
# Get the path to the submodules
223+
export SUBMODULES=$(grep -E '(/trunk/$|/branches/$|/tags/$)' /tmp/submodules.txt|\
224+
sed -e 's/trunk\/$//' -e 's/tags\/$//' -e 's/branches\/$//'|sort|uniq)
225+
226+
# Print a report of the discovered submodules
227+
if [[ ${#SUBMODULES} -le 4 ]]
207228
then
208-
echo "Discovering potential submodule candidates..."
209-
# Get the potential list of submodules, with branches, tags and trunk
210-
svn -R list ${REPO_URL} ${SVN_OPTIONS}|grep -E '(/trunk/$|/branches/$|/tags/$)' > /tmp/submodules.txt
211-
# it turns out, some folks have .git in their repos, and this falsely
212-
# identifies those as submodules. Let's remove those entries and not
213-
# present the user with the option to migrate them
214-
sed -i 's/\/.git\//d' /tmp/submodules.txt
215-
# Remove empty "trunk", "tags" and "branches" from the list of potentials
216-
for DIR in $(cat /tmp/submodules.txt);
217-
do
218-
FILES=$(svn list ${REPO_URL}/${DIR} ${SVN_OPTIONS})
219-
if [[ ${#FILES} -le 1 ]]
229+
echo "There were no nested repositories discovered"
230+
else
231+
options=($(echo ${SUBMODULES}))
232+
#Actions to take based on selection
233+
function ACTIONS {
234+
for NUM in ${!options[@]}; do
235+
[[ ${choices[NUM]} ]] && SUBDIRS+="${options[NUM]} "
236+
done
237+
if [[ ! -z ${SUBDIRS} ]]
220238
then
221-
sed -i "s/${DIR}/d" /tmp/submodules.txt
239+
export IGNORE_DIRS=$(echo "'^("${SUBDIRS}")$'"|sed -e 's/ /|/g;s/\/|)/\/)/')
240+
export FLAGS+=" --ignore-paths ${IGNORE_DIRS}"
222241
fi
223-
done
224-
# Get the path to the submodules
225-
export SUBMODULES=$(grep -E '(/trunk/$|/branches/$|/tags/$)' /tmp/submodules.txt|\
226-
sed -e 's/trunk\/$//' -e 's/tags\/$//' -e 's/branches\/$//'|sort|uniq)
227-
228-
# Print a report of the discovered submodules
229-
if [[ ${#SUBMODULES} -le 4 ]]
230-
then
231-
echo "There were no nested repositories discovered"
232-
else
233-
options=($(echo ${SUBMODULES}))
234-
#Actions to take based on selection
235-
function ACTIONS {
242+
}
243+
#Variables
244+
ERROR=" "
245+
#Clear screen for menu
246+
clear
247+
#Menu function
248+
function MENU {
249+
_print_banner "We have discovered the following folders that contain" \
250+
"branches, tags, or trunk. This typically means that teams are using" \
251+
"them as separate repositories, but there is no real method of" \
252+
"discovering this, outside of the 'svn:externals' property, which is" \
253+
"often not used. Please review the following folders and select which" \
254+
"ones are to be treated as git submodules"
255+
echo ""
256+
echo "Discovered Folders"
236257
for NUM in ${!options[@]}; do
237-
[[ ${choices[NUM]} ]] && SUBDIRS+="${options[NUM]} "
258+
echo "[""${choices[NUM]:- }""]" $(( NUM+1 ))") ${options[NUM]}"
238259
done
239-
if [[ ! -z ${SUBDIRS} ]]
240-
then
241-
export IGNORE_DIRS=$(echo "'^("${SUBDIRS}")$'"|sed -e 's/ /|/g;s/\/|)/\/)/')
242-
export FLAGS+=" --ignore-paths ${IGNORE_DIRS}"
243-
fi
244-
}
245-
#Variables
246-
ERROR=" "
247-
#Clear screen for menu
260+
echo "$ERROR"
261+
}
262+
#Menu loop
263+
while MENU && read -e -p "Select the desired options using their number (again to uncheck, ENTER when done): " -n1 SELECTION && [[ -n "${SELECTION}" ]]; do
248264
clear
249-
#Menu function
250-
function MENU {
251-
_print_banner "We have discovered the following folders that contain" \
252-
"branches, tags, or trunk. This typically means that teams are using" \
253-
"them as separate repositories, but there is no real method of" \
254-
"discovering this, outside of the 'svn:externals' property, which is" \
255-
"often not used. Please review the following folders and select which" \
256-
"ones are to be treated as git submodules"
257-
echo ""
258-
echo "Discovered Folders"
259-
for NUM in ${!options[@]}; do
260-
echo "[""${choices[NUM]:- }""]" $(( NUM+1 ))") ${options[NUM]}"
261-
done
262-
echo "$ERROR"
263-
}
264-
#Menu loop
265-
while MENU && read -e -p "Select the desired options using their number (again to uncheck, ENTER when done): " -n1 SELECTION && [[ -n "${SELECTION}" ]]; do
266-
clear
267-
if [[ "${SELECTION}" == *[[:digit:]]* && ${SELECTION} -ge 1 && ${SELECTION} -le ${#options[@]} ]]; then
268-
(( SELECTION-- ))
269-
if [[ "${choices[SELECTION]}" == "+" ]]; then
270-
choices[SELECTION]=""
271-
else
272-
choices[SELECTION]="+"
273-
fi
274-
ERROR=" "
265+
if [[ "${SELECTION}" == *[[:digit:]]* && ${SELECTION} -ge 1 && ${SELECTION} -le ${#options[@]} ]]; then
266+
(( SELECTION-- ))
267+
if [[ "${choices[SELECTION]}" == "+" ]]; then
268+
choices[SELECTION]=""
275269
else
276-
ERROR="Invalid option: ${SELECTION}"
270+
choices[SELECTION]="+"
277271
fi
278-
done
279-
ACTIONS
280-
fi
272+
ERROR=" "
273+
else
274+
ERROR="Invalid option: ${SELECTION}"
275+
fi
276+
done
277+
ACTIONS
281278
fi
282279
}
283280

svn2github.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,13 @@ fi
1111
_welcome
1212
_setup
1313
_svn_sizer
14-
_discover_submodules
15-
_process_submodules
14+
if [[ ${ENABLE_SUBMODULES} ]]
15+
then
16+
_discover_submodules
17+
_process_submodules
18+
else
19+
_get_svn_layout
20+
fi
1621
_git_svn_clone
1722
(
1823
cd ${REPO_NAME}

0 commit comments

Comments
 (0)