diff options
-rw-r--r-- | git_superproject.py | 42 | ||||
-rw-r--r-- | tests/fixtures/test.gitconfig | 4 |
2 files changed, 27 insertions, 19 deletions
diff --git a/git_superproject.py b/git_superproject.py index 8769355c..c677924f 100644 --- a/git_superproject.py +++ b/git_superproject.py | |||
@@ -122,11 +122,19 @@ class Superproject(object): | |||
122 | branch = branch[len(R_HEADS):] | 122 | branch = branch[len(R_HEADS):] |
123 | return branch | 123 | return branch |
124 | 124 | ||
125 | def _LogError(self, message): | 125 | def _LogMessage(self, message): |
126 | """Logs message to stderr and _git_event_log.""" | 126 | """Logs message to stderr and _git_event_log.""" |
127 | print(message, file=sys.stderr) | 127 | print(message, file=sys.stderr) |
128 | self._git_event_log.ErrorEvent(message, '') | 128 | self._git_event_log.ErrorEvent(message, '') |
129 | 129 | ||
130 | def _LogError(self, message): | ||
131 | """Logs error message to stderr and _git_event_log.""" | ||
132 | self._LogMessage(f'repo superproject error: {message}') | ||
133 | |||
134 | def _LogWarning(self, message): | ||
135 | """Logs warning message to stderr and _git_event_log.""" | ||
136 | self._LogMessage(f'repo superproject warning: {message}') | ||
137 | |||
130 | def _Init(self): | 138 | def _Init(self): |
131 | """Sets up a local Git repository to get a copy of a superproject. | 139 | """Sets up a local Git repository to get a copy of a superproject. |
132 | 140 | ||
@@ -146,8 +154,8 @@ class Superproject(object): | |||
146 | capture_stderr=True) | 154 | capture_stderr=True) |
147 | retval = p.Wait() | 155 | retval = p.Wait() |
148 | if retval: | 156 | if retval: |
149 | self._LogError(f'repo: error: git init call failed, command: git {cmd}, ' | 157 | self._LogWarning(f'git init call failed, command: git {cmd}, ' |
150 | f'return code: {retval}, stderr: {p.stderr}') | 158 | f'return code: {retval}, stderr: {p.stderr}') |
151 | return False | 159 | return False |
152 | return True | 160 | return True |
153 | 161 | ||
@@ -161,7 +169,7 @@ class Superproject(object): | |||
161 | True if fetch is successful, or False. | 169 | True if fetch is successful, or False. |
162 | """ | 170 | """ |
163 | if not os.path.exists(self._work_git): | 171 | if not os.path.exists(self._work_git): |
164 | self._LogError(f'git fetch missing directory: {self._work_git}') | 172 | self._LogWarning(f'git fetch missing directory: {self._work_git}') |
165 | return False | 173 | return False |
166 | if not git_require((2, 28, 0)): | 174 | if not git_require((2, 28, 0)): |
167 | print('superproject requires a git version 2.28 or later', file=sys.stderr) | 175 | print('superproject requires a git version 2.28 or later', file=sys.stderr) |
@@ -176,8 +184,8 @@ class Superproject(object): | |||
176 | capture_stderr=True) | 184 | capture_stderr=True) |
177 | retval = p.Wait() | 185 | retval = p.Wait() |
178 | if retval: | 186 | if retval: |
179 | self._LogError(f'repo: error: git fetch call failed, command: git {cmd}, ' | 187 | self._LogWarning(f'git fetch call failed, command: git {cmd}, ' |
180 | f'return code: {retval}, stderr: {p.stderr}') | 188 | f'return code: {retval}, stderr: {p.stderr}') |
181 | return False | 189 | return False |
182 | return True | 190 | return True |
183 | 191 | ||
@@ -190,7 +198,7 @@ class Superproject(object): | |||
190 | data: data returned from 'git ls-tree ...' instead of None. | 198 | data: data returned from 'git ls-tree ...' instead of None. |
191 | """ | 199 | """ |
192 | if not os.path.exists(self._work_git): | 200 | if not os.path.exists(self._work_git): |
193 | self._LogError(f'git ls-tree missing directory: {self._work_git}') | 201 | self._LogWarning(f'git ls-tree missing directory: {self._work_git}') |
194 | return None | 202 | return None |
195 | data = None | 203 | data = None |
196 | branch = 'HEAD' if not self._branch else self._branch | 204 | branch = 'HEAD' if not self._branch else self._branch |
@@ -205,8 +213,8 @@ class Superproject(object): | |||
205 | if retval == 0: | 213 | if retval == 0: |
206 | data = p.stdout | 214 | data = p.stdout |
207 | else: | 215 | else: |
208 | self._LogError(f'repo: error: git ls-tree call failed, command: git {cmd}, ' | 216 | self._LogWarning(f'git ls-tree call failed, command: git {cmd}, ' |
209 | f'return code: {retval}, stderr: {p.stderr}') | 217 | f'return code: {retval}, stderr: {p.stderr}') |
210 | return data | 218 | return data |
211 | 219 | ||
212 | def Sync(self): | 220 | def Sync(self): |
@@ -219,15 +227,15 @@ class Superproject(object): | |||
219 | 'address described in `repo version`', file=sys.stderr) | 227 | 'address described in `repo version`', file=sys.stderr) |
220 | 228 | ||
221 | if not self._manifest.superproject: | 229 | if not self._manifest.superproject: |
222 | self._LogError(f'repo error: superproject tag is not defined in manifest: ' | 230 | self._LogWarning(f'superproject tag is not defined in manifest: ' |
223 | f'{self._manifest.manifestFile}') | 231 | f'{self._manifest.manifestFile}') |
224 | return SyncResult(False, False) | 232 | return SyncResult(False, False) |
225 | 233 | ||
226 | should_exit = True | 234 | should_exit = True |
227 | url = self._manifest.superproject['remote'].url | 235 | url = self._manifest.superproject['remote'].url |
228 | if not url: | 236 | if not url: |
229 | self._LogError(f'repo error: superproject URL is not defined in manifest: ' | 237 | self._LogWarning(f'superproject URL is not defined in manifest: ' |
230 | f'{self._manifest.manifestFile}') | 238 | f'{self._manifest.manifestFile}') |
231 | return SyncResult(False, should_exit) | 239 | return SyncResult(False, should_exit) |
232 | 240 | ||
233 | if not self._Init(): | 241 | if not self._Init(): |
@@ -277,7 +285,7 @@ class Superproject(object): | |||
277 | manifest_path: Path name of the file into which manifest is written instead of None. | 285 | manifest_path: Path name of the file into which manifest is written instead of None. |
278 | """ | 286 | """ |
279 | if not os.path.exists(self._superproject_path): | 287 | if not os.path.exists(self._superproject_path): |
280 | self._LogError(f'error: missing superproject directory: {self._superproject_path}') | 288 | self._LogWarning(f'missing superproject directory: {self._superproject_path}') |
281 | return None | 289 | return None |
282 | manifest_str = self._manifest.ToXml(groups=self._manifest.GetGroupsStr()).toxml() | 290 | manifest_str = self._manifest.ToXml(groups=self._manifest.GetGroupsStr()).toxml() |
283 | manifest_path = self._manifest_path | 291 | manifest_path = self._manifest_path |
@@ -285,7 +293,7 @@ class Superproject(object): | |||
285 | with open(manifest_path, 'w', encoding='utf-8') as fp: | 293 | with open(manifest_path, 'w', encoding='utf-8') as fp: |
286 | fp.write(manifest_str) | 294 | fp.write(manifest_str) |
287 | except IOError as e: | 295 | except IOError as e: |
288 | self._LogError(f'error: cannot write manifest to : {manifest_path} {e}') | 296 | self._LogError(f'cannot write manifest to : {manifest_path} {e}') |
289 | return None | 297 | return None |
290 | return manifest_path | 298 | return manifest_path |
291 | 299 | ||
@@ -336,8 +344,8 @@ class Superproject(object): | |||
336 | # If superproject doesn't have a commit id for a project, then report an | 344 | # If superproject doesn't have a commit id for a project, then report an |
337 | # error event and continue as if do not use superproject is specified. | 345 | # error event and continue as if do not use superproject is specified. |
338 | if projects_missing_commit_ids: | 346 | if projects_missing_commit_ids: |
339 | self._LogError(f'error: please file a bug using {self._manifest.contactinfo.bugurl} ' | 347 | self._LogWarning(f'please file a bug using {self._manifest.contactinfo.bugurl} ' |
340 | f'to report missing commit_ids for: {projects_missing_commit_ids}') | 348 | f'to report missing commit_ids for: {projects_missing_commit_ids}') |
341 | return UpdateProjectsResult(None, False) | 349 | return UpdateProjectsResult(None, False) |
342 | 350 | ||
343 | for project in projects: | 351 | for project in projects: |
diff --git a/tests/fixtures/test.gitconfig b/tests/fixtures/test.gitconfig index d71f8e73..d69e162c 100644 --- a/tests/fixtures/test.gitconfig +++ b/tests/fixtures/test.gitconfig | |||
@@ -12,10 +12,10 @@ | |||
12 | intm = 10m | 12 | intm = 10m |
13 | intg = 10g | 13 | intg = 10g |
14 | [repo "syncstate.main"] | 14 | [repo "syncstate.main"] |
15 | synctime = 2021-07-29T22:07:43.463365Z | 15 | synctime = 2021-08-11T17:54:14.530286Z |
16 | version = 1 | 16 | version = 1 |
17 | [repo "syncstate.sys"] | 17 | [repo "syncstate.sys"] |
18 | argv = ['/usr/bin/pytest-3'] | 18 | argv = ['/usr/bin/pytest-3', '-v'] |
19 | [repo "syncstate.superproject"] | 19 | [repo "syncstate.superproject"] |
20 | test = false | 20 | test = false |
21 | [repo "syncstate.options"] | 21 | [repo "syncstate.options"] |