git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Two problems on alias of git

From
Jakub Narebski <jnareb@gmail.com>
Date
May 5, 2009, 14:03 UTC
Message-ID
<m3bpq7oddw.fsf@localhost.localdomain>
In-Reply-To
<op.utgiv92f6f2obg@i220-99-253-139.s27.a098.ap.plala.or.jp>
"Kana Natsuno" <kana@whileimautomaton.net> writes:
> Hello.  I found 2 problems on alias of git.
[...]
Show 34 quoted lines
> The second one is that git doesn't expand a kind of aliases
> properly, especially with double quotation marks (").  I used the
> following alias recently to list the last 10 commits on HEAD:
> 
> [alias]
>         lr = !git l1 | head | tac
> 
> Then I want to extend this alias to list the last N commits on
> a branch with "git lr 20", "git lr master", "git lr master 20",
> etc.  So that I wrote the following definition (note that the
> actual definition is written in a single line, though the quoted
> definition is folded in multiple lines for readability):
> 
> [alias]
>         lr = !$SHELL -c '
>                 n=10;
>                 1="${1:-$n}";
>                 if ! [ "${1##[0-9]*}" = "" ]; then
>                   t="$1";
>                   1="${2:-$n}";
>                   2="$t";
>                 fi;
>                 git --no-pager l1 --reverse -"$1" "${2:-HEAD}"
>               ' __dummy__
> 
> But it doesn't work because git expands as follows:
> 
> $ git config --get alias.lr
> !$SHELL -c '1=${1:-10}
> 
> Double quotation marks (") are removed and the aliased string is
> cut at a random position.  I expect that the aliased string is
> passed to system() as-is, but git doesn't so.  Why does git behave
> so?  Is it a bug or an intentional behavior?

I don't know if it is a bug or a feature, but git-config supports quoted strings (required if you want to have value which has trailing or leading whitespace, or which contains '#' which is beginning of comment character). Inside quoted string you need to escape '"':

   [string]
        quotes = "quoted \" string ' with # character"

expands as intended. Perhaps stripping of double quotes inside string are artifact of that feature. Try escaping or double escaping quotes: \" or \\\".

-- 
Jakub Narebski
Poland
ShadeHawk on #git
Previous: Kana NatsunoNext: Kana Natsuno
Message 2 of 7 in “Two problems on alias of git”
  1. Kana NatsunoMay 5, 2009
  2. Jakub NarebskiMay 5, 2009
  3. Kana NatsunoMay 5, 2009
  4. Jakub NarebskiMay 5, 2009
  5. Kana NatsunoMay 5, 2009
  6. Jakub NarebskiMay 5, 2009
  7. Jeff KingMay 8, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.