ff
This commit is contained in:
@@ -393,6 +393,41 @@ def getTrackedGitChanges(repoPath):
|
|||||||
return [line for line in completed.stdout.splitlines() if line.strip()]
|
return [line for line in completed.stdout.splitlines() if line.strip()]
|
||||||
|
|
||||||
|
|
||||||
|
def getCurrentGitBranch(repoPath):
|
||||||
|
completed = subprocess.run(
|
||||||
|
['git', 'rev-parse', '--abbrev-ref', 'HEAD'],
|
||||||
|
cwd=repoPath,
|
||||||
|
capture_output=True,
|
||||||
|
text=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
if completed.returncode != 0:
|
||||||
|
commandLabel = 'git rev-parse --abbrev-ref HEAD'
|
||||||
|
errorOutput = completed.stderr.strip() or completed.stdout.strip()
|
||||||
|
raise click.ClickException(
|
||||||
|
f"Unable to inspect bundle repository branch using '{commandLabel}': {errorOutput}"
|
||||||
|
)
|
||||||
|
|
||||||
|
return completed.stdout.strip() or "unknown"
|
||||||
|
|
||||||
|
|
||||||
|
def getBundleVersion(repoPath):
|
||||||
|
constantsPath = os.path.join(repoPath, 'src', 'ffx', 'constants.py')
|
||||||
|
|
||||||
|
try:
|
||||||
|
with open(constantsPath, encoding='utf-8') as constantsFile:
|
||||||
|
for line in constantsFile:
|
||||||
|
strippedLine = line.strip()
|
||||||
|
if strippedLine.startswith('VERSION=') or strippedLine.startswith('VERSION ='):
|
||||||
|
return strippedLine.split('=', 1)[1].strip().strip('"\'')
|
||||||
|
except OSError as ex:
|
||||||
|
raise click.ClickException(
|
||||||
|
f"Unable to inspect bundle version from {constantsPath}: {ex}"
|
||||||
|
) from ex
|
||||||
|
|
||||||
|
raise click.ClickException(f"Unable to inspect bundle version from {constantsPath}")
|
||||||
|
|
||||||
|
|
||||||
def runScriptWrapper(ctx, scriptPath, missingDescription, commandArgs):
|
def runScriptWrapper(ctx, scriptPath, missingDescription, commandArgs):
|
||||||
if not os.path.isfile(scriptPath):
|
if not os.path.isfile(scriptPath):
|
||||||
raise click.ClickException(f"{missingDescription} not found at {scriptPath}")
|
raise click.ClickException(f"{missingDescription} not found at {scriptPath}")
|
||||||
@@ -515,6 +550,10 @@ def upgrade(ctx, branch):
|
|||||||
if completed.returncode != 0:
|
if completed.returncode != 0:
|
||||||
ctx.exit(completed.returncode)
|
ctx.exit(completed.returncode)
|
||||||
|
|
||||||
|
upgradedBranch = getCurrentGitBranch(bundleRepoPath)
|
||||||
|
upgradedVersion = getBundleVersion(bundleRepoPath)
|
||||||
|
click.echo(f"Updated FFX to version {upgradedVersion} from branch {upgradedBranch}.")
|
||||||
|
|
||||||
|
|
||||||
@ffx.command()
|
@ffx.command()
|
||||||
@click.pass_context
|
@click.pass_context
|
||||||
|
|||||||
@@ -68,11 +68,14 @@ class UpgradeCommandTests(unittest.TestCase):
|
|||||||
subprocess_calls.append((args, kwargs))
|
subprocess_calls.append((args, kwargs))
|
||||||
if args == ['git', 'status', '--porcelain', '--untracked-files=no']:
|
if args == ['git', 'status', '--porcelain', '--untracked-files=no']:
|
||||||
return self.make_completed(args, stdout="M src/ffx/constants.py\n")
|
return self.make_completed(args, stdout="M src/ffx/constants.py\n")
|
||||||
|
if args == ['git', 'rev-parse', '--abbrev-ref', 'HEAD']:
|
||||||
|
return self.make_completed(args, stdout="main\n")
|
||||||
return self.make_completed(args)
|
return self.make_completed(args)
|
||||||
|
|
||||||
with (
|
with (
|
||||||
patch.object(cli, "getBundleRepoPath", return_value=repo_path),
|
patch.object(cli, "getBundleRepoPath", return_value=repo_path),
|
||||||
patch.object(cli, "getBundlePipPath", return_value=pip_path),
|
patch.object(cli, "getBundlePipPath", return_value=pip_path),
|
||||||
|
patch.object(cli, "getBundleVersion", return_value="0.3.2"),
|
||||||
patch.object(cli.os.path, "isdir", return_value=True),
|
patch.object(cli.os.path, "isdir", return_value=True),
|
||||||
patch.object(cli.os.path, "isfile", return_value=True),
|
patch.object(cli.os.path, "isfile", return_value=True),
|
||||||
patch.object(cli.subprocess, "run", side_effect=fake_run),
|
patch.object(cli.subprocess, "run", side_effect=fake_run),
|
||||||
@@ -81,6 +84,7 @@ class UpgradeCommandTests(unittest.TestCase):
|
|||||||
|
|
||||||
self.assertEqual(0, result.exit_code, result.output)
|
self.assertEqual(0, result.exit_code, result.output)
|
||||||
self.assertIn("Tracked local changes detected in the bundle repository:", result.output)
|
self.assertIn("Tracked local changes detected in the bundle repository:", result.output)
|
||||||
|
self.assertIn("Updated FFX to version 0.3.2 from branch main.", result.output)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
[
|
[
|
||||||
['git', 'status', '--porcelain', '--untracked-files=no'],
|
['git', 'status', '--porcelain', '--untracked-files=no'],
|
||||||
@@ -89,6 +93,7 @@ class UpgradeCommandTests(unittest.TestCase):
|
|||||||
['git', 'checkout', '-B', 'main', 'FETCH_HEAD'],
|
['git', 'checkout', '-B', 'main', 'FETCH_HEAD'],
|
||||||
[pip_path, 'install', '--upgrade', 'pip', 'setuptools', 'wheel'],
|
[pip_path, 'install', '--upgrade', 'pip', 'setuptools', 'wheel'],
|
||||||
[pip_path, 'install', '--editable', '.'],
|
[pip_path, 'install', '--editable', '.'],
|
||||||
|
['git', 'rev-parse', '--abbrev-ref', 'HEAD'],
|
||||||
],
|
],
|
||||||
[call[0] for call in subprocess_calls],
|
[call[0] for call in subprocess_calls],
|
||||||
)
|
)
|
||||||
@@ -106,11 +111,14 @@ class UpgradeCommandTests(unittest.TestCase):
|
|||||||
subprocess_calls.append((args, kwargs))
|
subprocess_calls.append((args, kwargs))
|
||||||
if args == ['git', 'status', '--porcelain', '--untracked-files=no']:
|
if args == ['git', 'status', '--porcelain', '--untracked-files=no']:
|
||||||
return self.make_completed(args, stdout="")
|
return self.make_completed(args, stdout="")
|
||||||
|
if args == ['git', 'rev-parse', '--abbrev-ref', 'HEAD']:
|
||||||
|
return self.make_completed(args, stdout="develop\n")
|
||||||
return self.make_completed(args)
|
return self.make_completed(args)
|
||||||
|
|
||||||
with (
|
with (
|
||||||
patch.object(cli, "getBundleRepoPath", return_value=repo_path),
|
patch.object(cli, "getBundleRepoPath", return_value=repo_path),
|
||||||
patch.object(cli, "getBundlePipPath", return_value=pip_path),
|
patch.object(cli, "getBundlePipPath", return_value=pip_path),
|
||||||
|
patch.object(cli, "getBundleVersion", return_value="0.3.3"),
|
||||||
patch.object(cli.os.path, "isdir", return_value=True),
|
patch.object(cli.os.path, "isdir", return_value=True),
|
||||||
patch.object(cli.os.path, "isfile", return_value=True),
|
patch.object(cli.os.path, "isfile", return_value=True),
|
||||||
patch.object(cli.subprocess, "run", side_effect=fake_run),
|
patch.object(cli.subprocess, "run", side_effect=fake_run),
|
||||||
@@ -118,12 +126,14 @@ class UpgradeCommandTests(unittest.TestCase):
|
|||||||
result = runner.invoke(cli.ffx, ["upgrade"])
|
result = runner.invoke(cli.ffx, ["upgrade"])
|
||||||
|
|
||||||
self.assertEqual(0, result.exit_code, result.output)
|
self.assertEqual(0, result.exit_code, result.output)
|
||||||
|
self.assertIn("Updated FFX to version 0.3.3 from branch develop.", result.output)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
[
|
[
|
||||||
['git', 'status', '--porcelain', '--untracked-files=no'],
|
['git', 'status', '--porcelain', '--untracked-files=no'],
|
||||||
['git', 'pull'],
|
['git', 'pull'],
|
||||||
[pip_path, 'install', '--upgrade', 'pip', 'setuptools', 'wheel'],
|
[pip_path, 'install', '--upgrade', 'pip', 'setuptools', 'wheel'],
|
||||||
[pip_path, 'install', '--editable', '.'],
|
[pip_path, 'install', '--editable', '.'],
|
||||||
|
['git', 'rev-parse', '--abbrev-ref', 'HEAD'],
|
||||||
],
|
],
|
||||||
[call[0] for call in subprocess_calls],
|
[call[0] for call in subprocess_calls],
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user