git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* git alias for options
@ 2017-02-17  8:23 hIpPy
  2017-02-17 13:15 ` Michael J Gruber
  2017-02-17 13:50 ` Ævar Arnfjörð Bjarmason
  0 siblings, 2 replies; 9+ messages in thread
From: hIpPy @ 2017-02-17  8:23 UTC (permalink / raw)
  To: git

Git has aliases for git commands. Is there a (an inbuilt) way to alias
options? If not, what is the reason?

Thanks,
hippy

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: git alias for options
  2017-02-17  8:23 git alias for options hIpPy
@ 2017-02-17 13:15 ` Michael J Gruber
  2017-02-17 13:50 ` Ævar Arnfjörð Bjarmason
  1 sibling, 0 replies; 9+ messages in thread
From: Michael J Gruber @ 2017-02-17 13:15 UTC (permalink / raw)
  To: hIpPy, git

hIpPy venit, vidit, dixit 17.02.2017 09:23:
> Git has aliases for git commands. Is there a (an inbuilt) way to alias
> options? If not, what is the reason?
> 
> Thanks,
> hippy
> 

You can setup an alias for "command with options", for example:

git help s
`git s' is aliased to `status -s -b -uno .'

As you see here, this can include non-option arguments such as the
pathsepc '.'.

You cannot alias options independent of the command, though.

Michael

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: git alias for options
  2017-02-17  8:23 git alias for options hIpPy
  2017-02-17 13:15 ` Michael J Gruber
@ 2017-02-17 13:50 ` Ævar Arnfjörð Bjarmason
  2017-02-17 20:42   ` Jeff King
  1 sibling, 1 reply; 9+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2017-02-17 13:50 UTC (permalink / raw)
  To: hIpPy; +Cc: Git Mailing List

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.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: git alias for options
  2017-02-17 13:50 ` Ævar Arnfjörð Bjarmason
@ 2017-02-17 20:42   ` Jeff King
  2017-02-17 22:10     ` Ævar Arnfjörð Bjarmason
  0 siblings, 1 reply; 9+ messages in thread
From: Jeff King @ 2017-02-17 20:42 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason; +Cc: hIpPy, Git Mailing List

On Fri, Feb 17, 2017 at 02:50:23PM +0100, Ævar Arnfjörð Bjarmason wrote:

> 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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: git alias for options
  2017-02-17 20:42   ` Jeff King
@ 2017-02-17 22:10     ` Ævar Arnfjörð Bjarmason
  2017-02-17 22:13       ` Jeff King
  0 siblings, 1 reply; 9+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2017-02-17 22:10 UTC (permalink / raw)
  To: Jeff King; +Cc: hIpPy, Git Mailing List

On Fri, Feb 17, 2017 at 9:42 PM, Jeff King <peff@peff.net> wrote:
> On Fri, Feb 17, 2017 at 02:50:23PM +0100, Ævar Arnfjörð Bjarmason wrote:
>
>> 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"

Indeed, exact same thing, different syntax. Mostly I like this
suggestion better, although the bad side of it is that it's not as
easy to introspect with a dump of git-config -l.

> 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.

The most gentle first step would be to try to turn the existing config
options where you can override cli-options into some declarative thing
from the current ad-hoc code we have for each one.

That would be no change in behavior, but would make it easier to
migrate more things in the future.

Anyway, words are cheap. Just replied because to the extent that hIpPy
wants to work on this I thought I'd sprinkle some historical caveats
from memory. Other than that no point in keeping talking about this
without patches.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: git alias for options
  2017-02-17 22:10     ` Ævar Arnfjörð Bjarmason
@ 2017-02-17 22:13       ` Jeff King
  2017-02-17 22:31         ` Junio C Hamano
  0 siblings, 1 reply; 9+ messages in thread
From: Jeff King @ 2017-02-17 22:13 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason; +Cc: hIpPy, Git Mailing List

On Fri, Feb 17, 2017 at 11:10:08PM +0100, Ævar Arnfjörð Bjarmason wrote:

> > 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.
> 
> The most gentle first step would be to try to turn the existing config
> options where you can override cli-options into some declarative thing
> from the current ad-hoc code we have for each one.
> 
> That would be no change in behavior, but would make it easier to
> migrate more things in the future.

Yeah, I'd agree with that. It does not change anything for the users,
but it makes the implementation less annoying.

-Peff

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: git alias for options
  2017-02-17 22:13       ` Jeff King
@ 2017-02-17 22:31         ` Junio C Hamano
  2017-02-17 22:34           ` hIpPy
  0 siblings, 1 reply; 9+ messages in thread
From: Junio C Hamano @ 2017-02-17 22:31 UTC (permalink / raw)
  To: Jeff King; +Cc: Ævar Arnfjörð Bjarmason, hIpPy, Git Mailing List

Jeff King <peff@peff.net> writes:

> On Fri, Feb 17, 2017 at 11:10:08PM +0100, Ævar Arnfjörð Bjarmason wrote:
>
>> The most gentle first step would be to try to turn the existing config
>> options where you can override cli-options into some declarative thing
>> from the current ad-hoc code we have for each one.
>> 
>> That would be no change in behavior, but would make it easier to
>> migrate more things in the future.
>
> Yeah, I'd agree with that. It does not change anything for the users,
> but it makes the implementation less annoying.

Yup, as long as that declarative thing (presumably it would hook
into parse-options that is already sort of declarative) allows some
command line options not overridable with configuration, I think it
would be OK.

I do not think anybody wants to see "reset --hard" and turn it into
"[reset] hard = yes" configuration, and we should not even allow for
that.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: git alias for options
  2017-02-17 22:31         ` Junio C Hamano
@ 2017-02-17 22:34           ` hIpPy
  2017-02-18  6:33             ` Jeff King
  0 siblings, 1 reply; 9+ messages in thread
From: hIpPy @ 2017-02-17 22:34 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: Jeff King, Ævar Arnfjörð Bjarmason,
	Git Mailing List

I think the conversation has drifted away from what I am asking / hoping for.

I apologize but I do not feel in the position of submitting patches
yet. I'll first need to read some code first before that.

I'm coming from the angle where currently I can alias just the command
(ex: l for log) not considering the 'command with options'.

[alias]
  l = log

Currently, the order is as follows:

If built-in git command then it wins.
If custom git command (script as git-l) then it wins.
If alias for git command then it wins.
Else throw as unknown command.

In short, built-in git command > custom git command > git alias.

So I think, the same could also be used for options.

Say I want an alias for option --name-status as -s, so I can type:
$ git log -s

But there is already a -s option and that wins so the built-in option
alias wins.

However, I think I should be able alias it as --ns.
$ git log --ns


Thanks,
hippy

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: git alias for options
  2017-02-17 22:34           ` hIpPy
@ 2017-02-18  6:33             ` Jeff King
  0 siblings, 0 replies; 9+ messages in thread
From: Jeff King @ 2017-02-18  6:33 UTC (permalink / raw)
  To: hIpPy
  Cc: Junio C Hamano, Ævar Arnfjörð Bjarmason,
	Git Mailing List

On Fri, Feb 17, 2017 at 02:34:15PM -0800, hIpPy wrote:

> I think the conversation has drifted away from what I am asking / hoping for.

Yeah, the usual answer to "can we have custom options" is "use a custom
alias". But I agree they are not quite the same thing.

> Say I want an alias for option --name-status as -s, so I can type:
> $ git log -s
> 
> But there is already a -s option and that wins so the built-in option
> alias wins.
> 
> However, I think I should be able alias it as --ns.
> $ git log --ns

To be honest, I am not that enthused about the idea, but I don't have an
real objection beyond "meh, that looks like an unnecessary
complication".

If anybody wants to pursue it, the simplest way would probably be to
teach parse-options to take a callback for an unknown option, which
could then do a config lookup to transmute the argument into another
option-name.

Though many of the options (notably the revision-walker and diff ones)
are not handled by parse-options. So that might present a challenge.

-Peff

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2017-02-18  6:33 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-17  8:23 git alias for options hIpPy
2017-02-17 13:15 ` Michael J Gruber
2017-02-17 13:50 ` Ævar Arnfjörð Bjarmason
2017-02-17 20:42   ` Jeff King
2017-02-17 22:10     ` Ævar Arnfjörð Bjarmason
2017-02-17 22:13       ` Jeff King
2017-02-17 22:31         ` Junio C Hamano
2017-02-17 22:34           ` hIpPy
2017-02-18  6:33             ` Jeff King

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).