git-config: aliases with parameter expansion ($1 and such)
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
Quoted 14 lines · Dirk Süsserott
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]
Quoted 8 lines
atag = tag -a -m "$1"So that I can simply call
$ git atag mytagIs 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.
Quoted 22 lines · Jay Soffian
Quoted 20 lines · Dirk Süsserott
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
Quoted 8 lines
Quoted 3 lines
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
Quoted 7 lines · Dirk Süsserott
Quoted 1 line
atag = !git tag -a -m "$1"
Thanks for the quick reply. Did you try that out? I did
$ git atag foowith 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
Quoted 4 lines · Jeff King
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
Quoted 8 lines · Jeff King
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.
Quoted 5 lines · Jay Soffian
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
Quoted 1 line
h = "!sh -c 'git alias \"$0\" || git help \"$0\"'"
without trailing '-'?
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.
Quoted 18 lines · Junio C Hamano
Quoted 6 lines · Jay Soffian
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
Quoted 2 lines
h = "!sh -c 'git alias \"$0\" || git help \"$0\"'"
without trailing '-'?
Quoted 9 lines · Dirk Süsserott
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.
Quoted 6 lines
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
Quoted 6 lines · Junio C Hamano
Quoted 4 lines · Jay Soffian
All my shell aliases therefor look like:
h = "!sh -c 'git alias \"$1\" || git help \"$1\"' -"
Quoted 7 lines
Quoted 1 line
(Notice the trailing '-'.)
Just for my curiosity, why aren't they
Quoted 1 line
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.
Hi,
Quoted 22 lines · Dirk Süsserott
Quoted 21 lines · Jay Soffian
Quoted 18 lines · Dirk Süsserott
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
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
$ git atag mytagIs 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
Quoted 7 lines · Johannes Schindelin
Quoted 1 line
Quoted 1 line
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
Quoted 38 lines · Johannes Schindelin
Hi,
Quoted 24 lines · Dirk Süsserott
Quoted 22 lines · Jay Soffian
Quoted 18 lines · Dirk Süsserott
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
Quoted 8 lines
Quoted 8 lines
Quoted 6 lines
$ git atag mytagIs 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"
Quoted 8 lines
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