-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTestUpdateOrCloneRepository.ps1
More file actions
146 lines (125 loc) · 7.81 KB
/
TestUpdateOrCloneRepository.ps1
File metadata and controls
146 lines (125 loc) · 7.81 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# This contains PowerShell commands for testing the UpdateOrCloneRepository.ps1.
# Open the PowerShell CLI in the directory of this script and copy-paste commands
# from this file, then verify the results.
# Set variables containing repository parameters for IGLibScripts:
./SetUpdateOrClone_IGLibScripts.ps1
./PrintSettingsUpdateOrClone.ps1
# Resets variables containing repository parameters to null:
./SetUpdateOrClone_Null.ps1
./PrintSettingsUpdateOrClone.ps1
# Cloning repository without specifying the checkout branch, into nested directory:
# Before, either remove the clone directory, or let it exist.
# Both if directory does not exist or it exists but it is empty,
# the remote repository should be cloned into the repos/IGLibScripts directory.
./UpdateOrCloneRepository.ps1 -Directory "repos/IGLibScripts" `
-address "https://github.com/ajgorhoe/IGLib.modules.IGLibScripts.git"
# Cloning repository from a directory different from script directory, with a
# relative path.
# Expected: Relative path resolves relative to the current directory.
Set-Location TestScripts # change to directory different than script directory
../UpdateOrCloneRepository.ps1 -Directory "repos/IGLibScripts" `
-address "https://github.com/ajgorhoe/IGLib.modules.IGLibScripts.git"
Set-Location .. # Change back to the initial directory
# Cloning repository from a directory different from script directory, with a
# relative path.
# Expected: Relative path resolves relative to the base directory.
Set-Location TestScripts # change to directory different than script directory
../UpdateOrCloneRepository.ps1 -Directory "repos/IGLibScripts" `
-BaseDirectory "../" `
-address "https://github.com/ajgorhoe/IGLib.modules.IGLibScripts.git"
Set-Location .. # Change back to the initial directory
# Cloning or updating with a different branch than the default one:
# Remove the repo directory before executing, or keep it with another ref
# check out to observe the effect.
# Expected: in all cases the specified ref should be checked out.
./UpdateOrCloneRepository.ps1 -Directory "IGLibScripts" `
-address "https://github.com/ajgorhoe/IGLib.modules.IGLibScripts.git" `
-ref "release/latestrelease"
# Cloning or updating with ABSOLUTE Directory path
# WARNING: Change directory path according to location on your machine!
# Expected: clone or update should be performed on the correct (specified) directory.
./UpdateOrCloneRepository.ps1 `
-Directory "u:/ws/ws/other/ajgor/iglibmodules/IGLibSandbox/scripts/IGLibScripts1" `
-address "https://github.com/ajgorhoe/IGLib.modules.IGLibScripts.git" `
-ref "release/latestrelease"
# Cloning or updating with additional remote specified:
# Remove or not the repository before executing.
# Expected: The remotes should be added.
./UpdateOrCloneRepository.ps1 -Directory "IGLibScripts" `
-address "https://github.com/ajgorhoe/IGLib.modules.IGLibScripts.git" `
-addressSecondary "https://XXXgithub.com/ajgorhoe/IGLib.modules.IGLibScripts.git"
./UpdateOrCloneRepository.ps1 -Directory "IGLibScripts" `
-address "https://github.com/ajgorhoe/IGLib.modules.IGLibScripts.git" `
-addressTertiary "d:\backup_sync\bk_code\git\ig\misc\iglib_modules\IGLibCore\" `
-remoteTertiary "mylocalrepo"
# PROVIDING PARAMETERS (all or part od them) VIA PowerShell FILES / VARIABLES:
# Agreed variable names are used to provide parameter values (the same as
# parameter names, but with a specified prefix - search the script for prefix!).
# When setting parameters in a PowerShell script, the script must be run with .
# (e.g. . ./SettingsCore.ps1) such that variables are reflected in the caller
# environment.
# In order for agreed global variables to provide values of unspecified parameters,
# both the -DefaultFromVars and -Execute switches must be on.
# Cloning or updating with VARIABLES specifying PARAMETERS:
# Variables CurrentRepo_Address and CurrentRepo_Directory defines repository address
# and a relative path to the cloning directory w.r. the script directory.
# Expected: the repository with specified address is cloned (or updated by Git pull)
# in the specified directory relative to the script directory.
# The lines below must be run from the PowerShell command-line:
$CurrentRepo_Directory = "IGLibScripts";
$CurrentRepo_Address = "https://github.com/ajgorhoe/IGLib.modules.IGLibScripts.git";
./UpdateOrCloneRepository.ps1 -DefaultFromVars -Execute
# Cloning or updating with VARIABLES that define script parameters IN THE SETTINGs
# SCRIPT. The settings script must be run with DOT AND SPACE preceding the script
# file path.
# Expected: Parameters take the values specified by global variables set by the
# settings script.
# The lines below must be run from the PowerShell command-line:
. ./TestSettingsIGLibScript.ps1 # this sets variables representing parameters
./UpdateOrCloneRepository.ps1 -DefaultFromVars -Execute
# Cloning or updating by setting VARIABLES that define script parameters while
# some script parameters are also specified explicitly.
# The specified SCRIPT PARAMETERS take PRIORITY over values in variables.
# Expected: Parameters take the values specified by global variables set before
# the script is run, except those parameters that are stated explicitly. E.g.,
# the clone directory is set to "IGLibScripts11" defined as script parameter,
# rather than "IGLibScript" defined in a variable.
# The lines below must be run from the PowerShell command-line:
$CurrentRepo_Directory = "IGLibScripts";
$CurrentRepo_Address = "https://github.com/ajgorhoe/IGLib.modules.IGLibScripts.git";
./UpdateOrCloneRepository.ps1 -Directory "IGLibScripts11" -DefaultFromVars -Execute
# USING the cloning/updating FUNCTION instead of script:
# You can run teh script just to get the function defined, and then run the
# function instead of the script. Rules are similar, except parameter names have
# camel case and there relative directory paths are with respect to the current
# directory rather than script's directory (because execution is not bound to
# the update script).
# Cloning / updating the repository by calling the function UpdateOrCloneRepository
# instead of running the script with the same name. However, we need to run the
# script with no parameters first, such that the script does not get executed.
# This defines the update/clone function, which we call next, providing it with
# the necessary parameters.
# Warning: the script must be called with the preceding dot and space, such that
# the function defined in the script is remains defined in the calling context.
# Expected: Function performs the task in a similar way than the script would.
# Parameters must be specified as camel case, and relative directories are stated
# with respect to the current directory rather than script directory.
. ./UpdateOrCloneRepository.ps1 # running of the script defines the function
UpdateOrCloneRepository -directory "IGLibScripts" `
-address "https://github.com/ajgorhoe/IGLib.modules.IGLibScripts.git"
# Cloning or Updating using specific script for a repository (Update_IGLibScripts.ps1):
# The specific update script always resolves the directories relative to script
# directory.
# Cloning from the same directory that contains the custom script:
# Repository directory is specified as relative path, which should be resolved
# relative to script directory.
# Expected results: The IFLib repository should be cloned or updated at the path
# specified in the specific update script, with relative path resolved relative
# to the custom script directory.
./Update_IGLibScripts.ps1
# Calling the specific (custom) update / clone script from a different directory:
# Expected: the repository directory should have the same path regardless of
# the current directory at the time when the script is called.
Set-Location TestScripts # change to a directory different than script directory
../Update_IGLibScripts.ps1
Set-Location ..