Skip to content

Incorrect arg splitting when using .. syntax for git log #15279

Closed

Description

$latestTag = git describe --tags --abbrev=0
git log $latestTag..HEAD --oneline

Expected behavior

Git log output such as

ac9ca9d (HEAD -> main, origin/main, origin/HEAD) added tree
7834bff indentation

Actual behavior

nothing is returned 

Environment data

Name                           Value
----                           -----
PSVersion                      7.2.0-preview.3
PSEdition                      Core
GitCommitId                    7.2.0-preview.3
OS                             Microsoft Windows 10.0.19042
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Additional info

Using

{ echo $tag..HEAD }.Ast.EndBlock.Statements[0].PipelineElements[0].CommandElements

StringConstantType : BareWord
Value              : echo
StaticType         : System.String
Extent             : echo
Parent             : echo $tag..HEAD

VariablePath : tag
Splatted     : False
StaticType   : System.Object
Extent       : $tag
Parent       : echo $tag..HEAD

StringConstantType : BareWord
Value              : ..HEAD
StaticType         : System.String
Extent             : ..HEAD
Parent             : echo $tag..HEAD

It's interpreting as two different parameters
As mentioned in this Twitter thread, this can be solved by using double quotes like so

 git log "$latestTag..HEAD" --oneline

Activity

  1. added
    Needs-Triage
    on Apr 20, 2021
  2. iSazonov commented on Apr 20, 2021

    @iSazonov
    Collaborator

    Does this work before 7.2.0-preview.3? In 7.1?

  3. added
    WG-Engine
    on Apr 20, 2021
  4. mklement0 commented on Apr 20, 2021

    @mklement0
    Contributor

    It's definitely surprising and unhelpful behavior that has been in place since v3 (in v2 you get a "Missing property name after reference operator." error).

    Just to provide some background:

    An argument that looks like a property access is usually treated as such:

    PS> cmd /c echo $PSHOME.Length # with .HEAD, $null would result, and no argument would be passed.
    35  # e.g.

    Seemingly, if what follows the first . isn't a syntactically valid property name, the argument is simply broken in two at the first . (and the variable reference is expanded and stringified as a whole), whereas it would make much more sense to implicitly treat the argument as an expandable string (as if it were enclosed in "..."), which is what otherwise happens, e.g., with
    cmd /c echo /$PSHOME..HEAD (because the token doesn't start with $).

    The rules around how unquoted compound tokens are parsed and sometimes broken up in argument mode are surprisingly complex, and there are other surprises - see #6467 and MicrosoftDocs/PowerShell-Docs#3440 (comment)

    You've already stated the workaround - double-quoting - which is always a way to avoid ambiguity, but it would certainly be nice if that weren't necessary.

    The change in behavior from v2 to v3 indicates that fallback behavior was deliberately introduced - it's just that the fallback chosen is unhelpful.

  5. SteveL-MSFT commented on Apr 20, 2021

    @SteveL-MSFT
    Member

    With the new 7.2-preview.5 native command parameter binding tracing, the problem is that git is being sent the value of $tag and ..HEAD as two parameters instead of one:

    PS> $tag = git describe --tags --abbrev=0
    PS> trace-command -Option ExecutionFlow -Name ParameterBinding -Expression { git log $tag..HEAD --oneline } -PSHost
    DEBUG: 2021-04-20 06:52:38.3359 ParameterBinding Information: 0 : BIND NAMED native application line args [/usr/bin/git]
    DEBUG: 2021-04-20 06:52:38.3468 ParameterBinding Information: 0 :     BIND cmd line arg [log] to position [0]
    DEBUG: 2021-04-20 06:52:38.3475 ParameterBinding Information: 0 :     BIND cmd line arg [v7.2.0-preview.5] to position [1]
    DEBUG: 2021-04-20 06:52:38.3475 ParameterBinding Information: 0 :     BIND cmd line arg [..HEAD] to position [2]
    DEBUG: 2021-04-20 06:52:38.3475 ParameterBinding Information: 0 :     BIND cmd line arg [--oneline] to position [3]
    DEBUG: 2021-04-20 06:52:38.4365 ParameterBinding Information: 0 : CALLING BeginProcessing

    Replacing the variable with a literal shows what is expected:

    PS> trace-command -Option ExecutionFlow -Name ParameterBinding -Expression { git log v7.2.0-preview.5..HEAD --oneline } -PSHost
    DEBUG: 2021-04-20 06:53:39.0736 ParameterBinding Information: 0 : BIND NAMED native application line args [/usr/bin/git]
    DEBUG: 2021-04-20 06:53:39.0754 ParameterBinding Information: 0 :     BIND cmd line arg [log] to position [0]
    DEBUG: 2021-04-20 06:53:39.0755 ParameterBinding Information: 0 :     BIND cmd line arg [v7.2.0-preview.5..HEAD] to position [1]
    DEBUG: 2021-04-20 06:53:39.0762 ParameterBinding Information: 0 :     BIND cmd line arg [--oneline] to position [2]
    DEBUG: 2021-04-20 06:53:39.1816 ParameterBinding Information: 0 : CALLING BeginProcessing
  6. SeeminglyScience commented on Apr 20, 2021

    @SeeminglyScience
    Contributor

    Steve Lee (@SteveL-MSFT) The issue has existed since version 3 (as noted by Michael Klement (@mklement0) above) and happens with any command (e.g. $i = '10'; echo $i..HEAD).

    Mathias R. Jessen (@IISResetMe) mentioned on twitter that it seems to occur at the tokenizer. In argument mode the tokenizer doesn't correctly revert back to a single expandable string when it hits the second period and instead creates a variable token and a literal string token.

  7. mklement0 commented on Apr 20, 2021

    @mklement0
    Contributor

    Thanks for the clarification, Patrick Meinecke (@SeeminglyScience); indeed, the problem also happens in regular parameter binding, not just when calling native executables.

    Given that a native executable happened to be the messenger, if you will, in this case, perhaps Steve Lee (@SteveL-MSFT) merely meant to showcase the new-in-preview.5 ability to also trace parameter binding when calling native executables, which is indeed good to know (though incidental here).

  8. SeeminglyScience commented on Apr 20, 2021

    @SeeminglyScience
    Contributor

    Given that a native executable happened to be the messenger, if you will, in this case, perhaps Steve Lee (@SteveL-MSFT) merely meant to showcase the new-in-preview.5 ability to also trace parameter binding when calling native executables, which is indeed good to know (though incidental here).

    Ahh good point! Didn't know that was new, I definitely misread that.

  9. added
    Issue-Enhancement
    and removed
    Needs-Triage
    on May 11, 2021
  10. added
    In-PR
    on Sep 7, 2023
  11. added
    Resolution-No Activity
    on Oct 13, 2024
  12. microsoft-github-policy-service commented on Oct 13, 2024

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if there is no further activity in 7 days, the issue will be closed automatically.

    Activity in this case refers only to comments on the issue. If the issue is closed and you are the author, you can re-open the issue using the button below. Please add more information to be considered during retriage. If you are not the author but the issue is impacting you after it has been closed, please submit a new issue with updated details and a link to this issue and the original.

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

Metadata

Metadata

Labels

In-PRIssue-EnhancementResolution-No ActivityWG-Engine

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions