-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit_pull_all.bat
71 lines (66 loc) · 1.99 KB
/
git_pull_all.bat
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
@echo off
setlocal enableDelayedExpansion
REM Set color codes for output
Set _fYELLOW=[93m
set _fRED=[91m
Set _RESET=[0m
goto :Start
REM Function to check if a folder contains a Git repository and a remote is set
:CheckGitRepo
pushd %1
if exist ".git" for /f "delims=" %%R in ('git remote') do (
echo "%_fYELLOW%Fetching changes in: %CD%%_RESET%"
git fetch --all 2>nul
if errorlevel 1 (
echo "%_fRED%Failed to fetch changes in: %CD%%_RESET%"
popd
exit /b 1
)
REM Get the default branch name
for /f "tokens=*" %%i in ('git symbolic-ref refs/remotes/origin/HEAD 2^>nul') do set "default_branch=%%i"
if not defined default_branch (
echo "%_fRED%Could not determine default branch in: %CD%%_RESET%"
popd
exit /b 1
)
set "default_branch=!default_branch:refs/remotes/origin/=!"
REM Checkout the default branch
git checkout !default_branch! 2>nul
if errorlevel 1 (
echo "%_fRED%Failed to checkout branch !default_branch! in: %CD%%_RESET%"
popd
exit /b 1
)
REM Check if a remote is configured
REM set "_gitMsg="
REM for /f "tokens=* delims= " %%i in ('git remote') do set "_gitMsg=%%i"
REM if "%_gitMsg%"=="" (
REM echo "%_fRED%No remote configured for %CD%%_RESET% - %_gitMsg%"
REM popd
REM exit /b 1
REM )
git pull 2>nul
if errorlevel 1 (
echo "%_fRED%Failed to pull updates for branch !default_branch! in: %CD%%_RESET%"
popd
exit /b 1
)
echo "Successfully pulled updates for branch !default_branch! in: %CD%"
)
popd
exit /b 0
REM Function to traverse directories recursively
:TraverseDirs
setlocal
set "currentDir=%~1"
for /d %%d in ("%currentDir%\*") do (
call :CheckGitRepo "%%~fd"
call :TraverseDirs "%%~fd"
)
endlocal
exit /b 0
REM Start label for the script
:Start
echo Starting directory traversal from %cd%
call :TraverseDirs "%cd%"
endlocal