Re: Allow git alias to override existing Git commands
- From
Sitaram Chamarty <sitaramc@gmail.com>
- Date
- Nov 11, 2015, 04:48 UTC
- Message-ID
- <5642C8BA.8030003@gmail.com>
- In-Reply-To
- <56424DDE.2030808@game-point.net>
On 11/11/15 01:34, Jeremy Morton wrote:
Show 17 quoted lines
> On 10/11/2015 18:12, Stefan Beller wrote: >> On Tue, Nov 10, 2015 at 8:31 AM, Jeremy Morton<admin@game-point.net> wrote: >>> It's recently come to my attention that the "git alias" config functionality >>> ignores all aliases that would override existing Git commands. This seems >>> like a bad idea to me. >> >> This ensures that the plumbing commands always work as expected. >> As scripts *should* only use plumbing commands, the scripts should >> work with high probability despite all the crazy user configuration/aliases. >> > > I just disagree with this. If a user chooses to override their Git > commands, it's their problem. Why should Git care about this? It > should provide the user with the option to do this, and if the user > ruins scripts because of their aliases, it is not Git's problem. What > you are doing is taking away power from users to use git aliases to > their full potential.
A lot of things in Unix do follow that "give you rope to hang yourself" philosophy. I used to (and to *some* extent still do) think like that, but some years of supporting normal users trying to do stuff has taught me it's not always that simple.
I can easily see someone blogging some cool way to do something, and a less savvy user uses that in his gitconfig, and gets burned later (possibly much later, enough that he does not easily make the connection!)
So for the record, I am definitely against this kind of change.
But if I were in your place, and really *needed* this, here's what I would do:
#!/bin/bash
# this file is named 'git' and placed in a directory that is earlier in $PATH
# than the real 'git' binary (typically $HOME/bin). This allows you to
# override git sub-commands by adding stuff like this to your ~/.gitconfig
# (notice the "o-" prefix):
#
# [alias]
# o-clone = clone --recursiveGIT=/bin/git # the real 'git' binary
cmd="$1"
shift if $GIT config --get alias.o-$cmd >/dev/null
then
$GIT o-$cmd "$@"
else
$GIT $cmd "$@"
fi