Skip to content

Instantly share code, notes, and snippets.

@innocenat
Last active March 25, 2024 03:59
Show Gist options
  • Save innocenat/4e46ef32b31da48e420757a6d54e80e0 to your computer and use it in GitHub Desktop.
Save innocenat/4e46ef32b31da48e420757a6d54e80e0 to your computer and use it in GitHub Desktop.
@ECHO off
REM Trap for doing `pause` only when double-click from explorer
IF "%parent%"=="" SET parent=%~0
IF "%console_mode%"=="" (
SET console_mode=1
FOR %%x IN (%cmdcmdline%) DO (
IF /i "%%~x"=="/c" SET console_mode=0
)
)
SETLOCAL DISABLEDELAYEDEXPANSION
SET depth=0
CALL :RECURSIVE
ENDLOCAL
GOTO :EXIT
REM Main recursive code traversing folder
:RECURSIVE
SET /A "depth+=1"
REM Only go 4 level deep
IF %depth% EQU 4 GOTO :CONT
REM To check if there are any git in first-level directory
IF %depth% EQU 2 SET "gitf=0"
IF EXIST ".git" (
REM We need delayed expansion here
SETLOCAL ENABLEDELAYEDEXPANSION
ECHO -----------------------------------------
ECHO GIT: %CD%
ECHO -----------------------------------------
FOR /F "tokens=*" %%A in ('git config --get remote.origin.url') DO (
SET upstream=%%A
)
ECHO Upstream: !upstream!
ECHO.
git status
ECHO.
ECHO.
ENDLOCAL
SET "gitf=1"
)
REM Recursively check subfolder
FOR /D %%d IN (*) DO (
CD %%d
CALL :RECURSIVE
CD ..
)
REM Print error if there are not any git in first-level subdirectory
IF %depth% EQU 2 (
IF %gitf%==0 (
ECHO 
ECHO ! -----------------------------------
ECHO ! No Git Found
ECHO ! Path: %CD%
ECHO ! -----------------------------------
ECHO 
)
)
:CONT
SET /A "depth-=1"
EXIT /B
:EXIT
IF "%parent%"=="%~0" ( IF "%console_mode%"=="0" PAUSE )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment