|
9 | 9 | from vcstool.clients.git import GitClient # noqa: E402
|
10 | 10 | from vcstool.util import rmtree # noqa: E402
|
11 | 11 |
|
| 12 | +file_uri_scheme = 'file://' if sys.platform != 'win32' else 'file:///' |
| 13 | + |
12 | 14 | REPOS_FILE = os.path.join(os.path.dirname(__file__), 'list.repos')
|
13 |
| -REPOS_FILE_URL = 'file://' + REPOS_FILE |
| 15 | +REPOS_FILE_URL = file_uri_scheme + REPOS_FILE |
14 | 16 | REPOS2_FILE = os.path.join(os.path.dirname(__file__), 'list2.repos')
|
15 | 17 | TEST_WORKSPACE = os.path.join(
|
16 | 18 | os.path.dirname(os.path.dirname(__file__)), 'test_workspace')
|
@@ -189,6 +191,11 @@ def test_pull_api(self):
|
189 | 191 | invocation.
|
190 | 192 | """
|
191 | 193 | output = output.replace(pull_warning, '')
|
| 194 | + # the output was retrieved through a different way here |
| 195 | + output = adapt_command_output(output.encode()).decode() |
| 196 | + if sys.platform == 'win32': |
| 197 | + # it does not include carriage return characters on Windows |
| 198 | + output = output.replace('\n', '\r\n') |
192 | 199 | expected = get_expected_output('pull').decode()
|
193 | 200 | assert output == expected
|
194 | 201 |
|
@@ -216,6 +223,12 @@ def test_reimport(self):
|
216 | 223 | output = run_command(
|
217 | 224 | 'import', ['--force', '--input', REPOS_FILE, '.'])
|
218 | 225 | expected = get_expected_output('reimport_force')
|
| 226 | + # on Windows, the "Already on 'master'" message is after the |
| 227 | + # "Your branch is up to date with ..." message, so remove it |
| 228 | + # from both output and expected strings |
| 229 | + if sys.platform == 'win32': |
| 230 | + output = output.replace(b"Already on 'master'\r\n", b'') |
| 231 | + expected = expected.replace(b"Already on 'master'\r\n", b'') |
219 | 232 | # newer git versions don't append three dots after the commit hash
|
220 | 233 | assert output == expected or output == expected.replace(b'... ', b' ')
|
221 | 234 |
|
@@ -352,6 +365,11 @@ def run_command(command, args=None, subfolder=None):
|
352 | 365 | output = subprocess.check_output(
|
353 | 366 | [sys.executable, script] + (args or []),
|
354 | 367 | stderr=subprocess.STDOUT, cwd=cwd, env=env)
|
| 368 | + return adapt_command_output(output, cwd) |
| 369 | + |
| 370 | + |
| 371 | +def adapt_command_output(output, cwd=None): |
| 372 | + assert type(output) == bytes |
355 | 373 | # replace message from older git versions
|
356 | 374 | output = output.replace(
|
357 | 375 | b'git checkout -b new_branch_name',
|
@@ -386,6 +404,23 @@ def run_command(command, args=None, subfolder=None):
|
386 | 404 | # replace GitHub SSH clone URL
|
387 | 405 | output = output.replace(
|
388 | 406 | b'[email protected]:', b'https://github.com/')
|
| 407 | + if sys.platform == 'win32': |
| 408 | + if cwd: |
| 409 | + # on Windows, git prints full path to repos |
| 410 | + # in some messages, so make it relative |
| 411 | + cwd_abs = os.path.abspath(cwd).replace('\\', '/') |
| 412 | + output = output.replace(cwd_abs.encode(), b'.') |
| 413 | + # replace path separators in specific paths; |
| 414 | + # this is less likely to cause wrong test results |
| 415 | + paths_to_replace = [ |
| 416 | + (b'.\\immutable', b'./immutable'), |
| 417 | + (b'.\\vcstool', b'./vcstool'), |
| 418 | + (b'.\\without_version', b'./without_version'), |
| 419 | + (b'\\hash', b'/hash'), |
| 420 | + (b'\\tag', b'/tag'), |
| 421 | + ] |
| 422 | + for before, after in paths_to_replace: |
| 423 | + output = output.replace(before, after) |
389 | 424 | return output
|
390 | 425 |
|
391 | 426 |
|
|
0 commit comments