필자는 주어진 브랜치에 따라 모든 자식 서브 모듈을 업데이트하는 스크립트를 작성하는 것입니다. 하위 모듈에 대해 그러한 분기가 없으면 master가 사용됩니다.
이것이 내가 지금 가진 것입니다.
#!/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
그러나이 스크립트를 실행할 때 오류가 발생합니다.
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.
내 생각에 git submodule foreacheval ( documentation 에 따르면)을 사용하는데,이 맥락에서 올바르게 사용하지 않습니다.
이 명령을 "인라인 콜백"과 함께 사용하는 방법에 대한 수십억 개의 예가 있지만 함수 형태의 콜백이있는 단일 명령을 찾을 수 없습니다. 어떻게 해결할 수 있습니까?
git-pbranch-submodule내장 git 명령처럼 동작 할 수 있습니다 :git pbranch-submodule또는git submodule foreach git pbranch-submodule. (foreach는 git 명령이 아닌 쉘 명령을 받아들입니다.)