Last active
March 25, 2024 03:59
-
-
Save innocenat/4e46ef32b31da48e420757a6d54e80e0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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 [34m-----------------------------------------[0m | |
ECHO [34mGIT: %CD% | |
ECHO [34m-----------------------------------------[0m | |
FOR /F "tokens=*" %%A in ('git config --get remote.origin.url') DO ( | |
SET upstream=%%A | |
) | |
ECHO [32mUpstream: !upstream![0m | |
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 [31m | |
ECHO ! ----------------------------------- | |
ECHO ! No Git Found | |
ECHO ! Path: [34m%CD%[31m | |
ECHO ! ----------------------------------- | |
ECHO [0m | |
) | |
) | |
: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