1+ installation
2+ cloneOrUpdateProject: projectDirName remoteName: remoteName in: gitRootPath preview: preview pull: pull
3+ " Clone the project into the gitRootPath directory using the information in the load spec for project. If the project
4+ has already been cloned, then checkout the revision specified in the load spec. The loadSpecs are indexed by
5+ projectDirName to allow for multiple copies of the project in the same directory. Normally, projectDirName
6+ and projectName are the same."
7+
8+ | wasTracing gitTool specDict gitUrls gitProjectRef gitUrl cloned projectName title stdout |
9+ (wasTracing := Rowan projectTools trace isTracing)
10+ ifTrue: [ Rowan projectTools trace stopTracing ].
11+ gitTool := Rowan gitTools.
12+ specDict := self loadSpecs at: projectDirName.
13+ gitUrls := specDict at: ' gitUrls' .
14+ gitUrl := gitUrls at: remoteName.
15+ projectName := specDict at: ' projectName' ifAbsent: [ projectDirName ].
16+ gitProjectRef := gitRootPath asFileReference / projectDirName.
17+ cloned := false .
18+ title := ' Clone or update ' , projectName.
19+ projectDirName = projectName
20+ ifFalse: [ title := title , ' as ' , projectDirName ].
21+ stdout := GsFile stdout.
22+ stdout
23+ cr;
24+ nextPutAll: ' ====================' ;
25+ cr;
26+ nextPutAll: ' Directory ' , gitProjectRef basename printString;
27+ cr;
28+ nextPutAll: ' Project ' , projectName printString;
29+ cr;
30+ nextPutAll: ' ====================' ;
31+ cr;
32+ tab;
33+ nextPutAll: ' Remote ' , remoteName;
34+ cr;
35+ tab;
36+ nextPutAll: ' In directory ' , gitProjectRef fullName.
37+ gitProjectRef exists
38+ ifTrue: [
39+ (Rowan gitTools gitstatusIn: gitProjectRef fullName with: ' --porcelain' ) isEmpty
40+ not
41+ ifTrue: [
42+ " the git repository has unsaved modifications, so abort the operation"
43+ self
44+ error:
45+ ' There are unsaved changes in ' , gitProjectRef fullName printString
46+ , ' . We cannot clone or update a repository with unsaved changes' ] ]
47+ ifFalse: [
48+ | originArg dirNameArg |
49+ " GIT CLONE"
50+ originArg := ' ' .
51+ remoteName ~= ' origin'
52+ ifTrue: [ originArg := ' --origin ' , remoteName , ' ' ].
53+ dirNameArg := ' ' .
54+ projectName = projectDirName
55+ ifFalse: [ dirNameArg := ' ' , projectDirName ].
56+ stdout
57+ cr;
58+ tab;
59+ nextPutAll: ' Cloning ' , gitUrl , ' to ' , projectDirName.
60+ stdout
61+ cr;
62+ nextPutAll:
63+ (gitTool
64+ gitcloneIn: gitRootPath
65+ with: originArg , gitUrl , dirNameArg
66+ logging: false ).
67+ cloned := true ].
68+ (specDict at: ' revision' ifAbsent: [ ])
69+ ifNotNil: [ :revision |
70+ stdout
71+ cr;
72+ tab;
73+ nextPutAll: ' Set ' , projectDirName , ' revision to ' , revision.
74+ cloned
75+ ifTrue: [
76+ " GIT SWITCH"
77+ stdout
78+ cr;
79+ tab;
80+ nextPutAll:
81+ ' Switch (after clone) ' , remoteName , ' /' , revision , ' -t -C ' , revision;
82+ cr;
83+ nextPutAll:
84+ (gitTool
85+ performGitCommand: ' switch'
86+ in: gitProjectRef fullName
87+ with: ' ' , remoteName , ' /' , revision , ' -t -C ' , revision) ]
88+ ifFalse: [
89+ pull
90+ ifTrue: [
91+ " GIT FETCH
92+ GIT SWITCH
93+ GIT PULL"
94+ stdout
95+ cr;
96+ tab;
97+ nextPutAll: ' Fetch --all ' .
98+ stdout
99+ cr;
100+ nextPutAll: (gitTool gitfetchIn: gitProjectRef with: ' --all' ).
101+ stdout
102+ cr;
103+ tab;
104+ nextPutAll:
105+ ' Switch (after fetch) ' , remoteName , ' /' , revision , ' -t -C ' , revision.
106+ stdout
107+ cr;
108+ nextPutAll:
109+ (gitTool
110+ performGitCommand: ' switch'
111+ in: gitProjectRef fullName
112+ with: ' ' , remoteName , ' /' , revision , ' -t -C ' , revision).
113+ stdout
114+ cr;
115+ tab;
116+ nextPutAll:
117+ ' Pull ' , projectName , ' revision: ' , revision , ' from remote: ' , remoteName.
118+ stdout
119+ cr;
120+ nextPutAll:
121+ (gitTool gitpullIn: gitProjectRef fullName remote: remoteName branch: revision) ]
122+ ifFalse: [
123+ preview
124+ ifTrue: [
125+ | currentBranchName |
126+ currentBranchName := Rowan gitTools
127+ gitBranchNameIn: gitProjectRef fullName.
128+ stdout
129+ cr;
130+ nextPutAll: ' Current BRANCHNAME: ' , currentBranchName.
131+ revision = currentBranchName
132+ ifTrue: [
133+ stdout
134+ cr;
135+ nextPutAll: ' PREVIEW:: FETCH and PULL ' , currentBranchName ]
136+ ifFalse: [
137+ stdout
138+ cr;
139+ nextPutAll: ' ------ Preview FETCH,' ;
140+ cr;
141+ nextPutAll: ' ***' ;
142+ tab;
143+ nextPutAll: ' SWITCH TO ' , revision , ' FROM ' , currentBranchName;
144+ cr;
145+ tab;
146+ nextPutAll: ' and PULL' ;
147+ nextPutAll: ' ' , revision ] ] ] ] ].
148+ cloned
149+ ifTrue: [
150+ " GIT REMOTE ADD"
151+ (gitUrls keys reject: [ :each | each = remoteName ])
152+ do: [ :theRemote |
153+ self
154+ gitAddRemoteIn: gitProjectRef fullName
155+ remote: theRemote
156+ gitUrl: (gitUrls at: theRemote) ]. " GIT FETCH --all"
157+ stdout
158+ cr;
159+ tab;
160+ nextPutAll: ' Fetch --all ' .
161+ stdout
162+ cr;
163+ nextPutAll: (gitTool gitfetchIn: gitProjectRef with: ' --all' ) ].
164+ stdout
165+ cr;
166+ nextPutAll: ' ------ branches' ;
167+ cr;
168+ nextPutAll: (Rowan gitTools gitbranchIn: gitProjectRef fullName with: ' ' );
169+ cr;
170+ nextPutAll: ' ==========' ;
171+ cr;
172+ nextPutAll: ' ==========' ;
173+ cr.
174+ wasTracing
175+ ifTrue: [ Rowan projectTools trace startTracing ]
0 commit comments