PrimeIntellect/SWE-rebench-V2-Filtered-Easy-Verified huggingface dataset:
Repository: pallets/click (python)
Issue: Generated help with aliased group shows abbreviated command in usage
The typical AliasGroup class overrides the get_command method and returns a matching sub command; however, when help is displayed, the usage information shows the matched abbreviated subcommand instead of the full subcommand name. After debugging, I found that the context.info_name contains the the abbreviated sub command name. I think when a sub-command context is being created, it should use the full command name for this field rather than what the user typed.
Pull request description: Show full subcommand names when using --help in aliasedgroup
Fixes #1422 

Patch:
diff --git a/CHANGES.rst b/CHANGES.rst
index 4842bd5..cd40f78 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -24,6 +24,10 @@ Unreleased
     raises a ``ValueError``. :issue:`1465`
 -   ``echo()`` will not fail when using pytest's ``capsys`` fixture on
     Windows. :issue:`1590`
+-   Resolving commands returns the canonical command name instead of the
+    matched name. This makes behavior such as help text and
+    ``Context.invoked_subcommand`` consistent when using patterns like
+    ``AliasedGroup``. :issue:`1422`
 
 
 Version 7.1.2
diff --git a/src/click/core.py b/src/click/core.py
index 2b05d3f..22f7420 100644
--- a/src/click/core.py
+++ b/src/click/core.py
@@ -1346,7 +1346,7 @@ class MultiCommand(Command):
                 self.parse_args(ctx, ctx.args)
             ctx.fail(f"No such command '{original_cmd_name}'.")
 
-        return cmd_name, cmd, args[1:]
+        return cmd.name, cmd, args[1:]
 
     def get_command(self, ctx, cmd_name):
         """Given a context and a command name, this returns a


Test patch:
diff --git a/tests/test_commands.py b/tests/test_commands.py
index eace114..2467c73 100644
--- a/tests/test_commands.py
+++ b/tests/test_commands.py
@@ -258,6 +258,22 @@ def test_invoked_subcommand(runner):
     assert result.output == "no subcommand, use default\nin subcommand\n"
 
 
+def test_aliased_command_canonical_name(runner):
+    class AliasedGroup(click.Group):
+        def get_command(self, ctx, cmd_name):
+            return push
+
+    cli = AliasedGroup()
+
+    @cli.command()
+    def push():
+        click.echo("push command")
+
+    result = runner.invoke(cli, ["pu", "--help"])
+    assert not result.exception
+    assert result.output.startswith("Usage: root push [OPTIONS]")
+
+
 def test_unprocessed_options(runner):
     @click.command(context_settings=dict(ignore_unknown_options=True))
     @click.argument("args", nargs=-1, type=click.UNPROCESSED)