Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
482 views
in Technique[技术] by (71.8m points)

bash - Running a script that contains git commands using `git submodule foreach` causes a `not a git repository` error

I'm using a few git submodules in my project, each with their own dependencies. I'm running the top level setup.sh, which installs top level deps and then runs this, which calls each submodule's setup.sh script.

git submodule foreach 'if [ -e "setup.sh" ]; then ${SUDO} "`pwd`/setup.sh"; fi'

That runs fine, but the problem arises when the sub1 and sub2 submodules call their own setup.sh script that does the exact same thing. When any git command is run by the sub1 and sub2 setup.sh script, it fails with the error:

fatal: not a git repository: '.git'

pwd in the sub1 and sub2 scripts give me the correct path, and the scripts work fine in isolation.

Project structure:

.
├── setup.sh
└── submodules
    ├── sub1
    |   ├── setup.sh
    |   └── submodules
    |       └── sub3
    |           └── setup.sh
    └── sub2
        ├── setup.sh
        └── submodules
            └── sub4
                └── setup.sh

Apologies if this is a stupid question, thanks a bunch.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...