git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Johannes Sixt <j6t@kdbg.org>
To: Robert Dailey <rcdailey.lists@gmail.com>
Cc: Git <git@vger.kernel.org>
Subject: Re: Need help debugging issue in git
Date: Mon, 2 Apr 2018 08:53:35 +0200	[thread overview]
Message-ID: <3152c739-5c80-99b3-ac16-31fe348b7657@kdbg.org> (raw)
In-Reply-To: <CAHd499C39sBTJy_AoCJxE2ZS4ECJju2jroY6_0E1MssCBtmC=A@mail.gmail.com>

Am 02.04.2018 um 02:36 schrieb Robert Dailey:
> I'm struggling with a bug that I found introduced in git v2.13.2. The
> bug was not reproducible in v2.13.1. The issue is that using arguments
> like "@{-1}" to aliases causes those curly braces to be removed, so
> once the command is executed after alias processing the argument looks
> like "@-1". This breaks any aliases you have that wrap `git log` and
> such. I originally opened the bug on the Git for Windows project
> (since I use Git mostly on Windows):
> 
> https://github.com/git-for-windows/git/issues/1220
...
> Here is the alias being used for a test:
> 
> [alias]
>      lgtest = !git log --oneline \"$@\"
> 
> And here is the command I invoke for the test:
> 
> $ git lgtest @{-1}
> 
> I should get logs for the previously-checked-out branch.
> 
> When `prepare_shell_cmd()` is called in run-command.c, it gets expanded like so:
> 
> + [0] "sh" const char *
> + [1] "-c" const char *
> + [2] "git log --oneline \"$@\" \"$@\"" const char *
> + [3] "git log --oneline \"$@\"" const char *
> + [4] "@{-1}" const char *
> 
> With my modifications (again, patch inline below) I get this:
> 
> + [0] "sh" const char *
> + [1] "-c" const char *
> + [2] "git log --oneline \"$@\"" const char *
> + [3] "@{-1}" const char *
> 
> The second version looks much better.

But this is wrong. Try this on the command line:

   sh -c 'echo "$@"' a b c

Notice how this prints only 'b c', not 'a b c'. The reason is that the 
argument 'a' is treated like a "script" name, i.e. what you get for 
"$0", and 'b' and 'c' as the actual arguments to the "script".

That is, you must fill in some dummy "script" name at slot [3], and 
run_command chooses to put the alias text there.

> I think the constant nesting of
> commands inside each other that the first version does is somehow
> causing curly braces to be removed. I don't understand enough about
> shell processing to know why it would do this.

Some shells expand the curly braces. They must get lost somewhere by one 
of the two shell invocations that happen on the way.

BTW, you don't happen to have a file named '@-1' in your directory, most 
likely by accident?

-- Hannes

  reply	other threads:[~2018-04-02  6:53 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-02  0:36 Need help debugging issue in git Robert Dailey
2018-04-02  6:53 ` Johannes Sixt [this message]
2018-04-14 16:39   ` Robert Dailey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3152c739-5c80-99b3-ac16-31fe348b7657@kdbg.org \
    --to=j6t@kdbg.org \
    --cc=git@vger.kernel.org \
    --cc=rcdailey.lists@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).