Skip to content

fix: Display branch name instead of branch id#45

Merged
Ruari-Phipps merged 8 commits intomainfrom
ruari/fix/display_branch_name_correctly
Mar 27, 2026
Merged

fix: Display branch name instead of branch id#45
Ruari-Phipps merged 8 commits intomainfrom
ruari/fix/display_branch_name_correctly

Conversation

@Ruari-Phipps
Copy link
Copy Markdown
Collaborator

@Ruari-Phipps Ruari-Phipps commented Mar 26, 2026

Summary

Display new branch name in CLI when the tool switches branch

Motivation

On push when creating a new branch, users would be shown branch ID not new branch name

Changes

  • Change logger level for some logs to hide on usual CLI usage
  • Make it more clear when a branch id is used in logs
  • When branch_id changes, output this in CLI with new branch name
  • Update auto branch name to exclude sdk-user

Test strategy

  • Added/updated unit tests
  • Manual CLI testing (poly <command>)
  • Tested against a live Agent Studio project
  • N/A (docs, config, or trivial change)

Checklist

  • ruff check . and ruff format --check . pass
  • pytest passes
  • No breaking changes to the poly CLI interface (or migration path documented)
  • Commit messages follow conventional commits

Screenshots / Logs

Screenshot 2026-03-26 at 15 54 24

@github-actions

This comment has been minimized.

branch_name=branch_name,
)
logger.warning(f"Created and switched to new branch '{self.sdk.branch_id}'")
logger.info(f"Created and switched to new branch '{self.sdk.branch_id}'")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is branch_id appropriate in this context for some reason?

src/poly/cli.py Outdated
return

if new_branch_name:
warning(f"Switched to branch '{new_branch_name}'.")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When does this happen? is this when the upstream gets merged -- should we give a bit more detail here?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it is. Its when your current branch is merged/deleted

@github-actions

This comment has been minimized.

src/poly/cli.py Outdated
return

if new_branch_name:
warning(f"Created new branch '{new_branch_name}'.")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can happen when:

  • You are currently on main
  • The branch you are currently on has been merged/deleted, so switches to main. Then its because of the above

Copy link
Copy Markdown
Contributor

@yuenhsi yuenhsi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left a non-blocking question, lgtm otherwise.

We could consider consolidating the warning / info / error import in console.py to also do a logger trace -- also non-blocking

@github-actions

This comment has been minimized.

1 similar comment
@github-actions

This comment has been minimized.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates ADK CLI/logging to avoid exposing opaque branch IDs in typical output, while explicitly surfacing the human-readable branch name when the tool auto-switches/creates a branch during pull/push.

Changes:

  • Adjusts several log messages/levels to reduce branch-ID visibility and clarify when an ID is being logged.
  • Adds CLI (and JSON) output for pull/push when the current branch changes, reporting the new branch name (and ID in JSON).
  • Simplifies auto-generated branch names (removing the email-derived component).

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/poly/resources/function.py Updates warning text when variable references can’t be resolved from mappings.
src/poly/project.py Promotes some “not found” conditions to error-level logging when resolving remote resources by name.
src/poly/handlers/sync_client.py Adjusts branch-related log messages and changes auto branch-name generation.
src/poly/handlers/sdk.py Logs merge-conflict detection at error level.
src/poly/cli.py Adds user-facing output (and JSON fields) when pull/push causes a branch switch/creation.

Comment on lines +946 to 950
if original_branch_id != project.branch_id:
new_branch_name = project.get_current_branch()
if output_json or output_json_projection:
json_output = {
"success": not bool(files_with_conflicts),
Copy link

Copilot AI Mar 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new_branch_name is only assigned inside the if original_branch_id != project.branch_id block, but it’s referenced later (if new_branch_name:) in both JSON and non-JSON paths. If the branch ID doesn’t change, this will raise an UnboundLocalError at runtime. Initialize new_branch_name = None before the conditional (or set it in an else) so the later checks are always safe.

Copilot uses AI. Check for mistakes.
Comment on lines +1006 to 1010
if original_branch_id != project.branch_id:
new_branch_name = project.get_current_branch()
if output_json or output_commands:
json_output = {
"success": push_ok,
Copy link

Copilot AI Mar 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new_branch_name is conditionally assigned only when original_branch_id != project.branch_id, but it’s referenced later in this method (if new_branch_name:). When the branch ID is unchanged, this will raise an UnboundLocalError. Define new_branch_name = None before the conditional (or set it in an else) so the variable always exists.

Copilot uses AI. Check for mistakes.
@Ruari-Phipps Ruari-Phipps changed the title fix: Hide branch id in logs fix: Display branch name instead of branch id Mar 26, 2026
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 6 comments.

Comment on lines 998 to 1019
@@ -992,19 +1004,29 @@ def push(
email=email,
projection_json=projection_json,
)
new_branch_name = None
if original_branch_id != project.branch_id:
new_branch_name = project.get_current_branch()
if output_json or output_commands:
json_output = {
"success": push_ok,
"message": output,
"dry_run": dry_run,
}
if new_branch_name:
json_output["new_branch_name"] = new_branch_name
json_output["new_branch_id"] = project.branch_id
if output_commands:
Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new branch-switch behavior in pull()/push() (including the additional --json fields) isn’t covered by unit tests. Since src/poly/tests/cli_test.py already tests other CLI behaviors, adding tests for (1) when project.branch_id changes and the CLI emits a message, and (2) the extra JSON keys (new_branch_name, new_branch_id) would help prevent regressions.

Copilot generated this review using guidance from repository custom instructions.
Comment on lines +954 to +956
if new_branch_name:
json_output["new_branch_name"] = new_branch_name
json_output["new_branch_id"] = project.branch_id
Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR changes user-facing CLI output and the JSON schema for pull/push (new warning text + new_branch_name/new_branch_id). Per the project’s versioning guidelines, this should come with a minor version bump in pyproject.toml (patch bumps are auto-applied, but output changes should be minor).

Suggested change
if new_branch_name:
json_output["new_branch_name"] = new_branch_name
json_output["new_branch_id"] = project.branch_id

Copilot uses AI. Check for mistakes.
else:
logger.error(f"Branch {branch_id} does not exist.")
logger.error(f"Branch ID:'{branch_id}' does not exist.")
return False
Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

switch_branch() is annotated to return bool, but if fetch_branches() returns no/empty branches the function falls through without returning anything (implicitly None). Add an explicit return False (and possibly a log) for the "no branches returned" case to keep the return type consistent.

Suggested change
return False
return False
else:
logger.error("No branches returned from fetch_branches(); cannot switch branch.")
return False

Copilot uses AI. Check for mistakes.
Comment on lines +1666 to 1669
logger.error(
"Could not retrieve resources for one or both specified names: "
f"before={before_name}, after={after_name}"
)
Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

diff_remote_named_versions() now logs an error when get_remote_resources_by_name() returns empty, but get_remote_resources_by_name() also logs an error for the same failure paths. This will produce duplicated error logs for a single user mistake (unknown name / missing deployment). Consider having only one layer log (e.g., let get_remote_resources_by_name() be silent and raise/return a structured error, or keep logging only at the caller).

Suggested change
logger.error(
"Could not retrieve resources for one or both specified names: "
f"before={before_name}, after={after_name}"
)

Copilot uses AI. Check for mistakes.
# Check if this is a conflict response
if "conflicts" in response_data or "hasConflicts" in response_data:
logger.warning(
logger.error(
Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This conflict path is also logged at a higher level (e.g., SyncClientHandler.merge_branch() logs an error when hasConflicts is true). With this changed to logger.error, a single merge-with-conflicts event will likely emit duplicate error-level logs. Consider logging conflicts at only one layer (or keeping this as warning/info and letting the caller handle user-facing severity).

Suggested change
logger.error(
logger.warning(

Copilot uses AI. Check for mistakes.
src/poly/cli.py Outdated
Comment on lines +1027 to +1028
warning(
f"Current branch no longer exists in Agent Studio. Created and switched to new branch '{new_branch_name}'."
Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The user-facing warning shown after push_project() triggers any time project.branch_id changes, including the normal/expected case of pushing from main (where a new branch is created). In that common scenario, the message is misleading because it claims the current branch no longer exists. Consider distinguishing between (a) switching because the local branch ID was invalid/deleted vs (b) creating a new draft branch from main, and adjust the wording and/or severity accordingly (e.g., only warn for the invalid/deleted case).

Suggested change
warning(
f"Current branch no longer exists in Agent Studio. Created and switched to new branch '{new_branch_name}'."
info(
f"Created and switched to new branch '{new_branch_name}' in Agent Studio."

Copilot uses AI. Check for mistakes.
@github-actions
Copy link
Copy Markdown
Contributor

Coverage Report

Base (main) PR Change
70.4% 70.2% -0.2% ⚠️

Changed file coverage

File Coverage Change
poly/handlers/sdk.py 14.5% +0.1% ✅
poly/handlers/sync_client.py 18.3% -0.1% ⚠️
poly/cli.py 31.3% -0.8% ⚠️

@Ruari-Phipps Ruari-Phipps merged commit 5a54240 into main Mar 27, 2026
3 checks passed
@Ruari-Phipps Ruari-Phipps deleted the ruari/fix/display_branch_name_correctly branch March 27, 2026 11:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants