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

Re: git alias for options

From
Jeff King <peff@peff.net>
Date
Feb 17, 2017, 20:42 UTC
Message-ID
<20170217204227.kreormjoo5lr6zu4@sigill.intra.peff.net>
In-Reply-To
<CACBZZX4Zmwb8ZHGBXCpm6=yH_uxc-K1X1vv1jQ+wwnUPneqM4A@mail.gmail.com>
On Fri, Feb 17, 2017 at 02:50:23PM +0100, Ævar Arnfjörð Bjarmason wrote:
Show 23 quoted lines
> On Fri, Feb 17, 2017 at 9:23 AM, hIpPy <hippy2981@gmail.com> wrote:
> > Git has aliases for git commands. Is there a (an inbuilt) way to alias
> > options? If not, what is the reason?
> 
> This has long been on my  wishlist, because there's a lot of
> copy/pasted logic all over Git to make git foo --whatever aliased to
> foo.whatever in the config, but only for some options.
> 
> It should ideally be part of something every option just supports, via
> the getopts struct.
> 
> However, it can't allow you to modify whatever option you want,
> because some things like git-commit-tree should not be customized
> based on config, it would break things that rely on the plumbing
> commands.
> 
> So it would have to be a whitelist for each option we allow to be
> configured like this via the getopts struct.
> 
> Also there are surely other edge cases, like maybe the config option
> now doesn't 1=1 map to the name for the option in some cases, or the
> flag should be config-able but is has no long form (which we'd like
> for the config), then we'd want to add that etc.

I think your idea is roughly equivalent in functionality to just allowing aliases to override command names. E.g., anything you could do with:

  [log]
  follow = true
  decorate = false
could be done with:
  [alias]
  log = "log --follow --no-decorate"

The reason we have historically not allowed that is for the "commit-tree" plumbing reason you gave above. One option would be to relax it for a whitelist of porcelain commands. Then your whitelist at least only has to cover commands, and not each individual option.

I think there are a lot of corner cases in that whitelist, though. A lot of commands serve dual porcelain/plumbing purposes. E.g., "log" and "tag" are commonly used by both humans and by scripts.

A first step in that direction would probably be an environment variable to tell Git to suppress command-aliases. Scripts would set that to ensure a more vanilla experience. It doesn't fix _existing_ scripts, but if that option were introduced, then over time scripts would start to use it. Then eventually it would be safe(r) to introduce something like command aliases.

But nobody has ever taken that first step, so here we are.
-Peff
Previous: Ævar Arnfjörð BjarmasonNext: Ævar Arnfjörð Bjarmason
Message 4 of 9 in “git alias for options”
  1. hIpPyFeb 17, 2017
  2. Michael J GruberFeb 17, 2017
  3. Ævar Arnfjörð BjarmasonFeb 17, 2017
  4. Jeff KingFeb 17, 2017
  5. Ævar Arnfjörð BjarmasonFeb 17, 2017
  6. Jeff KingFeb 17, 2017
  7. Junio C HamanoFeb 17, 2017
  8. hIpPyFeb 17, 2017
  9. Jeff KingFeb 18, 2017

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.