-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCleanRepo.bat
More file actions
129 lines (102 loc) · 4.27 KB
/
CleanRepo.bat
File metadata and controls
129 lines (102 loc) · 4.27 KB
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
127
128
@echo off
:: Cleans the repository at the specified location.
:: Usually used for reposiories that are embedded as full independent
:: repositories rather than via submodules or some other Git mechanism.
:: Callinng this script has NO SIDE EFFECTS (the body is enclosed in
:: setlocal / endlocal block).
:: PARAMETERS of the script are obtained via environment variables:
:: ModuleDir: root directory of cloned Repository
:: One way to call the script is to set all environment variables
:: that define parameters of the update (see above), then call this
:: script to perform the update. A better way is to create a settings
:: script that sets all the required parameters, and call this script
:: via embedded calll mechanism simply by stating script path as parameter
:: when calling the script (the advantage is that scripts have no sde
:: effects (variables set or changed) that would propagate to the calling
:: environment). See below for explanation.
:: If any PARAMETERS are specified when calling the script, these are
:: interpreted as EMBEDDED COMMAND with parameters, which is CALLED
:: BEFORE the body of the current script is executed, still WITHIN setlocal
:: / endlocal block.
:: This mechanism makes possible to define as parameter a script that sets
:: all the parameters as environment variables (the settings script), which
:: is called before the body of this script is executed. The advantage of
:: this approach is that settings for different repositories are packed into
:: the corresponding settings scripts and handling different repositories
:: is performed by calling the current script wih the appropriate settings
:: script as parameter. Annother advantage is that the calling environment
:: is not polluted with environment variables defining the parameters,
:: because this script takes care (by defining setlocal/endlocal block) that
:: variables set in the embedded call do not propagate to the callerr's
:: environment.
:: As EXAMPLE, suppose we define the scrippt SettingsRepoIGLibCore, which
:: contains repository settings for the IGLibCore repository. Removing the
:: corresponding repository is done simply by calling:
:: CleanRepo.bat SettingsRepoIGLibCore.bat
:: It is advisable that the settings script is also created in such a way
:: that it can take an embedded script as parameter, and this script is
:: run AFTER the environment variables (parameters for this script) are
:: set. In this way, some parameters can be simply overriden by recursively
:: nested commands, e.g.:
:: CleanRepo.bat SettingsRepoIGLibCore.bat SetVar ModuleDir .\MyDir
:: This would cause the same as command with a single parameter, except that
:: the module's cloned directory would be different, i.e. instead of the
:: branch specified in SettingsRepoIGLibCore.bat.
setlocal
:: Reset the error level (by running an always successfull command):
ver > nul
:: Base directories:
set ScriptDirCleanRepo=%~dp0
set InitialDirCleanRepo=%CD%
rem Before execution, execute command composed of script parameters, when
rem any:
if "%~1" EQU "" goto AfterCommandCall
:: If any command-line arguments were specified then assemble a
:: command-line from these arguments and execute it:
:: Assemble command-line from the remaining arguments....
set CommandLine90674="%~1"
:loop
shift
if [%1]==[] goto afterloop
set CommandLine90674=%CommandLine90674% "%~1"
goto loop
:afterloop
:: Call the assembled command-line:
echo.
echo Calling command composed of arguments:
echo "%CommandLine90674%"
echo.
call %CommandLine90674%
:AfterCommandCall
echo.
echo ========
echo Cleaning (embedded) module repository located at:
echo "%ModuleDir%"
echo.
:: Check that directory exists and it is a true Git repository:
:: Derived parameters:
set ModuleGitSubdir=%ModuleDir%\.git\refs
if not exist "%ModuleGitSubdir%" (
echo.
echo ====
echo Module's Git subdirectory does NOT exist:
echo "%ModuleGitSubdir%"
echo Cleaning of module directory will NOT be performed - not a Git repo.
echo.
goto finalize
) else (
rem
)
echo.
echo ====
echo CLEANING Module directory (removing untracked files and dirs):
echo "%ModuleDir%"
echo Executing:
echo git clean -f -x -d
cd "%ModuleDir%"
git clean -f -x -d
:finalize
cd %InitialDirCleanRepo%
ver > nul
endlocal
echo ... done, "CleanRepo" script completed.