I am trying to migrate some modules from SVN to GIT using svn2git. I have a list of modules in .csv file like this:
pl.com.neokartgis.i18n;pl.com.neokartgis.i18n;test-gis;svniop
pl.com.neokartgis.cfg;pl.com.neokartgis.cfg;test-gis;svniop
pl.com.neokart.db;pl.com.neokart.db;test-gis;svniop
I want to migrate each module to separate GIT repository. I tried following script that reads list of modules from .csv file and import each module in a loop:
#!/bin/bash
LIST=$1
SVN_PATH=svn://svn.server/path/to/root
DIR=`pwd`
function importToGitModule {
cd $DIR
rm -rf /bigtmp/svn2git/repo
mkdir /bigtmp/svn2git/repo
cd /bigtmp/svn2git/repo
svn2git --verbose $SVN_PATH/$1
#some other stuff with imported repository
}
cat $LIST | gawk -F";" '{ print $2; }' | while read module_to_import
do
echo "before import $module_to_import"
importToGitModule "$module_to_import";
done;
The problem is that the script ends after first iteration. However if I remove call to svn2git
, script works as expected and prints message for each module in file.
My question is: why this script ends after first iteration and how can I change it to import all modules in a loop?
EDIT:
Following version of loop works correctly:
for module_to_import in `cat $LIST | gawk -F";" '{ print $2; }'`
do
echo "before import $module_to_import"
importToGitModule "$module_to_import";
done;
So why while read
doesn't work?
I suspect that something inside your loop -- possibly part of the svn2git
process -- is consuming stdin
. Consider a loop like this:
ls /etc | while read file; do
echo "filename: $file"
cat > /tmp/data
done
Regardless of how many files are in /etc
, this loop will only run once. The cat
in this loop will consume all the other input on stdin
.
You can see if you have encountered the same situation by explicitly redirecting stdin
from /dev/null
, like this:
cat $LIST | gawk -F";" '{ print $2; }' | while read module_to_import
do
echo "before import $module_to_import"
importToGitModule "$module_to_import" < /dev/null
done