Re: Two problems on alias of git

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



"Kana Natsuno" <kana@xxxxxxxxxxxxxxxxxxxx> 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
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]