-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_remote_scripts_repositories.cmd
126 lines (110 loc) · 3.87 KB
/
get_remote_scripts_repositories.cmd
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
:: Name: get_remote_scripts_repositiories.cmd
:: Purpose: Connect folders to git repository
:: Author: [email protected]
:: Revision: 2019 04 30 - initial version
::
:: Required environment variables
:: ==============================
:: - VERBOSE how verbose output should be if not set script sets it to YES
:: - extensionFolderName the name of the extension based on the top level foldername
::
@ECHO off
::
:: inspiration: http://batcheero.blogspot.com/2007/06/how-to-enabledelayedexpansion.html
:: using ENABLEDELAYEDEXPANSION and !env-var! ensures correct operation of script
::
SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
::
:: Check if required environment variables are set.
:: If not set them to a safe default value or exit with error.
::
IF "%VERBOSE%" == "" (
SET VERBOSE=YES
)
ECHO [%~n0 ] ... [0200]
IF "%extensionFolderName%" == "" (
SET ERROR_MESSAGE=[ERROR] [%~n0 ] ... [0201] extensionFolderName environment variable not set ...
GOTO ERROR_EXIT_SUBSCRIPT
)
SET git_username=pierre-pvln
SET remote_git_repository=build-joomla
SET local_git_repository=bld
CALL:GIT_FLOW_INIT
SET remote_git_repository=stage-joomla
SET local_git_repository=stg
CALL:GIT_FLOW_INIT
SET remote_git_repository=deploy-joomla
SET local_git_repository=dpl
CALL:GIT_FLOW_INIT
:: Don't initialize gitflow for skeleton here.
:: Batch file crashes...
::SET remote_git_repository=skeleton-joomla
::SET local_git_repository=struc
::CALL:GIT_FLOW_INIT
GOTO CLEAN_EXIT_SUBSCRIPT
:ERROR_EXIT_SUBSCRIPT
ECHO %ERROR_MESSAGE%
EXIT /B 1
:CLEAN_EXIT_SUBSCRIPT
EXIT /B 0
::--------------------------------------------------------
::-- Function section starts below here
::--
::-- Inspiration: https://www.dostips.com/DtTutoFunctions.php
::--
::--------------------------------------------------------
:GIT_FLOW_INIT
:: Initializes git flow for folder local_git_repository
:: And links it to remote_git_repository
::
IF %VERBOSE%==YES (
ECHO [%~n0 ] ...
ECHO [%~n0 ] ... [0202] Running GIT_FLOW_INIT for: %local_git_repository%
ECHO [%~n0 ] ...
)
CD %local_git_repository%
IF %VERBOSE%==YES ECHO [%~n0 ] ... [0203] Currently running in %CD%
::
:: check if folder is under git control
::
IF %VERBOSE%==YES ECHO [%~n0 ] ... [0204] Check if folder is under git control
git status
:: if not clone repository in folder and set default values
IF %ERRORLEVEL% NEQ 0 (
IF %VERBOSE%==YES ECHO [%~n0 ] ... [0205] This folder is not under git control: Initializing git
CD ..
git clone [email protected]:%git_username%/%remote_git_repository%.git %local_git_repository%
CD %local_git_repository%
IF %VERBOSE%==YES ECHO [%~n0 ] ... [0206] Currently running in %CD%
git status
IF !ERRORLEVEL! NEQ 0 (
SET ERROR_MESSAGE=[ERROR] [%~n0 ] ... [0207] Remote repository [email protected]:%git_username%/%remote_git_repository%.git not found ...
GOTO ERROR_EXIT_SUBSCRIPT
)
git config --local user.name "Pierre Veelen (%extensionFolderName%)"
git config --local user.email [email protected]
git config --local color.ui auto
)
IF %VERBOSE%==YES ECHO [%~n0 ] ... [0208] This folder is under git control
IF %VERBOSE%==YES ECHO [%~n0 ] ... [0209] Determine current local branch name
:: Get current branch in environment variable
:: https://ss64.com/nt/for_cmd.html
::
FOR /F %%G IN ('git rev-parse --abbrev-ref HEAD') DO SET currentGitBranch=%%G
:: remove spaces in name
:: http://www.dostips.com/DtTipsStringManipulation.php
::
SET currentGitBranch=%currentGitBranch: =%
:: show the result
IF %VERBOSE%==YES ECHO [%~n0 ] ... [0210] Current branch: %currentGitBranch%
:: current git branch is determined
IF "%currentGitBranch%" == "master" (
:: start git flow with default settings ( -d )
git flow init -d
:: create the featurebranch %extensionFolderName%
git flow feature start FROM_%extensionFolderName%
:: share this feature branch
git flow feature publish FROM_%extensionFolderName%
)
CD ..
goto:eof