Skip to content

rtk git branch --form: a long option abbreviation is not read as --format, adding a blank line #5174

Open

Description

@KuSh

rtk git branch --form=<template>, an abbreviation of --format that git accepts, is not read as --format, so the listing goes through the default-layout compaction and comes back with an extra blank line.

Reproduction

D=$(mktemp -d); cd "$D"; git init -q -b main . && git -c user.name=t -c user.email=t@t commit -q --allow-empty -m init
export LC_ALL=C

git branch --format='%(refname:short)' | od -c    # main\n
rtk git branch --format='%(refname:short)' | od -c  # main\n          (git's bytes)

git branch --form='%(refname:short)' | od -c      # main\n
rtk git branch --form='%(refname:short)' | od -c    # main\n\n        <- extra blank line

Built from develop at 3ab08be (Linux, git 2.53.0).

Mechanism

BRANCH_GRAMMAR in src/cmds/git/git_cmd.rs is declared with Dialect::Posix, which has no unique-prefix abbreviation, so --form is an undeclared flag. It is not a list flag either, so run_branch adds -a and runs filter_branch_output over lines that are the caller's template, not git's default layout.

git's option parser accepts any unambiguous prefix of a long option (--form and --forma work; --for is ambiguous between --force and --format). The same holds for the other git grammars declared with Dialect::Posix, so this is not specific to branch.

Open question

Whether a git grammar should opt into Abbreviation::UniquePrefix. That changes how every git flag token is read, so it wants a pass over each git grammar rather than a one-flag patch. I am offering the work, not asking anyone to take it on.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions