From: Jakub Narebski <jnareb@gmail.com>
To: "Kana Natsuno" <kana@whileimautomaton.net>
Cc: git@vger.kernel.org
Subject: Re: Two problems on alias of git
Date: Tue, 05 May 2009 07:03:49 -0700 (PDT) [thread overview]
Message-ID: <m3bpq7oddw.fsf@localhost.localdomain> (raw)
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.
[...]
> 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
next prev parent reply other threads:[~2009-05-05 14:04 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-05-05 12:42 Two problems on alias of git Kana Natsuno
2009-05-05 14:03 ` Jakub Narebski [this message]
2009-05-05 15:11 ` Kana Natsuno
2009-05-05 15:42 ` Jakub Narebski
2009-05-05 16:25 ` Kana Natsuno
2009-05-05 17:01 ` Jakub Narebski
2009-05-08 9:06 ` Jeff King
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m3bpq7oddw.fsf@localhost.localdomain \
--to=jnareb@gmail.com \
--cc=git@vger.kernel.org \
--cc=kana@whileimautomaton.net \
/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.
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 NNTP newsgroup(s).