My indention is to have a script that updates all git submodules according to which branch is given. If there's no such branch for a submodule, master is used.
This is what I have now:
#!/bin/bash -x
if [ -z $1 ]; then
echo "Branch name required."
exit
fi
function pbranch {
exists=`git show-ref refs/heads/$branch`
if [ -z $exists ]; then
branch="master"
fi
git co $branch
git pull origin $branch
}
branch=$1
git submodule foreach pbranch
But when running this script, the error is thrown:
oleq@pc ~/project> git-fetchmodules major
+ '[' -z major ']'
+ branch=major
+ git submodule foreach pbranch
Entering 'submodule'
/usr/lib/git-core/git-submodule: 1: eval: pbranch: not found
Stopping at 'submodule'; script returned non-zero status.
My guess is that git submodule foreach
utilizes eval (according to the documentation), which I don't use correctly in this context.
There are billions of examples of how to use this command with "inline callback" but I couldn't found a single one with the callback in form of the function. Any idea how to solve this?