Skip to content

Commit 834dcc2

Browse files
committed
Fix auto-updating of projects.
Use subroutines to set local variables inside if statements and for loops.
1 parent 0aae104 commit 834dcc2

File tree

1 file changed

+39
-22
lines changed

1 file changed

+39
-22
lines changed

phases/common.bat

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ call :%*
88
exit /b %errorlevel%
99

1010
:loadenv
11-
exit /b 0
11+
goto :eof
1212

1313
:prepare_project
1414
if not defined PROJECT (echo Missing PROJECT && exit /b 1)
@@ -35,26 +35,7 @@ exit /b %errorlevel%
3535
if not [%NO_UPDATE%] == [true] (
3636
echo.
3737
if "%TAG%" == "" (
38-
:: check if we should update project
39-
set GIT_BRANCH=NONE
40-
for /f "usebackq delims=" %%i in (`git symbolic-ref --short -q HEAD`) do (
41-
set GIT_BRANCH=%%i
42-
)
43-
if not [%GIT_BRANCH%] == [NONE] (
44-
:: check if current branch has a remote
45-
set GIT_REMOTE=NONE
46-
for /f "usebackq delims=" %%i in (`git config --get branch.%GIT_BRANCH%.remote`) do (
47-
set GIT_REMOTE=%%i
48-
)
49-
if not [%GIT_REMOTE%] == [NONE] (
50-
echo ### Updating project
51-
git pull --ff-only || exit /b 1
52-
) else (
53-
echo ### NOT updating project [no remote for branch %GIT_BRANCH%]
54-
)
55-
) else (
56-
echo NOT updating project [not on branch]
57-
)
38+
call :update_project
5839
) else (
5940
echo ### Checking out %TAG%
6041
git fetch --tags || exit /b 1
@@ -72,4 +53,40 @@ exit /b %errorlevel%
7253
git apply %%P
7354
)
7455

75-
exit /b 0
56+
goto :eof
57+
58+
:update_project
59+
:: check if we should update project
60+
set GIT_BRANCH=NONE
61+
for /f "usebackq delims=" %%i in (`git symbolic-ref --short -q HEAD`) do (
62+
call :set_git_branch %%i
63+
)
64+
if not [%GIT_BRANCH%] == [NONE] (
65+
call :update_project_2
66+
) else (
67+
echo NOT updating project [not on branch]
68+
)
69+
goto :eof
70+
71+
:update_project_2
72+
:: check if current branch has a remote
73+
set GIT_REMOTE=NONE
74+
for /f "usebackq delims=" %%i in (`git config --get branch.%GIT_BRANCH%.remote`) do (
75+
call :set_git_remote %%i
76+
)
77+
if not [%GIT_REMOTE%] == [NONE] (
78+
echo ### Updating project
79+
git pull --ff-only || exit /b 1
80+
) else (
81+
echo ### NOT updating project [no remote for branch %GIT_BRANCH%]
82+
)
83+
goto :eof
84+
85+
:set_git_branch
86+
set GIT_BRANCH=%1
87+
goto :eof
88+
89+
:set_git_remote
90+
set GIT_REMOTE=%1
91+
goto :eof
92+

0 commit comments

Comments
 (0)