Skip to content

Instantly share code, notes, and snippets.

@geerteltink
Last active January 15, 2016 16:36
Show Gist options
  • Save geerteltink/73108189df710ef55149 to your computer and use it in GitHub Desktop.
Save geerteltink/73108189df710ef55149 to your computer and use it in GitHub Desktop.
@ECHO OFF
setlocal ENABLEDELAYEDEXPANSION
SET _START=%CD%
ECHO.
ECHO -------------------------------------------------------------
ECHO Checking git repos for uncommitted files and unpushed commits
ECHO -------------------------------------------------------------
ECHO.
SET _ERROR=0
:: Get all directories
FOR /F %%D IN ('2^>nul DIR /B /S /A:D ^| FINDSTR /V "node_modules" ^| FINDSTR /E ".git"') DO (
SET _CURRENT_DIR=%%D
:: Change to current dir
PUSHD !_CURRENT_DIR:~0,-4!
SET _CURRENT_ERROR=0
SET _UNCOMMITTED=0
SET _UNPUSHED=0
:: Check for uncommitted changes
git status --porcelain | FIND /v /c "" > %TMP%\git-status
SET /P _COUNT= < %TMP%\git-status
IF !_COUNT! GTR 0 (
SET _ERROR=1
SET _CURRENT_ERROR=1
SET _UNCOMMITTED=1
)
rm %TMP%\git-status
:: Check for changes that need a push
git log --oneline --branches --not --remotes | FIND /v /c "" > %TMP%\git-status
SET /P _COUNT= < %TMP%\git-status
IF !_COUNT! GTR 0 (
SET _ERROR=1
SET _CURRENT_ERROR=1
SET _UNPUSHED=1
)
rm %TMP%\git-status
IF !_CURRENT_ERROR! == 1 (
ECHO.
ECHO Scanning: !_CURRENT_DIR:~0,-4!
)
IF !_UNCOMMITTED! == 1 (
ECHO Warning: Uncommitted files found!
)
IF !_UNPUSHED! == 1 (
ECHO Warning: Not all commits are pushed!
)
)
IF !_ERROR! == 0 (
ECHO.
ECHO All files committed and pushed.
)
@silashansen
Copy link

Change the FOR-line to:
FOR /F %%D IN ('2^>nul DIR /B /S /A:D ^| FINDSTR /V "node_modules" ^| FINDSTR /E ".git"') DO (

to suppress errors in the FS. I am getting lots of errors that some paths are too long.

@geerteltink
Copy link
Author

@silashansen Changed, thanx.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment