git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* git-config: aliases with parameter expansion ($1 and such)
@ 2008-03-23 13:28 Dirk Süsserott
  2008-03-23 13:45 ` Jay Soffian
  0 siblings, 1 reply; 13+ messages in thread
From: Dirk Süsserott @ 2008-03-23 13:28 UTC (permalink / raw)
  To: Git Mailing List

Hi, I've a question concerning git config and the alias things.
I'd like to create an alias 'atag' that creates an annotated
tag with the message being the same as the tag. Usually I create
annotated tags like this:

$ git tag -a -m "mytag" mytag

(BTW: It's not documented, but I have the impression that
the '-a' switch is implicitely added when the '-m' switch
is present. Is that true?)

I'd like to have an alias like this:

[alias]
    atag = tag -a -m "$1"

So that I can simply call

$ git atag mytag

Is it possible to pass parameters to the alias definition?
With the definition above I got a tag with message "$1".

Thanks, Dirk

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

* Re: git-config: aliases with parameter expansion ($1 and such)
  2008-03-23 13:28 git-config: aliases with parameter expansion ($1 and such) Dirk Süsserott
@ 2008-03-23 13:45 ` Jay Soffian
  2008-03-23 14:04   ` Dirk Süsserott
  0 siblings, 1 reply; 13+ messages in thread
From: Jay Soffian @ 2008-03-23 13:45 UTC (permalink / raw)
  To: Dirk Süsserott; +Cc: Git Mailing List

On Sun, Mar 23, 2008 at 9:28 AM, Dirk Süsserott <newsletter@dirk.my1.cc> wrote:
> Hi, I've a question concerning git config and the alias things.
>  I'd like to create an alias 'atag' that creates an annotated
>  tag with the message being the same as the tag. Usually I create
>  annotated tags like this:
>
>  $ git tag -a -m "mytag" mytag
>
>  (BTW: It's not documented, but I have the impression that
>  the '-a' switch is implicitely added when the '-m' switch
>  is present. Is that true?)
>
>  I'd like to have an alias like this:
>
>  [alias]
>     atag = tag -a -m "$1"
>
>  So that I can simply call
>
>  $ git atag mytag
>
>  Is it possible to pass parameters to the alias definition?
>  With the definition above I got a tag with message "$1".

atag = !git tag -a -m "$1"

j.

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

* Re: git-config: aliases with parameter expansion ($1 and such)
  2008-03-23 13:45 ` Jay Soffian
@ 2008-03-23 14:04   ` Dirk Süsserott
  2008-03-23 14:19     ` Johannes Schindelin
  2008-03-23 19:38     ` Jeff King
  0 siblings, 2 replies; 13+ messages in thread
From: Dirk Süsserott @ 2008-03-23 14:04 UTC (permalink / raw)
  To: Git Mailing List

Jay Soffian schrieb:
> On Sun, Mar 23, 2008 at 9:28 AM, Dirk Süsserott <newsletter@dirk.my1.cc> wrote:
>   
>> Hi, I've a question concerning git config and the alias things.
>>  I'd like to create an alias 'atag' that creates an annotated
>>  tag with the message being the same as the tag. Usually I create
>>  annotated tags like this:
>>
>>  $ git tag -a -m "mytag" mytag
>>
>>  (BTW: It's not documented, but I have the impression that
>>  the '-a' switch is implicitely added when the '-m' switch
>>  is present. Is that true?)
>>
>>  I'd like to have an alias like this:
>>
>>  [alias]
>>     atag = tag -a -m "$1"
>>
>>  So that I can simply call
>>
>>  $ git atag mytag
>>
>>  Is it possible to pass parameters to the alias definition?
>>  With the definition above I got a tag with message "$1".
>>     
>
> atag = !git tag -a -m "$1"
>
> j.
>   
Thanks for the quick reply. Did you try that out? I did

$ git atag foo

with your definition and got a tag with message "$1" and
the tag's name was "'foo'" (surrounded by single quotes).

If you tried it and it worked (with linux), then it might
be a problem with my environment: I'm using Git with windows
and the bash (Git-1.5.4-preview20080202.exe). Usually that
works very good, but sometimes it doesn't. Probably this
is one of the few "it doesn't" things.

Dirk

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

* Re: git-config: aliases with parameter expansion ($1 and such)
  2008-03-23 14:04   ` Dirk Süsserott
@ 2008-03-23 14:19     ` Johannes Schindelin
  2008-03-23 14:31       ` Dirk Süsserott
  2008-03-23 19:38       ` Jeff King
  2008-03-23 19:38     ` Jeff King
  1 sibling, 2 replies; 13+ messages in thread
From: Johannes Schindelin @ 2008-03-23 14:19 UTC (permalink / raw)
  To: Dirk Süsserott; +Cc: Git Mailing List

[-- Attachment #1: Type: TEXT/PLAIN, Size: 1052 bytes --]

Hi,

On Sun, 23 Mar 2008, Dirk Süsserott wrote:

> Jay Soffian schrieb:
> > On Sun, Mar 23, 2008 at 9:28 AM, Dirk Süsserott <newsletter@dirk.my1.cc>
> > wrote:
> >   
> > > Hi, I've a question concerning git config and the alias things.
> > >  I'd like to create an alias 'atag' that creates an annotated
> > >  tag with the message being the same as the tag. Usually I create
> > >  annotated tags like this:
> > >
> > >  $ git tag -a -m "mytag" mytag
> > >
> > >  (BTW: It's not documented, but I have the impression that
> > >  the '-a' switch is implicitely added when the '-m' switch
> > >  is present. Is that true?)
> > >
> > >  I'd like to have an alias like this:
> > >
> > >  [alias]
> > >     atag = tag -a -m "$1"
> > >
> > >  So that I can simply call
> > >
> > >  $ git atag mytag
> > >
> > >  Is it possible to pass parameters to the alias definition?
> > >  With the definition above I got a tag with message "$1".
> > >     
> >
> > atag = !git tag -a -m "$1"

Why so complicated?

	atag = tag -a -m

should work already.

Hth,
Dscho

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

* Re: git-config: aliases with parameter expansion ($1 and such)
  2008-03-23 14:19     ` Johannes Schindelin
@ 2008-03-23 14:31       ` Dirk Süsserott
  2008-03-23 19:38       ` Jeff King
  1 sibling, 0 replies; 13+ messages in thread
From: Dirk Süsserott @ 2008-03-23 14:31 UTC (permalink / raw)
  To: Git Mailing List

Johannes Schindelin schrieb:
> Hi,
>
> On Sun, 23 Mar 2008, Dirk Süsserott wrote:
>
>   
>> Jay Soffian schrieb:
>>     
>>> On Sun, Mar 23, 2008 at 9:28 AM, Dirk Süsserott <newsletter@dirk.my1.cc>
>>> wrote:
>>>   
>>>       
>>>> Hi, I've a question concerning git config and the alias things.
>>>>  I'd like to create an alias 'atag' that creates an annotated
>>>>  tag with the message being the same as the tag. Usually I create
>>>>  annotated tags like this:
>>>>
>>>>  $ git tag -a -m "mytag" mytag
>>>>
>>>>  (BTW: It's not documented, but I have the impression that
>>>>  the '-a' switch is implicitely added when the '-m' switch
>>>>  is present. Is that true?)
>>>>
>>>>  I'd like to have an alias like this:
>>>>
>>>>  [alias]
>>>>     atag = tag -a -m "$1"
>>>>
>>>>  So that I can simply call
>>>>
>>>>  $ git atag mytag
>>>>
>>>>  Is it possible to pass parameters to the alias definition?
>>>>  With the definition above I got a tag with message "$1".
>>>>     
>>>>         
>>> atag = !git tag -a -m "$1"
>>>       
>
> Why so complicated?
>
> 	atag = tag -a -m
>
> should work already.
>
> Hth,
> Dscho
Almost, but not what I want. With
    atag = tag -a -m
I still have to say
    $ git atag mytag mytag
But I just wanna say
    $ git atag mytag
to create an annotated tag as if I've said
    $ git tag -a -m "mytag" mytag

Dirk

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

* Re: git-config: aliases with parameter expansion ($1 and such)
  2008-03-23 14:04   ` Dirk Süsserott
  2008-03-23 14:19     ` Johannes Schindelin
@ 2008-03-23 19:38     ` Jeff King
  2008-03-23 19:45       ` Jeff King
  1 sibling, 1 reply; 13+ messages in thread
From: Jeff King @ 2008-03-23 19:38 UTC (permalink / raw)
  To: Dirk Süsserott; +Cc: Git Mailing List

On Sun, Mar 23, 2008 at 03:04:50PM +0100, Dirk Süsserott wrote:

>> atag = !git tag -a -m "$1"
> Thanks for the quick reply. Did you try that out? I did
>
> $ git atag foo
>
> with your definition and got a tag with message "$1" and
> the tag's name was "'foo'" (surrounded by single quotes).

If you want to use positional parameters, you have to invoke the shell
explicitly. Try:

  [alias]
    atag = !sh -c 'git tag -a -m "$0" "$0"'

As an aside, this should be "$1" but it looks like we don't pass the
shell a proper argv[0].

-Peff

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

* Re: git-config: aliases with parameter expansion ($1 and such)
  2008-03-23 14:19     ` Johannes Schindelin
  2008-03-23 14:31       ` Dirk Süsserott
@ 2008-03-23 19:38       ` Jeff King
  1 sibling, 0 replies; 13+ messages in thread
From: Jeff King @ 2008-03-23 19:38 UTC (permalink / raw)
  To: Johannes Schindelin; +Cc: Dirk Süsserott, Git Mailing List

On Sun, Mar 23, 2008 at 03:19:01PM +0100, Johannes Schindelin wrote:

> > > atag = !git tag -a -m "$1"
> 
> Why so complicated?
> 
> 	atag = tag -a -m
> 
> should work already.

The problem is that he needs to duplicate the final argument. I.e., "git
atag foo" becomes "git atag -a -m foo foo".

-Peff

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

* Re: git-config: aliases with parameter expansion ($1 and such)
  2008-03-23 19:38     ` Jeff King
@ 2008-03-23 19:45       ` Jeff King
  2008-03-24  1:54         ` Jay Soffian
  0 siblings, 1 reply; 13+ messages in thread
From: Jeff King @ 2008-03-23 19:45 UTC (permalink / raw)
  To: Dirk Süsserott; +Cc: Git Mailing List

On Sun, Mar 23, 2008 at 03:38:42PM -0400, Jeff King wrote:

>     atag = !sh -c 'git tag -a -m "$0" "$0"'
> 
> As an aside, this should be "$1" but it looks like we don't pass the
> shell a proper argv[0].

Hmm, I take it back. Git is doing the right thing, but it is a quirk of
the shell that it counts the first argument as the "name of the script"
even though the script actually comes from "-c".

  $ sh -c 'echo $0' foo
  foo
  $ echo 'echo $0' | sh
  sh

-Peff

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

* Re: git-config: aliases with parameter expansion ($1 and such)
  2008-03-23 19:45       ` Jeff King
@ 2008-03-24  1:54         ` Jay Soffian
  2008-03-24  2:47           ` Junio C Hamano
  0 siblings, 1 reply; 13+ messages in thread
From: Jay Soffian @ 2008-03-24  1:54 UTC (permalink / raw)
  To: Jeff King; +Cc: Dirk Süsserott, Git Mailing List

On Sun, Mar 23, 2008 at 3:45 PM, Jeff King <peff@peff.net> wrote:
>  Hmm, I take it back. Git is doing the right thing, but it is a quirk of
>  the shell that it counts the first argument as the "name of the script"
>  even though the script actually comes from "-c".
>
>   $ sh -c 'echo $0' foo
>   foo
>   $ echo 'echo $0' | sh
>   sh

All my shell aliases therefor look like:

h          = "!sh -c 'git alias \"$1\" || git help \"$1\"' -"

(Notice the trailing '-'.)

j.

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

* Re: git-config: aliases with parameter expansion ($1 and such)
  2008-03-24  1:54         ` Jay Soffian
@ 2008-03-24  2:47           ` Junio C Hamano
  2008-03-24 13:15             ` Dirk Süsserott
  2008-03-24 14:54             ` Jay Soffian
  0 siblings, 2 replies; 13+ messages in thread
From: Junio C Hamano @ 2008-03-24  2:47 UTC (permalink / raw)
  To: Jay Soffian; +Cc: Jeff King, Dirk Süsserott, Git Mailing List

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

> All my shell aliases therefor look like:
>
> h          = "!sh -c 'git alias \"$1\" || git help \"$1\"' -"
>
> (Notice the trailing '-'.)

Just for my curiosity, why aren't they

> h          = "!sh -c 'git alias \"$0\" || git help \"$0\"'"

without trailing '-'?

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

* Re: git-config: aliases with parameter expansion ($1 and such)
  2008-03-24  2:47           ` Junio C Hamano
@ 2008-03-24 13:15             ` Dirk Süsserott
  2008-03-24 19:29               ` Jeff King
  2008-03-24 14:54             ` Jay Soffian
  1 sibling, 1 reply; 13+ messages in thread
From: Dirk Süsserott @ 2008-03-24 13:15 UTC (permalink / raw)
  To: Git Mailing List

Thanks for the help. Both
    (1) atag = !sh -c 'git tag -a -m "$0" "$0"'
and
    (2) atag = !sh -c 'git tag -a -m "$1" "$1"' -
work, but in the latter case the '-' is indeed crucial.
If not given, $1 is not set and git tag complains badly.
When called without any args, (1) sets a tag called "sh"
whereas (2) complains about the missing value for the -m option.
So I decided to use the second form. Shells are funny things. ;-)

BTW: Is it true that "-a" is implicitely added to "git tag"
when the "-m" switch is present, i.e. are
    $ git tag -m foo foo
and
    $ git tag -a -m foo foo
equivalent? Thought so, but it's not in the docs.

Junio C Hamano schrieb:
> "Jay Soffian" <jaysoffian@gmail.com> writes:
>
>   
>> All my shell aliases therefor look like:
>>
>> h          = "!sh -c 'git alias \"$1\" || git help \"$1\"' -"
>>
>> (Notice the trailing '-'.)
>>     
>
> Just for my curiosity, why aren't they
>
>   
>> h          = "!sh -c 'git alias \"$0\" || git help \"$0\"'"
>>     
>
> without trailing '-'?
>   

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

* Re: git-config: aliases with parameter expansion ($1 and such)
  2008-03-24  2:47           ` Junio C Hamano
  2008-03-24 13:15             ` Dirk Süsserott
@ 2008-03-24 14:54             ` Jay Soffian
  1 sibling, 0 replies; 13+ messages in thread
From: Jay Soffian @ 2008-03-24 14:54 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Jeff King, Dirk Süsserott, Git Mailing List

On Sun, Mar 23, 2008 at 10:47 PM, Junio C Hamano <gitster@pobox.com> wrote:
> "Jay Soffian" <jaysoffian@gmail.com> writes:
>
>  > All my shell aliases therefor look like:
>  >
>  > h          = "!sh -c 'git alias \"$1\" || git help \"$1\"' -"
>  >
>  > (Notice the trailing '-'.)
>
>  Just for my curiosity, why aren't they
>
>  > h          = "!sh -c 'git alias \"$0\" || git help \"$0\"'"
>
>  without trailing '-'?

Lost to the mists of time. But I think for consistency with other
aliases where I was checking $#. Maybe.

j.

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

* Re: git-config: aliases with parameter expansion ($1 and such)
  2008-03-24 13:15             ` Dirk Süsserott
