git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Redirect "git" subcommand to itself?
@ 2015-05-28  0:28 Stefan Beller
  2015-05-28  1:53 ` Junio C Hamano
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Stefan Beller @ 2015-05-28  0:28 UTC (permalink / raw)
  To: git@vger.kernel.org

Hi,

so I just run into this problem again (which happens to me maybe twice a week):
I want to do a git operations, so I type "git " into my shell, and
then I look around what
exactly I want to do and usually I find it in the help text of a
previous command such as
    You are currently reverting commit 383c14b.
      (fix conflicts and run "git revert --continue")
      (use "git revert --abort" to cancel the revert operation)

then I copy the whole operation "git revert --abort" in this case and
paste it to the shell
and let go.
The result looks like
    $ git git revert --abort
    git: 'git' is not a git command. See 'git --help'.

    Did you mean this?
    init

I wonder if we want to make a "git" subcommand, which behaves exactly
the same as git itself?
Then "git git git status" would just return the same as "git status".

Thanks,
Stefan

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

* Re: Redirect "git" subcommand to itself?
  2015-05-28  0:28 Redirect "git" subcommand to itself? Stefan Beller
@ 2015-05-28  1:53 ` Junio C Hamano
  2015-05-28  5:22   ` Jeff King
  2015-05-29  8:38   ` Christian Neukirchen
  2015-05-28 10:36 ` Konstantin Khomoutov
  2015-05-28 13:11 ` Matthieu Moy
  2 siblings, 2 replies; 11+ messages in thread
From: Junio C Hamano @ 2015-05-28  1:53 UTC (permalink / raw)
  To: Stefan Beller; +Cc: git@vger.kernel.org

Stefan Beller <sbeller@google.com> writes:

> so I just run into this problem again (which happens to me maybe twice a week):
> I want to do a git operations, so I type "git " into my shell, and
> then I look around what
> exactly I want to do and usually I find it in the help text of a
> previous command such as
>     You are currently reverting commit 383c14b.
>       (fix conflicts and run "git revert --continue")
>       (use "git revert --abort" to cancel the revert operation)
>
> then I copy the whole operation "git revert --abort" in this case and
> paste it to the shell
> and let go.
> The result looks like
>     $ git git revert --abort
>     git: 'git' is not a git command. See 'git --help'.
>
>     Did you mean this?
>     init
>
> I wonder if we want to make a "git" subcommand, which behaves exactly
> the same as git itself?
> Then "git git git status" would just return the same as "git status".

A few unrelated thoughts.

 * Perhaps we should omit 'git' from these advice-texts?  E.g.

     use "revert --abort" to cancel

   I dunno.

 * While we bend over backwards to a certain degree to be helpful, I
   somehow feel making "git git" a synonym to "git" is going too
   far, akin to asking POSIX maintainers to define "act", "cta",
   "atc", "tca", and "tac" all as synonyms to "cat" because you
   often fat-finger when typing "cat" (yes, "tac" does something
   else that is more useful, I know).

 * You can help yourself with something like this, I suppose:

   [alias]
	git = "!sh -c 'exec git \"$@\"' -"

   but I personally feel that it is too ugly to live as part of our
   official suggestion, so please do not send a patch to add it as
   a built-in alias ;-).

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

* Re: Redirect "git" subcommand to itself?
  2015-05-28  1:53 ` Junio C Hamano
@ 2015-05-28  5:22   ` Jeff King
  2015-05-29  8:38   ` Christian Neukirchen
  1 sibling, 0 replies; 11+ messages in thread
From: Jeff King @ 2015-05-28  5:22 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Stefan Beller, git@vger.kernel.org

On Wed, May 27, 2015 at 06:53:26PM -0700, Junio C Hamano wrote:

> > I wonder if we want to make a "git" subcommand, which behaves exactly
> > the same as git itself?
> > Then "git git git status" would just return the same as "git status".
> 
> A few unrelated thoughts.
> 
>  * Perhaps we should omit 'git' from these advice-texts?  E.g.
> 
>      use "revert --abort" to cancel
> 
>    I dunno.

Please don't. You help the set of people who type "git" and then paste
the rest of the command at the expense of people who just  paste the
whole command. We don't know the relative numbers of those people, but
we know there is at least 1 in each group. ;)

-Peff

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

* Re: Redirect "git" subcommand to itself?
  2015-05-28  0:28 Redirect "git" subcommand to itself? Stefan Beller
  2015-05-28  1:53 ` Junio C Hamano
@ 2015-05-28 10:36 ` Konstantin Khomoutov
  2015-05-28 13:11 ` Matthieu Moy
  2 siblings, 0 replies; 11+ messages in thread
From: Konstantin Khomoutov @ 2015-05-28 10:36 UTC (permalink / raw)
  To: Stefan Beller; +Cc: git@vger.kernel.org

On Wed, 27 May 2015 17:28:34 -0700
Stefan Beller <sbeller@google.com> wrote:

> so I just run into this problem again (which happens to me maybe
> twice a week): I want to do a git operations, so I type "git " into
> my shell,
[...]
> then I copy the whole operation "git revert --abort" in this case and
> paste it to the shell and let go.
> The result looks like
>     $ git git revert --abort
>     git: 'git' is not a git command. See 'git --help'.
[...]
> I wonder if we want to make a "git" subcommand, which behaves exactly
> the same as git itself?
> Then "git git git status" would just return the same as "git status".

In your ~/.whateverrc, put this:

git() {
  while [ $# -gt 0 ]; do
    test "$1" != "git" && break;
    shift;
  done;
  command git $@;
}

This assumes a POSIX-compatible shell but I think you've got the idea.
("command" is a builtin which forces interpreting the following word as
the name of an external program.)

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

* Re: Redirect "git" subcommand to itself?
  2015-05-28  0:28 Redirect "git" subcommand to itself? Stefan Beller
  2015-05-28  1:53 ` Junio C Hamano
  2015-05-28 10:36 ` Konstantin Khomoutov
@ 2015-05-28 13:11 ` Matthieu Moy
  2 siblings, 0 replies; 11+ messages in thread
From: Matthieu Moy @ 2015-05-28 13:11 UTC (permalink / raw)
  To: Stefan Beller; +Cc: git@vger.kernel.org

Stefan Beller <sbeller@google.com> writes:

> so I just run into this problem again (which happens to me maybe twice
> a week):
> I want to do a git operations, so I type "git " into my shell, and
> then [...] I copy the whole operation "git revert --abort" in this case and
> paste it to the shell

On my side, that wouldn't be twice a week, but I often do the same
mistake. I find your idea for a solution conceptually ugly but
practically very convenient ;-), so I'd be in favor of doing it.

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/

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

* Re: Redirect "git" subcommand to itself?
  2015-05-28  1:53 ` Junio C Hamano
  2015-05-28  5:22   ` Jeff King
@ 2015-05-29  8:38   ` Christian Neukirchen
  2015-05-29 13:24     ` Aaron Schrab
  2015-05-29 15:38     ` Junio C Hamano
  1 sibling, 2 replies; 11+ messages in thread
From: Christian Neukirchen @ 2015-05-29  8:38 UTC (permalink / raw)
  To: git

Junio C Hamano <gitster@pobox.com> writes:

>  * You can help yourself with something like this, I suppose:
>
>    [alias]
> 	git = "!sh -c 'exec git \"$@\"' -"
>
>    but I personally feel that it is too ugly to live as part of our
>    official suggestion, so please do not send a patch to add it as
>    a built-in alias ;-).

So I thought I was clever, but this didn't work:

% ln -s /usr/bin/git ~/bin/git-git  
% git git
fatal: cannot handle git as a builtin

-- 
Christian Neukirchen  <chneukirchen@gmail.com>  http://chneukirchen.org

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

* Re: Redirect "git" subcommand to itself?
  2015-05-29  8:38   ` Christian Neukirchen
@ 2015-05-29 13:24     ` Aaron Schrab
  2015-05-29 15:38     ` Junio C Hamano
  1 sibling, 0 replies; 11+ messages in thread
From: Aaron Schrab @ 2015-05-29 13:24 UTC (permalink / raw)
  To: Christian Neukirchen; +Cc: git, Stefan Beller

At 10:38 +0200 29 May 2015, Christian Neukirchen <chneukirchen@gmail.com> wrote:
>Junio C Hamano <gitster@pobox.com> writes:
>
>>  * You can help yourself with something like this, I suppose:
>>
>>    [alias]
>> 	git = "!sh -c 'exec git \"$@\"' -"
>>
>>    but I personally feel that it is too ugly to live as part of our
>>    official suggestion, so please do not send a patch to add it as
>>    a built-in alias ;-).
>
>So I thought I was clever, but this didn't work:

I've done the same as the original poster a few times myself, so awhile 
ago I added the following to my .gitconfig file:

[alias]
    git         = "!f() { git $@; }; f"

And this has worked for me.

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

* Re: Redirect "git" subcommand to itself?
  2015-05-29  8:38   ` Christian Neukirchen
  2015-05-29 13:24     ` Aaron Schrab
@ 2015-05-29 15:38     ` Junio C Hamano
  2015-05-29 16:00       ` Stefan Beller
  2015-05-29 16:41       ` Christian Neukirchen
  1 sibling, 2 replies; 11+ messages in thread
From: Junio C Hamano @ 2015-05-29 15:38 UTC (permalink / raw)
  To: Christian Neukirchen; +Cc: git

Christian Neukirchen <chneukirchen@gmail.com> writes:

> Junio C Hamano <gitster@pobox.com> writes:
>
>>  * You can help yourself with something like this, I suppose:
>>
>>    [alias]
>> 	git = "!sh -c 'exec git \"$@\"' -"
>>
>>    but I personally feel that it is too ugly to live as part of our
>>    official suggestion, so please do not send a patch to add it as
>>    a built-in alias ;-).
>
> So I thought I was clever, but this didn't work:
>
> % ln -s /usr/bin/git ~/bin/git-git  
> % git git
> fatal: cannot handle git as a builtin

Why did you have to do that when I already gave an alias that works?

Or didn't the alias work?

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

* Re: Redirect "git" subcommand to itself?
  2015-05-29 15:38     ` Junio C Hamano
@ 2015-05-29 16:00       ` Stefan Beller
  2015-05-29 16:41       ` Christian Neukirchen
  1 sibling, 0 replies; 11+ messages in thread
From: Stefan Beller @ 2015-05-29 16:00 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Christian Neukirchen, git@vger.kernel.org

Thanks a lot for the discussion!
So I'll just fix it locally for me and we keep the state as is.

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

* Re: Redirect "git" subcommand to itself?
  2015-05-29 15:38     ` Junio C Hamano
  2015-05-29 16:00       ` Stefan Beller
@ 2015-05-29 16:41       ` Christian Neukirchen
  2015-05-29 16:49         ` Junio C Hamano
  1 sibling, 1 reply; 11+ messages in thread
From: Christian Neukirchen @ 2015-05-29 16:41 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

Junio C Hamano <gitster@pobox.com> writes:

> Christian Neukirchen <chneukirchen@gmail.com> writes:
>
>> Junio C Hamano <gitster@pobox.com> writes:
>>
>>>  * You can help yourself with something like this, I suppose:
>>>
>>>    [alias]
>>> 	git = "!sh -c 'exec git \"$@\"' -"
>>>
>>>    but I personally feel that it is too ugly to live as part of our
>>>    official suggestion, so please do not send a patch to add it as
>>>    a built-in alias ;-).
>>
>> So I thought I was clever, but this didn't work:
>>
>> % ln -s /usr/bin/git ~/bin/git-git  
>> % git git
>> fatal: cannot handle git as a builtin
>
> Why did you have to do that when I already gave an alias that works?

I was just toying around, and it would have been cute.

> Or didn't the alias work?

It does.  This seems to work just as well, and is easier:

	git = !git

Thanks,
-- 
Christian Neukirchen  <chneukirchen@gmail.com>  http://chneukirchen.org

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

* Re: Redirect "git" subcommand to itself?
  2015-05-29 16:41       ` Christian Neukirchen
@ 2015-05-29 16:49         ` Junio C Hamano
  0 siblings, 0 replies; 11+ messages in thread
From: Junio C Hamano @ 2015-05-29 16:49 UTC (permalink / raw)
  To: Christian Neukirchen; +Cc: git

Christian Neukirchen <chneukirchen@gmail.com> writes:

> I was just toying around, and it would have been cute.
>
>> Or didn't the alias work?
>
> It does.  This seems to work just as well, and is easier:

Thanks; I was wondering if I gave something that was not portable or
something.

> 	git = !git

I'd call that the ultimate cuteness.

We have a winner ;-) ;-) ;-).

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

end of thread, other threads:[~2015-05-29 16:49 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-05-28  0:28 Redirect "git" subcommand to itself? Stefan Beller
2015-05-28  1:53 ` Junio C Hamano
2015-05-28  5:22   ` Jeff King
2015-05-29  8:38   ` Christian Neukirchen
2015-05-29 13:24     ` Aaron Schrab
2015-05-29 15:38     ` Junio C Hamano
2015-05-29 16:00       ` Stefan Beller
2015-05-29 16:41       ` Christian Neukirchen
2015-05-29 16:49         ` Junio C Hamano
2015-05-28 10:36 ` Konstantin Khomoutov
2015-05-28 13:11 ` Matthieu Moy

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 NNTP newsgroup(s).