I have following git project structure:
MAIN_PRJ
SUB_MODULE1
SUB_MODULE2
SUB_MODULE2_1
SUB_MODULE3
SUB_MODULE3_1
SUBMODULE_3_1_1
As part of my jenkins job trigger, the trigger message that passed contains fetch commands for curtain sub-modules, passed as a string. For example:
git fetch https://git.server/SUB_MODULE1 hash_commit;git fetch https://git.server/SUB_MODULE2_1 hash_commit;git fetch https://git.server/SUB_MODULE3_1_1 hash_commit
We use those for cross dependency checks. I am looking for a way to make all those "fetches" recursively.
One of the direction -
running git submodule foreach --recursive 'git remote -v'
command
get the remote from it
compare remote path to fetch path
if true execute the fetch command
git remote -v
Command returns the origin for fetch and push, Is there a way to get only one of them? Is there a way to store this remote value as a parameter? The path during the recursive run stored as pwd parameter.
In my vision it will look like that:
foreach fetch_remote in fetchlist:
git submodule foreach --recursive 'git remote -v;if [$origin==$fetch_remote] then fetch_command fi'
Any other Ideas?
Update: So far I managed to combine following command that partly works:
foreach fetch_remote in fetchlist:
git submodule foreach --recursive 'sub_remote=$(git remote get-url origin);if[$sub_remote==$fetch_remote];then $fetch_command; fi'
But I am getting an error, for explanation let assume that fetch_remote="http://git_remote/SUB_MODULE2_1"
/usr/lib/git-core/git-submodule: 1: eval: [http://git_remote/SUB_MODULE2_1==http://git_remote/SUB_MODULE2_1]: not found
Found solution that work for me:
foreach fetch_remote in fetchlist:
git submodule foreach --recursive 'if [ "$(git remote get-url origin)" = "$fetch_remote" ]; then fetch_command; fi'
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.