# allowing aliases to override builtins to support default options

7 messages from 2009-03-06 to 2009-03-07. Participants: Jay Soffian, Sverre Rabbelier, Junio C Hamano, Johannes Schindelin.
Thread: https://gitlist.dev/t/18183

## Jay Soffian, 2009-03-06 22:30

Subject: allowing aliases to override builtins to support default options
Message-ID: <76718490903061430s2fbea2dfibe06282fd22b1588@mail.gmail.com>
URL: https://gitlist.dev/e/76718490903061430s2fbea2dfibe06282fd22b1588%40mail.gmail.com

```
Currently git does not allow aliases to override builtins. I
understand the reasoning behind this, but I wonder if it's overly
conservative.

Most shells support overriding commands with aliases, and I'm not sure
why git needs to be more conservative than the shell. (Although, I
will say, I hate when vendors alias rm to "rm -i", etc...)

It seems like this would be an elegant way to support default options.
Were it to be supported, it should probably have an escape hatch, such
as git --no-alias COMMAND, and it should probably only apply to
porcelains.

Thoughts?

j.

```

## Sverre Rabbelier, 2009-03-06 22:37

Subject: Re: allowing aliases to override builtins to support default options
Message-ID: <fabb9a1e0903061437t2df5620bn58c6c087214f994b@mail.gmail.com>
URL: https://gitlist.dev/e/fabb9a1e0903061437t2df5620bn58c6c087214f994b%40mail.gmail.com
In-Reply-To: <76718490903061430s2fbea2dfibe06282fd22b1588@mail.gmail.com>

```
Heya,

On Fri, Mar 6, 2009 at 23:30, Jay Soffian <jaysoffian@gmail.com> wrote:
> Most shells support overriding commands with aliases, and I'm not sure
> why git needs to be more conservative than the shell. (Although, I
> will say, I hate when vendors alias rm to "rm -i", etc...)

Hmmm, maybe we could require marking such an alias somehow, to signify
that you're aware that you're overriding a builtin? Also, what would
we do the alias 'foo' calling 'git foo'? Does it call the original
command, or itself?

-- 
Cheers,

Sverre Rabbelier

```

## Junio C Hamano, 2009-03-06 23:22

Subject: Re: allowing aliases to override builtins to support default options
Message-ID: <7vhc26qls3.fsf@gitster.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vhc26qls3.fsf%40gitster.siamese.dyndns.org
In-Reply-To: <76718490903061430s2fbea2dfibe06282fd22b1588@mail.gmail.com>

```
Jay Soffian <jaysoffian@gmail.com> writes:

> Currently git does not allow aliases to override builtins. I
> understand the reasoning behind this, but I wonder if it's overly
> conservative.

It is not.

> Most shells support overriding commands with aliases, and I'm not sure
> why git needs to be more conservative than the shell.

Because sane shells do not expand aliases when used in a script, and gives
a handy way to defeat the alias even from the command line.

    $ alias ls='ls -aF'
    $ echo ls >script
    $ chmod +x script

and compare:

    $ ./script
    $ ls
    $ /bin/ls

```

## Jay Soffian, 2009-03-06 23:51

Subject: Re: allowing aliases to override builtins to support default options
Message-ID: <76718490903061551m24a95ed8r2e334ff0e6f0fcf3@mail.gmail.com>
URL: https://gitlist.dev/e/76718490903061551m24a95ed8r2e334ff0e6f0fcf3%40mail.gmail.com
In-Reply-To: <7vhc26qls3.fsf@gitster.siamese.dyndns.org>

```
On Fri, Mar 6, 2009 at 6:22 PM, Junio C Hamano <gitster@pobox.com> wrote:
> Because sane shells do not expand aliases when used in a script, and gives
> a handy way to defeat the alias even from the command line.
>
>    $ alias ls='ls -aF'
>    $ echo ls >script
>    $ chmod +x script
>
> and compare:
>
>    $ ./script
>    $ ls
>    $ /bin/ls

Understood. And if git could do the same, still no?

j.

```

## Johannes Schindelin, 2009-03-07 02:37

Subject: Re: allowing aliases to override builtins to support default options
Message-ID: <alpine.DEB.1.00.0903070336200.10279@pacific.mpi-cbg.de>
URL: https://gitlist.dev/e/alpine.DEB.1.00.0903070336200.10279%40pacific.mpi-cbg.de
In-Reply-To: <76718490903061430s2fbea2dfibe06282fd22b1588@mail.gmail.com>

```
Hi,

On Fri, 6 Mar 2009, Jay Soffian wrote:

> Currently git does not allow aliases to override builtins. I understand 
> the reasoning behind this, but I wonder if it's overly conservative.
> 
> Most shells support overriding commands with aliases, and I'm not sure 
> why git needs to be more conservative than the shell. (Although, I will 
> say, I hate when vendors alias rm to "rm -i", etc...)
> 
> It seems like this would be an elegant way to support default options.

What you dream about breaks a lot of scripts.

So while it might be nice for you, you would make life of others much, 
much, much harder.  Not nice at all.

Ciao,
Dscho

```

## Jay Soffian, 2009-03-07 02:57

Subject: Re: allowing aliases to override builtins to support default options
Message-ID: <76718490903061857y5446098by3633559697508c2e@mail.gmail.com>
URL: https://gitlist.dev/e/76718490903061857y5446098by3633559697508c2e%40mail.gmail.com
In-Reply-To: <alpine.DEB.1.00.0903070336200.10279@pacific.mpi-cbg.de>

```
On Fri, Mar 6, 2009 at 9:37 PM, Johannes Schindelin
<Johannes.Schindelin@gmx.de> wrote:
> What you dream about breaks a lot of scripts.

I said I understood the implications.

> So while it might be nice for you, you would make life of others much,
> much, much harder.  Not nice at all.

This is not something I am dreaming about, and I'm only interested to
the extent that it improves git w/o hindering existing users. I'm
certainly not aiming to be not nice to anyone!

For example, what if:

1. The aliases applied only to porcelain commands, not to plumbing.
2. The aliases worked only if stdout was a terminal, using the same
method that git uses for detecting when it is okay to start a pager.
3. git took --alias-builtins and --no-alias-builtins just like it
takes --paginate and --no-pager to override (2).

j.

```

## Johannes Schindelin, 2009-03-07 03:10

Subject: Re: allowing aliases to override builtins to support default options
Message-ID: <alpine.DEB.1.00.0903070407480.10279@pacific.mpi-cbg.de>
URL: https://gitlist.dev/e/alpine.DEB.1.00.0903070407480.10279%40pacific.mpi-cbg.de
In-Reply-To: <76718490903061857y5446098by3633559697508c2e@mail.gmail.com>

```
Hi,

On Fri, 6 Mar 2009, Jay Soffian wrote:

> For example, what if:
> 
> 1. The aliases applied only to porcelain commands, not to plumbing.

Inconsistency like this is bad for a couple of reasons.  Just 3 out of 
them:

- it makes it hard for users to understand,

- it is prone for subtle breakages,

- the code will be complicated, and therefore ugly.

> 2. The aliases worked only if stdout was a terminal, using the same 
>    method that git uses for detecting when it is okay to start a pager.

This would be even more complicated to understand for the regular Git user 
who just wants to use the darned thing and not care about its internals.

> 3. git took --alias-builtins and --no-alias-builtins just like it takes 
>    --paginate and --no-pager to override (2).

And this makes it even more complicated.

I'd rather stay with our current notion that aliases cannot override Git 
programs.  This is _very_ easy to explain, and also _very_ easy to defend.

Ciao,
Dscho

```
