ff
This commit is contained in:
@@ -393,6 +393,41 @@ def getTrackedGitChanges(repoPath):
|
||||
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):
|
||||
if not os.path.isfile(scriptPath):
|
||||
raise click.ClickException(f"{missingDescription} not found at {scriptPath}")
|
||||
@@ -515,6 +550,10 @@ def upgrade(ctx, branch):
|
||||
if completed.returncode != 0:
|
||||
ctx.exit(completed.returncode)
|
||||
|
||||
upgradedBranch = getCurrentGitBranch(bundleRepoPath)
|
||||
upgradedVersion = getBundleVersion(bundleRepoPath)
|
||||
click.echo(f"Updated FFX to version {upgradedVersion} from branch {upgradedBranch}.")
|
||||
|
||||
|
||||
@ffx.command()
|
||||
@click.pass_context
|
||||
|
||||
@@ -68,11 +68,14 @@ class UpgradeCommandTests(unittest.TestCase):
|
||||
subprocess_calls.append((args, kwargs))
|
||||
if args == ['git', 'status', '--porcelain', '--untracked-files=no']:
|
||||
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)
|
||||
|
||||
with (
|
||||
patch.object(cli, "getBundleRepoPath", return_value=repo_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, "isfile", return_value=True),
|
||||
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.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(
|
||||
[
|
||||
['git', 'status', '--porcelain', '--untracked-files=no'],
|
||||
@@ -89,6 +93,7 @@ class UpgradeCommandTests(unittest.TestCase):
|
||||
['git', 'checkout', '-B', 'main', 'FETCH_HEAD'],
|
||||
[pip_path, 'install', '--upgrade', 'pip', 'setuptools', 'wheel'],
|
||||
[pip_path, 'install', '--editable', '.'],
|
||||
['git', 'rev-parse', '--abbrev-ref', 'HEAD'],
|
||||
],
|
||||
[call[0] for call in subprocess_calls],
|
||||
)
|
||||
@@ -106,11 +111,14 @@ class UpgradeCommandTests(unittest.TestCase):
|
||||
subprocess_calls.append((args, kwargs))
|
||||
if args == ['git', 'status', '--porcelain', '--untracked-files=no']:
|
||||
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)
|
||||
|
||||
with (
|
||||
patch.object(cli, "getBundleRepoPath", return_value=repo_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, "isfile", return_value=True),
|
||||
patch.object(cli.subprocess, "run", side_effect=fake_run),
|
||||
@@ -118,12 +126,14 @@ class UpgradeCommandTests(unittest.TestCase):
|
||||
result = runner.invoke(cli.ffx, ["upgrade"])
|
||||
|
||||
self.assertEqual(0, result.exit_code, result.output)
|
||||
self.assertIn("Updated FFX to version 0.3.3 from branch develop.", result.output)
|
||||
self.assertEqual(
|
||||
[
|
||||
['git', 'status', '--porcelain', '--untracked-files=no'],
|
||||
['git', 'pull'],
|
||||
[pip_path, 'install', '--upgrade', 'pip', 'setuptools', 'wheel'],
|
||||
[pip_path, 'install', '--editable', '.'],
|
||||
['git', 'rev-parse', '--abbrev-ref', 'HEAD'],
|
||||
],
|
||||
[call[0] for call in subprocess_calls],
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user