@ 2008-03-24 19:29               ` Jeff King
  0 siblings, 0 replies; 13+ messages in thread
From: Jeff King @ 2008-03-24 19:29 UTC (permalink / raw)
  To: Dirk Süsserott; +Cc: Git Mailing List

On Mon, Mar 24, 2008 at 02:15:21PM +0100, Dirk Süsserott wrote:

> Thanks for the help. Both
>    (1) atag = !sh -c 'git tag -a -m "$0" "$0"'
> and
>    (2) atag = !sh -c 'git tag -a -m "$1" "$1"' -
> work, but in the latter case the '-' is indeed crucial.
> If not given, $1 is not set and git tag complains badly.
> When called without any args, (1) sets a tag called "sh"
> whereas (2) complains about the missing value for the -m option.
> So I decided to use the second form. Shells are funny things. ;-)

I hadn't thought of that when I gave (1) as an example. I think (2) is
clearly superior for that reason.

> BTW: Is it true that "-a" is implicitely added to "git tag"
> when the "-m" switch is present, i.e. are
>    $ git tag -m foo foo
> and
>    $ git tag -a -m foo foo
> equivalent? Thought so, but it's not in the docs.

Yes, see builtin-tag:430-433 (it is also implied by -F). Care to submit
a documentation patch?

-Peff

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

end of thread, other threads:[~2008-03-24 19:30 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-03-23 13:28 git-config: aliases with parameter expansion ($1 and such) Dirk Süsserott
2008-03-23 13:45 ` Jay Soffian
2008-03-23 14:04   ` Dirk Süsserott
2008-03-23 14:19     ` Johannes Schindelin
2008-03-23 14:31       ` Dirk Süsserott
2008-03-23 19:38       ` Jeff King
2008-03-23 19:38     ` Jeff King
2008-03-23 19:45       ` Jeff King
2008-03-24  1:54         ` Jay Soffian
2008-03-24  2:47           ` Junio C Hamano
2008-03-24 13:15             ` Dirk Süsserott
2008-03-24 19:29               ` Jeff King
2008-03-24 14:54             ` Jay Soffian

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