-
Notifications
You must be signed in to change notification settings - Fork 0
/
recurse.cmd
43 lines (41 loc) · 1.23 KB
/
recurse.cmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
@echo off
rem Usage: recurse <command>
rem
rem Walk the submodules recursively and execute the command at
rem every level. By default, it steps into git submodules, but
rem if there is a recurse script in a subdirectory, it will call
rem that one instead.
setlocal
set command=%*
rem Get the subdirectories from .gitmodules. If it doesn't
rem exit, don't process any subdirectories
if exist .gitmodules (
for /f %%f in ('awk "/path += +/{print $3}" ^< .gitmodules') do (
if not "%%f" == "echo" (
call :processDir %%f
)
)
)
rem After the subdirectories are done, process the current directory.
for %%f in (.) do (
echo # %%~ff
%command%
)
goto :eof
:processDir
rem Replace slashes with backslashes in the directory name
for /f %%d in ('echo %1 ^| sed s/\//\\/g;') do (
set dirName=%%d
)
if exist %dirName% (
pushd .\%dirName%
rem Now that we are in the subdirectory, call
rem recurse again. We use cmd /c because it has
rem to be in a separate process. Also, if there
rem is a recurse script in the subdirectory, it
rem will use that one instead.
cmd /c recurse %command%
popd
)
goto :eof
endlocal