Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
479 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 Answer

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...