scripts: Fix issue when no branch is given and fix nested repos handling
When no branch is given for an entry in repo.conf
and the checkout is done the first time, the checkout fails with the message 'Error: [Errno 2] No such file or directory:'
This is because the branch can not be determined from a not yet cloned git repo. A check whether the directory contains a git repo is introduced to prevent this.
For directory structures with nested repositories it's important to check out the git repository with the upmost path first. Else git will refuse to check out in a non empty directory. Now the directories are sorted before processed.
Both problems arised with the build-stm32mp
layer configuration. And the fixup was tested with this configuration ;-)
Edited by Eberhard Stoll