diff --git a/src/ffx/cli.py b/src/ffx/cli.py index 146db52..387060f 100755 --- a/src/ffx/cli.py +++ b/src/ffx/cli.py @@ -436,10 +436,14 @@ def upgrade(ctx, branch): commandSequences.append(['git', 'reset', '--hard', 'HEAD']) if branch: - commandSequences.append(['git', 'checkout', branch]) + commandSequences += [ + ['git', 'fetch', 'origin', branch], + ['git', 'checkout', '-B', branch, 'FETCH_HEAD'], + ] + else: + commandSequences.append(['git', 'pull']) commandSequences += [ - ['git', 'pull'], [bundlePipPath, 'install', '--upgrade', 'pip', 'setuptools', 'wheel'], [bundlePipPath, 'install', '--editable', '.'], ] diff --git a/tests/assets/dball_S01E89_3_und.sup b/tests/assets/dball_S01E89_3_und.sup new file mode 100644 index 0000000..5f5c1f8 Binary files /dev/null and b/tests/assets/dball_S01E89_3_und.sup differ diff --git a/tests/assets/dball_S01E89_4_und.sup b/tests/assets/dball_S01E89_4_und.sup new file mode 100644 index 0000000..9427590 Binary files /dev/null and b/tests/assets/dball_S01E89_4_und.sup differ diff --git a/tests/unit/test_cli_upgrade.py b/tests/unit/test_cli_upgrade.py index d392f27..f68cc2f 100644 --- a/tests/unit/test_cli_upgrade.py +++ b/tests/unit/test_cli_upgrade.py @@ -57,7 +57,7 @@ class UpgradeCommandTests(unittest.TestCase): self.assertTrue(subprocess_calls[0][1]["capture_output"]) self.assertTrue(subprocess_calls[0][1]["text"]) - def test_upgrade_resets_before_checkout_and_pull_when_user_confirms(self): + def test_upgrade_resets_then_fetches_and_checks_out_requested_branch_when_user_confirms(self): runner = CliRunner() repo_path = "/tmp/ffx-repo" pip_path = "/tmp/ffx-venv/bin/pip" @@ -85,8 +85,8 @@ class UpgradeCommandTests(unittest.TestCase): [ ['git', 'status', '--porcelain', '--untracked-files=no'], ['git', 'reset', '--hard', 'HEAD'], - ['git', 'checkout', 'main'], - ['git', 'pull'], + ['git', 'fetch', 'origin', 'main'], + ['git', 'checkout', '-B', 'main', 'FETCH_HEAD'], [pip_path, 'install', '--upgrade', 'pip', 'setuptools', 'wheel'], [pip_path, 'install', '--editable', '.'], ], @@ -95,6 +95,39 @@ class UpgradeCommandTests(unittest.TestCase): for args, kwargs in subprocess_calls[1:]: self.assertEqual(repo_path, kwargs["cwd"], args) + def test_upgrade_pulls_current_branch_when_no_branch_is_requested(self): + runner = CliRunner() + repo_path = "/tmp/ffx-repo" + pip_path = "/tmp/ffx-venv/bin/pip" + + subprocess_calls = [] + + def fake_run(args, **kwargs): + subprocess_calls.append((args, kwargs)) + if args == ['git', 'status', '--porcelain', '--untracked-files=no']: + return self.make_completed(args, stdout="") + return self.make_completed(args) + + with ( + patch.object(cli, "getBundleRepoPath", return_value=repo_path), + patch.object(cli, "getBundlePipPath", return_value=pip_path), + patch.object(cli.os.path, "isdir", return_value=True), + patch.object(cli.os.path, "isfile", return_value=True), + patch.object(cli.subprocess, "run", side_effect=fake_run), + ): + result = runner.invoke(cli.ffx, ["upgrade"]) + + self.assertEqual(0, result.exit_code, result.output) + self.assertEqual( + [ + ['git', 'status', '--porcelain', '--untracked-files=no'], + ['git', 'pull'], + [pip_path, 'install', '--upgrade', 'pip', 'setuptools', 'wheel'], + [pip_path, 'install', '--editable', '.'], + ], + [call[0] for call in subprocess_calls], + ) + if __name__ == "__main__": unittest.main()