{"thread":{"id":"12818","subject":"git-config: aliases with parameter expansion ($1 and such)","startedAt":"2008-03-23T13:28:21Z","lastAt":"2008-03-24T19:29:52Z","messageCount":13,"participants":["Dirk Süsserott","Jay Soffian","Johannes Schindelin","Jeff King","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"72744","messageId":"47E65AF5.4060708@dirk.my1.cc","threadId":"12818","inReplyTo":null,"subject":"git-config: aliases with parameter expansion ($1 and such)","fromName":"Dirk Süsserott","fromEmail":"newsletter@dirk.my1.cc","sentAt":"2008-03-23T13:28:21Z","receivedAt":"2008-03-23T13:28:21Z","isPatch":false,"sender":{"key":"newsletter@dirk.my1.cc","avatar":null},"body":"Hi, I've a question concerning git config and the alias things.\nI'd like to create an alias 'atag' that creates an annotated\ntag with the message being the same as the tag. Usually I create\nannotated tags like this:\n\n$ git tag -a -m \"mytag\" mytag\n\n(BTW: It's not documented, but I have the impression that\nthe '-a' switch is implicitely added when the '-m' switch\nis present. Is that true?)\n\nI'd like to have an alias like this:\n\n[alias]\n    atag = tag -a -m \"$1\"\n\nSo that I can simply call\n\n$ git atag mytag\n\nIs it possible to pass parameters to the alias definition?\nWith the definition above I got a tag with message \"$1\".\n\nThanks, Dirk\n"},{"id":"72748","messageId":"76718490803230645k13471472sc99932563b0239da@mail.gmail.com","threadId":"12818","inReplyTo":"47E65AF5.4060708@dirk.my1.cc","subject":"Re: git-config: aliases with parameter expansion ($1 and such)","fromName":"Jay Soffian","fromEmail":"jaysoffian@gmail.com","sentAt":"2008-03-23T13:45:34Z","receivedAt":"2008-03-23T13:45:34Z","isPatch":false,"sender":{"key":"jaysoffian@gmail.com","avatar":"https://avatars.githubusercontent.com/u/155970?v=4"},"body":"On Sun, Mar 23, 2008 at 9:28 AM, Dirk Süsserott <newsletter@dirk.my1.cc> wrote:\n> Hi, I've a question concerning git config and the alias things.\n>  I'd like to create an alias 'atag' that creates an annotated\n>  tag with the message being the same as the tag. Usually I create\n>  annotated tags like this:\n>\n>  $ git tag -a -m \"mytag\" mytag\n>\n>  (BTW: It's not documented, but I have the impression that\n>  the '-a' switch is implicitely added when the '-m' switch\n>  is present. Is that true?)\n>\n>  I'd like to have an alias like this:\n>\n>  [alias]\n>     atag = tag -a -m \"$1\"\n>\n>  So that I can simply call\n>\n>  $ git atag mytag\n>\n>  Is it possible to pass parameters to the alias definition?\n>  With the definition above I got a tag with message \"$1\".\n\natag = !git tag -a -m \"$1\"\n\nj.\n"},{"id":"72752","messageId":"47E66382.5030800@dirk.my1.cc","threadId":"12818","inReplyTo":"76718490803230645k13471472sc99932563b0239da@mail.gmail.com","subject":"Re: git-config: aliases with parameter expansion ($1 and such)","fromName":"Dirk Süsserott","fromEmail":"newsletter@dirk.my1.cc","sentAt":"2008-03-23T14:04:50Z","receivedAt":"2008-03-23T14:04:50Z","isPatch":false,"sender":{"key":"newsletter@dirk.my1.cc","avatar":null},"body":"Jay Soffian schrieb:\n> On Sun, Mar 23, 2008 at 9:28 AM, Dirk Süsserott <newsletter@dirk.my1.cc> wrote:\n>   \n>> Hi, I've a question concerning git config and the alias things.\n>>  I'd like to create an alias 'atag' that creates an annotated\n>>  tag with the message being the same as the tag. Usually I create\n>>  annotated tags like this:\n>>\n>>  $ git tag -a -m \"mytag\" mytag\n>>\n>>  (BTW: It's not documented, but I have the impression that\n>>  the '-a' switch is implicitely added when the '-m' switch\n>>  is present. Is that true?)\n>>\n>>  I'd like to have an alias like this:\n>>\n>>  [alias]\n>>     atag = tag -a -m \"$1\"\n>>\n>>  So that I can simply call\n>>\n>>  $ git atag mytag\n>>\n>>  Is it possible to pass parameters to the alias definition?\n>>  With the definition above I got a tag with message \"$1\".\n>>     \n>\n> atag = !git tag -a -m \"$1\"\n>\n> j.\n>   \nThanks for the quick reply. Did you try that out? I did\n\n$ git atag foo\n\nwith your definition and got a tag with message \"$1\" and\nthe tag's name was \"'foo'\" (surrounded by single quotes).\n\nIf you tried it and it worked (with linux), then it might\nbe a problem with my environment: I'm using Git with windows\nand the bash (Git-1.5.4-preview20080202.exe). Usually that\nworks very good, but sometimes it doesn't. Probably this\nis one of the few \"it doesn't\" things.\n\nDirk\n"},{"id":"72758","messageId":"alpine.LSU.1.00.0803231518340.4353@racer.site","threadId":"12818","inReplyTo":"47E66382.5030800@dirk.my1.cc","subject":"Re: git-config: aliases with parameter expansion ($1 and such)","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2008-03-23T14:19:01Z","receivedAt":"2008-03-23T14:19:01Z","isPatch":false,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Sun, 23 Mar 2008, Dirk Süsserott wrote:\n\n> Jay Soffian schrieb:\n> > On Sun, Mar 23, 2008 at 9:28 AM, Dirk Süsserott <newsletter@dirk.my1.cc>\n> > wrote:\n> >   \n> > > Hi, I've a question concerning git config and the alias things.\n> > >  I'd like to create an alias 'atag' that creates an annotated\n> > >  tag with the message being the same as the tag. Usually I create\n> > >  annotated tags like this:\n> > >\n> > >  $ git tag -a -m \"mytag\" mytag\n> > >\n> > >  (BTW: It's not documented, but I have the impression that\n> > >  the '-a' switch is implicitely added when the '-m' switch\n> > >  is present. Is that true?)\n> > >\n> > >  I'd like to have an alias like this:\n> > >\n> > >  [alias]\n> > >     atag = tag -a -m \"$1\"\n> > >\n> > >  So that I can simply call\n> > >\n> > >  $ git atag mytag\n> > >\n> > >  Is it possible to pass parameters to the alias definition?\n> > >  With the definition above I got a tag with message \"$1\".\n> > >     \n> >\n> > atag = !git tag -a -m \"$1\"\n\nWhy so complicated?\n\n\tatag = tag -a -m\n\nshould work already.\n\nHth,\nDscho"},{"id":"72838","messageId":"47E669CB.6070605@dirk.my1.cc","threadId":"12818","inReplyTo":"alpine.LSU.1.00.0803231518340.4353@racer.site","subject":"Re: git-config: aliases with parameter expansion ($1 and such)","fromName":"Dirk Süsserott","fromEmail":"newsletter@dirk.my1.cc","sentAt":"2008-03-23T14:31:39Z","receivedAt":"2008-03-23T14:31:39Z","isPatch":false,"sender":{"key":"newsletter@dirk.my1.cc","avatar":null},"body":"Johannes Schindelin schrieb:\n> Hi,\n>\n> On Sun, 23 Mar 2008, Dirk Süsserott wrote:\n>\n>   \n>> Jay Soffian schrieb:\n>>     \n>>> On Sun, Mar 23, 2008 at 9:28 AM, Dirk Süsserott <newsletter@dirk.my1.cc>\n>>> wrote:\n>>>   \n>>>       \n>>>> Hi, I've a question concerning git config and the alias things.\n>>>>  I'd like to create an alias 'atag' that creates an annotated\n>>>>  tag with the message being the same as the tag. Usually I create\n>>>>  annotated tags like this:\n>>>>\n>>>>  $ git tag -a -m \"mytag\" mytag\n>>>>\n>>>>  (BTW: It's not documented, but I have the impression that\n>>>>  the '-a' switch is implicitely added when the '-m' switch\n>>>>  is present. Is that true?)\n>>>>\n>>>>  I'd like to have an alias like this:\n>>>>\n>>>>  [alias]\n>>>>     atag = tag -a -m \"$1\"\n>>>>\n>>>>  So that I can simply call\n>>>>\n>>>>  $ git atag mytag\n>>>>\n>>>>  Is it possible to pass parameters to the alias definition?\n>>>>  With the definition above I got a tag with message \"$1\".\n>>>>     \n>>>>         \n>>> atag = !git tag -a -m \"$1\"\n>>>       \n>\n> Why so complicated?\n>\n> \tatag = tag -a -m\n>\n> should work already.\n>\n> Hth,\n> Dscho\nAlmost, but not what I want. With\n    atag = tag -a -m\nI still have to say\n    $ git atag mytag mytag\nBut I just wanna say\n    $ git atag mytag\nto create an annotated tag as if I've said\n    $ git tag -a -m \"mytag\" mytag\n\nDirk\n"},{"id":"72803","messageId":"20080323193842.GA23227@coredump.intra.peff.net","threadId":"12818","inReplyTo":"47E66382.5030800@dirk.my1.cc","subject":"Re: git-config: aliases with parameter expansion ($1 and such)","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2008-03-23T19:38:42Z","receivedAt":"2008-03-23T19:38:42Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sun, Mar 23, 2008 at 03:04:50PM +0100, Dirk Süsserott wrote:\n\n>> atag = !git tag -a -m \"$1\"\n> Thanks for the quick reply. Did you try that out? I did\n>\n> $ git atag foo\n>\n> with your definition and got a tag with message \"$1\" and\n> the tag's name was \"'foo'\" (surrounded by single quotes).\n\nIf you want to use positional parameters, you have to invoke the shell\nexplicitly. Try:\n\n  [alias]\n    atag = !sh -c 'git tag -a -m \"$0\" \"$0\"'\n\nAs an aside, this should be \"$1\" but it looks like we don't pass the\nshell a proper argv[0].\n\n-Peff\n"},{"id":"72804","messageId":"20080323193855.GA22535@coredump.intra.peff.net","threadId":"12818","inReplyTo":"alpine.LSU.1.00.0803231518340.4353@racer.site","subject":"Re: git-config: aliases with parameter expansion ($1 and such)","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2008-03-23T19:38:55Z","receivedAt":"2008-03-23T19:38:55Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sun, Mar 23, 2008 at 03:19:01PM +0100, Johannes Schindelin wrote:\n\n> > > atag = !git tag -a -m \"$1\"\n> \n> Why so complicated?\n> \n> \tatag = tag -a -m\n> \n> should work already.\n\nThe problem is that he needs to duplicate the final argument. I.e., \"git\natag foo\" becomes \"git atag -a -m foo foo\".\n\n-Peff\n"},{"id":"72806","messageId":"20080323194514.GA23492@coredump.intra.peff.net","threadId":"12818","inReplyTo":"20080323193842.GA23227@coredump.intra.peff.net","subject":"Re: git-config: aliases with parameter expansion ($1 and such)","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2008-03-23T19:45:15Z","receivedAt":"2008-03-23T19:45:15Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sun, Mar 23, 2008 at 03:38:42PM -0400, Jeff King wrote:\n\n>     atag = !sh -c 'git tag -a -m \"$0\" \"$0\"'\n> \n> As an aside, this should be \"$1\" but it looks like we don't pass the\n> shell a proper argv[0].\n\nHmm, I take it back. Git is doing the right thing, but it is a quirk of\nthe shell that it counts the first argument as the \"name of the script\"\neven though the script actually comes from \"-c\".\n\n  $ sh -c 'echo $0' foo\n  foo\n  $ echo 'echo $0' | sh\n  sh\n\n-Peff\n"},{"id":"72842","messageId":"76718490803231854u6ee76437h5acf37b0b602f3b1@mail.gmail.com","threadId":"12818","inReplyTo":"20080323194514.GA23492@coredump.intra.peff.net","subject":"Re: git-config: aliases with parameter expansion ($1 and such)","fromName":"Jay Soffian","fromEmail":"jaysoffian@gmail.com","sentAt":"2008-03-24T01:54:49Z","receivedAt":"2008-03-24T01:54:49Z","isPatch":false,"sender":{"key":"jaysoffian@gmail.com","avatar":"https://avatars.githubusercontent.com/u/155970?v=4"},"body":"On Sun, Mar 23, 2008 at 3:45 PM, Jeff King <peff@peff.net> wrote:\n>  Hmm, I take it back. Git is doing the right thing, but it is a quirk of\n>  the shell that it counts the first argument as the \"name of the script\"\n>  even though the script actually comes from \"-c\".\n>\n>   $ sh -c 'echo $0' foo\n>   foo\n>   $ echo 'echo $0' | sh\n>   sh\n\nAll my shell aliases therefor look like:\n\nh          = \"!sh -c 'git alias \\\"$1\\\" || git help \\\"$1\\\"' -\"\n\n(Notice the trailing '-'.)\n\nj.\n"},{"id":"72848","messageId":"7vzlso3kjc.fsf@gitster.siamese.dyndns.org","threadId":"12818","inReplyTo":"76718490803231854u6ee76437h5acf37b0b602f3b1@mail.gmail.com","subject":"Re: git-config: aliases with parameter expansion ($1 and such)","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-03-24T02:47:35Z","receivedAt":"2008-03-24T02:47:35Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Jay Soffian\" <jaysoffian@gmail.com> writes:\n\n> All my shell aliases therefor look like:\n>\n> h          = \"!sh -c 'git alias \\\"$1\\\" || git help \\\"$1\\\"' -\"\n>\n> (Notice the trailing '-'.)\n\nJust for my curiosity, why aren't they\n\n> h          = \"!sh -c 'git alias \\\"$0\\\" || git help \\\"$0\\\"'\"\n\nwithout trailing '-'?\n"},{"id":"72884","messageId":"47E7A969.8010405@dirk.my1.cc","threadId":"12818","inReplyTo":"7vzlso3kjc.fsf@gitster.siamese.dyndns.org","subject":"Re: git-config: aliases with parameter expansion ($1 and such)","fromName":"Dirk Süsserott","fromEmail":"newsletter@dirk.my1.cc","sentAt":"2008-03-24T13:15:21Z","receivedAt":"2008-03-24T13:15:21Z","isPatch":false,"sender":{"key":"newsletter@dirk.my1.cc","avatar":null},"body":"Thanks for the help. Both\n    (1) atag = !sh -c 'git tag -a -m \"$0\" \"$0\"'\nand\n    (2) atag = !sh -c 'git tag -a -m \"$1\" \"$1\"' -\nwork, but in the latter case the '-' is indeed crucial.\nIf not given, $1 is not set and git tag complains badly.\nWhen called without any args, (1) sets a tag called \"sh\"\nwhereas (2) complains about the missing value for the -m option.\nSo I decided to use the second form. Shells are funny things. ;-)\n\nBTW: Is it true that \"-a\" is implicitely added to \"git tag\"\nwhen the \"-m\" switch is present, i.e. are\n    $ git tag -m foo foo\nand\n    $ git tag -a -m foo foo\nequivalent? Thought so, but it's not in the docs.\n\nJunio C Hamano schrieb:\n> \"Jay Soffian\" <jaysoffian@gmail.com> writes:\n>\n>   \n>> All my shell aliases therefor look like:\n>>\n>> h          = \"!sh -c 'git alias \\\"$1\\\" || git help \\\"$1\\\"' -\"\n>>\n>> (Notice the trailing '-'.)\n>>     \n>\n> Just for my curiosity, why aren't they\n>\n>   \n>> h          = \"!sh -c 'git alias \\\"$0\\\" || git help \\\"$0\\\"'\"\n>>     \n>\n> without trailing '-'?\n>   \n"},{"id":"72899","messageId":"76718490803240754g161998bereb5bf3a22eb8ca76@mail.gmail.com","threadId":"12818","inReplyTo":"7vzlso3kjc.fsf@gitster.siamese.dyndns.org","subject":"Re: git-config: aliases with parameter expansion ($1 and such)","fromName":"Jay Soffian","fromEmail":"jaysoffian@gmail.com","sentAt":"2008-03-24T14:54:28Z","receivedAt":"2008-03-24T14:54:28Z","isPatch":false,"sender":{"key":"jaysoffian@gmail.com","avatar":"https://avatars.githubusercontent.com/u/155970?v=4"},"body":"On Sun, Mar 23, 2008 at 10:47 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> \"Jay Soffian\" <jaysoffian@gmail.com> writes:\n>\n>  > All my shell aliases therefor look like:\n>  >\n>  > h          = \"!sh -c 'git alias \\\"$1\\\" || git help \\\"$1\\\"' -\"\n>  >\n>  > (Notice the trailing '-'.)\n>\n>  Just for my curiosity, why aren't they\n>\n>  > h          = \"!sh -c 'git alias \\\"$0\\\" || git help \\\"$0\\\"'\"\n>\n>  without trailing '-'?\n\nLost to the mists of time. But I think for consistency with other\naliases where I was checking $#. Maybe.\n\nj.\n"},{"id":"72935","messageId":"20080324192952.GD14002@coredump.intra.peff.net","threadId":"12818","inReplyTo":"47E7A969.8010405@dirk.my1.cc","subject":"Re: git-config: aliases with parameter expansion ($1 and such)","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2008-03-24T19:29:52Z","receivedAt":"2008-03-24T19:29:52Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Mon, Mar 24, 2008 at 02:15:21PM +0100, Dirk Süsserott wrote:\n\n> Thanks for the help. Both\n>    (1) atag = !sh -c 'git tag -a -m \"$0\" \"$0\"'\n> and\n>    (2) atag = !sh -c 'git tag -a -m \"$1\" \"$1\"' -\n> work, but in the latter case the '-' is indeed crucial.\n> If not given, $1 is not set and git tag complains badly.\n> When called without any args, (1) sets a tag called \"sh\"\n> whereas (2) complains about the missing value for the -m option.\n> So I decided to use the second form. Shells are funny things. ;-)\n\nI hadn't thought of that when I gave (1) as an example. I think (2) is\nclearly superior for that reason.\n\n> BTW: Is it true that \"-a\" is implicitely added to \"git tag\"\n> when the \"-m\" switch is present, i.e. are\n>    $ git tag -m foo foo\n> and\n>    $ git tag -a -m foo foo\n> equivalent? Thought so, but it's not in the docs.\n\nYes, see builtin-tag:430-433 (it is also implied by -F). Care to submit\na documentation patch?\n\n-Peff\n"}]}