4
\$\begingroup\$

I'm absolutely terrible with .bat files, but sometimes they are just needed. Right now I'm working on a project with quite some submodules, which have quite some submodules, and sometimes even those have submodules. Now, being a lazy programmer I figured I'd automate the task of committing the submodule-update in every single parent, and then having to push those parents manually. So I created this script:

@echo off
for /f "delims=" %%i in ('git rev-parse --show-toplevel') do set toplevel=%%i
cd %toplevel%
for /f "delims=" %%i in ('basename %cd%') do set reponame=%%i
echo "Master repo is %cd%"
git remote | xargs -L1 git push --all
:intorepo
for %%* in (.) do set submodulename=%%~nx*
for %%* in (.) do set submoduledir=%cd%
cd ..
set result=false
for /f "delims=" %%i in ('git rev-parse --is-inside-work-tree') do set result=%%i
if %result%==true (
    echo "%cd% is a parent"
    echo "%submodulename% is the submodule"
    git reset
    git add %submodulename%
    git commit -m "%submodulename% has been updated, committing recursively"
    goto :intorepo
)
echo "No more parents"
cd "%submoduledir%"
for /f "delims=" %%i in ('git remote get-url origin') do set pushto=%%i
echo "Pushing top-most repository, and submodules on demand."
git remote | xargs -L1 git push --all --recurse-submodules=on-demand
echo "done"

Are there any improvements I could make?

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.