# git-config: aliases with parameter expansion ($1 and such)

13 messages from 2008-03-23 to 2008-03-24. Participants: Dirk Süsserott, Jay Soffian, Johannes Schindelin, Jeff King, Junio C Hamano.
Thread: https://gitlist.dev/t/12818

## Dirk Süsserott, 2008-03-23 13:28

Subject: git-config: aliases with parameter expansion ($1 and such)
Message-ID: <47E65AF5.4060708@dirk.my1.cc>
URL: https://gitlist.dev/e/47E65AF5.4060708%40dirk.my1.cc

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

```

## Jay Soffian, 2008-03-23 13:45

Subject: Re: git-config: aliases with parameter expansion ($1 and such)
Message-ID: <76718490803230645k13471472sc99932563b0239da@mail.gmail.com>
URL: https://gitlist.dev/e/76718490803230645k13471472sc99932563b0239da%40mail.gmail.com
In-Reply-To: <47E65AF5.4060708@dirk.my1.cc>

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

```

## Dirk Süsserott, 2008-03-23 14:04

Subject: Re: git-config: aliases with parameter expansion ($1 and such)
Message-ID: <47E66382.5030800@dirk.my1.cc>
URL: https://gitlist.dev/e/47E66382.5030800%40dirk.my1.cc
In-Reply-To: <76718490803230645k13471472sc99932563b0239da@mail.gmail.com>

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

```

## Johannes Schindelin, 2008-03-23 14:19

Subject: Re: git-config: aliases with parameter expansion ($1 and such)
Message-ID: <alpine.LSU.1.00.0803231518340.4353@racer.site>
URL: https://gitlist.dev/e/alpine.LSU.1.00.0803231518340.4353%40racer.site
In-Reply-To: <47E66382.5030800@dirk.my1.cc>

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

## Dirk Süsserott, 2008-03-23 14:31

Subject: Re: git-config: aliases with parameter expansion ($1 and such)
Message-ID: <47E669CB.6070605@dirk.my1.cc>
URL: https://gitlist.dev/e/47E669CB.6070605%40dirk.my1.cc
In-Reply-To: <alpine.LSU.1.00.0803231518340.4353@racer.site>

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

```

## Jeff King, 2008-03-23 19:38

Subject: Re: git-config: aliases with parameter expansion ($1 and such)
Message-ID: <20080323193842.GA23227@coredump.intra.peff.net>
URL: https://gitlist.dev/e/20080323193842.GA23227%40coredump.intra.peff.net
In-Reply-To: <47E66382.5030800@dirk.my1.cc>

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

```

## Jeff King, 2008-03-23 19:38

Subject: Re: git-config: aliases with parameter expansion ($1 and such)
Message-ID: <20080323193855.GA22535@coredump.intra.peff.net>
URL: https://gitlist.dev/e/20080323193855.GA22535%40coredump.intra.peff.net
In-Reply-To: <alpine.LSU.1.00.0803231518340.4353@racer.site>

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

```

## Jeff King, 2008-03-23 19:45

Subject: Re: git-config: aliases with parameter expansion ($1 and such)
Message-ID: <20080323194514.GA23492@coredump.intra.peff.net>
URL: https://gitlist.dev/e/20080323194514.GA23492%40coredump.intra.peff.net
In-Reply-To: <20080323193842.GA23227@coredump.intra.peff.net>

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

```

## Jay Soffian, 2008-03-24 01:54

Subject: Re: git-config: aliases with parameter expansion ($1 and such)
Message-ID: <76718490803231854u6ee76437h5acf37b0b602f3b1@mail.gmail.com>
URL: https://gitlist.dev/e/76718490803231854u6ee76437h5acf37b0b602f3b1%40mail.gmail.com
In-Reply-To: <20080323194514.GA23492@coredump.intra.peff.net>

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

```

## Junio C Hamano, 2008-03-24 02:47

Subject: Re: git-config: aliases with parameter expansion ($1 and such)
Message-ID: <7vzlso3kjc.fsf@gitster.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vzlso3kjc.fsf%40gitster.siamese.dyndns.org
In-Reply-To: <76718490803231854u6ee76437h5acf37b0b602f3b1@mail.gmail.com>

```
"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 '-'?

```

## Dirk Süsserott, 2008-03-24 13:15

Subject: Re: git-config: aliases with parameter expansion ($1 and such)
Message-ID: <47E7A969.8010405@dirk.my1.cc>
URL: https://gitlist.dev/e/47E7A969.8010405%40dirk.my1.cc
In-Reply-To: <7vzlso3kjc.fsf@gitster.siamese.dyndns.org>

```
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 '-'?
>   

```

## Jay Soffian, 2008-03-24 14:54

Subject: Re: git-config: aliases with parameter expansion ($1 and such)
Message-ID: <76718490803240754g161998bereb5bf3a22eb8ca76@mail.gmail.com>
URL: https://gitlist.dev/e/76718490803240754g161998bereb5bf3a22eb8ca76%40mail.gmail.com
In-Reply-To: <7vzlso3kjc.fsf@gitster.siamese.dyndns.org>

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

```

## Jeff King, 2008-03-24 19:29

Subject: Re: git-config: aliases with parameter expansion ($1 and such)
Message-ID: <20080324192952.GD14002@coredump.intra.peff.net>
URL: https://gitlist.dev/e/20080324192952.GD14002%40coredump.intra.peff.net
In-Reply-To: <47E7A969.8010405@dirk.my1.cc>

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

```
