{"thread":{"id":"23700","subject":"[PATCH] Set GIT_PATHNAME_PREFIX with aliases.","startedAt":"2010-05-05T00:25:22Z","lastAt":"2010-05-06T07:02:35Z","messageCount":23,"participants":["Jared Hance","Jeff King","Johannes Sixt","Eli Barzilay","Junio C Hamano","Jonathan Nieder","Will Palmer","Adam Brewster","Matthieu Moy"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"140951","messageId":"1273019122.16093.6.camel@ubuntu.ubuntu-domain","threadId":"23700","inReplyTo":null,"subject":"[PATCH] Set GIT_PATHNAME_PREFIX with aliases.","fromName":"Jared Hance","fromEmail":"jaredhance@gmail.com","sentAt":"2010-05-05T00:25:22Z","receivedAt":"2010-05-05T00:25:22Z","isPatch":true,"sender":{"key":"jaredhance@gmail.com","avatar":"https://avatars.githubusercontent.com/u/170192?v=4"},"body":"The environment variable GIT_PATHNAME_PREFIX passes on the\ncurrent working directory (where the git command was called from)\nto shell aliases (aliases that begin with \"!\"). This allows these\nshell aliases to know the directory that the git command was called\nfrom.\n\nSigned-off-by: Jared Hance <jaredhance@gmail.com>\n---\n git.c |    3 +++\n 1 files changed, 3 insertions(+), 0 deletions(-)\n\ndiff --git a/git.c b/git.c\nindex 6bae305..836f753 100644\n--- a/git.c\n+++ b/git.c\n@@ -167,6 +167,9 @@ static int handle_alias(int *argcp, const char ***argv)\n \t\t\t\tfree(alias_string);\n \t\t\t\talias_string = buf.buf;\n \t\t\t}\n+\t\t\tstatic char current_dir[PATH_MAX+1];\n+\t\t\tsetenv(\"GIT_PATHNAME_PREFIX\", getcwd(current_dir, sizeof(current_dir)), 1);\n+\n \t\t\ttrace_printf(\"trace: alias to shell cmd: %s => %s\\n\",\n \t\t\t\t     alias_command, alias_string + 1);\n \t\t\tret = system(alias_string + 1);\n-- \n1.7.0.4\n"},{"id":"140952","messageId":"20100505005153.GC25390@coredump.intra.peff.net","threadId":"23700","inReplyTo":"1273019122.16093.6.camel@ubuntu.ubuntu-domain","subject":"Re: [PATCH] Set GIT_PATHNAME_PREFIX with aliases.","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2010-05-05T00:51:53Z","receivedAt":"2010-05-05T00:51:53Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Tue, May 04, 2010 at 08:25:22PM -0400, Jared Hance wrote:\n\n> The environment variable GIT_PATHNAME_PREFIX passes on the\n> current working directory (where the git command was called from)\n> to shell aliases (aliases that begin with \"!\"). This allows these\n> shell aliases to know the directory that the git command was called\n> from.\n\nSeems like a reasonable goal, but...\n\n> --- a/git.c\n> +++ b/git.c\n> @@ -167,6 +167,9 @@ static int handle_alias(int *argcp, const char ***argv)\n>  \t\t\t\tfree(alias_string);\n>  \t\t\t\talias_string = buf.buf;\n>  \t\t\t}\n> +\t\t\tstatic char current_dir[PATH_MAX+1];\n> +\t\t\tsetenv(\"GIT_PATHNAME_PREFIX\", getcwd(current_dir, sizeof(current_dir)), 1);\n> +\n>  \t\t\ttrace_printf(\"trace: alias to shell cmd: %s => %s\\n\",\n>  \t\t\t\t     alias_command, alias_string + 1);\n>  \t\t\tret = system(alias_string + 1);\n\nI see three problems:\n\n  1. Don't declare variables in the middle of a function. It's a C99-ism\n     that we avoid to retain portability with older compilers.\n\n  2. On getcwd error, we setenv the value to NULL. Is that OK on all\n     platforms (I am specifically thinking of our Windows *env wrappers,\n     which have some restrictions, but I don't remember the details)?\n\n  3. Most importantly, isn't this totally the wrong place to look at\n     getcwd? We're just about to run system(), which means we will\n     already have done our chdir() (which probably is the one happening\n     in setup_git_directory). On even a simple test, it seems to always\n     print the root of the repository for me.\n\n     I think instead you want to pass in the prefix value computed by\n     setup_git_directory to handle_alias.\n\n-Peff\n"},{"id":"140968","messageId":"4BE115EF.8010306@viscovery.net","threadId":"23700","inReplyTo":"20100505005153.GC25390@coredump.intra.peff.net","subject":"Re: [PATCH] Set GIT_PATHNAME_PREFIX with aliases.","fromName":"Johannes Sixt","fromEmail":"j.sixt@viscovery.net","sentAt":"2010-05-05T06:53:35Z","receivedAt":"2010-05-05T06:53:35Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Am 5/5/2010 2:51, schrieb Jeff King:\n> On Tue, May 04, 2010 at 08:25:22PM -0400, Jared Hance wrote:\n> \n>> The environment variable GIT_PATHNAME_PREFIX passes on the\n>> current working directory (where the git command was called from)\n>> to shell aliases (aliases that begin with \"!\"). This allows these\n>> shell aliases to know the directory that the git command was called\n>> from.\n> \n> Seems like a reasonable goal, but...\n\nSorry, I disagree.\n\nThe availability of this environment variable doesn't help the alias\nwriter a lot:\n\n1. The alias is still burdened with the task to check *when* to use the\nvariable, i.e., whether an argument passed is absolute or relative, and\napply the variable only to a relative argument.\n\n2. When more than one pathspec is passed to the alias, it is tedious to\napply $GIT_PATHNAME_PREFIX to each of them.\n\nThe only way where this variable could be used in a useful manner is to\nwrite the alias as\n\n   !cd \"${GIT_PATHNAME_PREFIX:-.}\" && { do stuff... ; }\n\nwhich is something that git should do before it invokes the alias.\n\n-- Hannes\n"},{"id":"140969","messageId":"20100505070131.GA11265@coredump.intra.peff.net","threadId":"23700","inReplyTo":"4BE115EF.8010306@viscovery.net","subject":"Re: [PATCH] Set GIT_PATHNAME_PREFIX with aliases.","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2010-05-05T07:01:31Z","receivedAt":"2010-05-05T07:01:31Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Wed, May 05, 2010 at 08:53:35AM +0200, Johannes Sixt wrote:\n\n> Am 5/5/2010 2:51, schrieb Jeff King:\n> > On Tue, May 04, 2010 at 08:25:22PM -0400, Jared Hance wrote:\n> > \n> >> The environment variable GIT_PATHNAME_PREFIX passes on the\n> >> current working directory (where the git command was called from)\n> >> to shell aliases (aliases that begin with \"!\"). This allows these\n> >> shell aliases to know the directory that the git command was called\n> >> from.\n> > \n> > Seems like a reasonable goal, but...\n> \n> Sorry, I disagree.\n> [reasons why it sucks]\n\nYes, I agree it sucks. The problem is that this information is totally\nlost now for shell aliases, so you can't even do these painful things.\nYour alias simply doesn't have access to that information at all. I am\nopen to better interfaces (my \"reasonable\" above was not a ringing\nendorsement, but rather \"I can see why you might want to do this\").\n\n> The only way where this variable could be used in a useful manner is to\n> write the alias as\n> \n>    !cd \"${GIT_PATHNAME_PREFIX:-.}\" && { do stuff... ; }\n\nAgreed that is the only sane thing to do with it, but...\n\n> which is something that git should do before it invokes the alias.\n\nWouldn't we then be breaking existing aliases which do not expect this\nnew behavior?\n\n-Peff\n"},{"id":"140971","messageId":"19425.9169.537598.876589@winooski.ccs.neu.edu","threadId":"23700","inReplyTo":"20100505070131.GA11265@coredump.intra.peff.net","subject":"Re: [PATCH] Set GIT_PATHNAME_PREFIX with aliases.","fromName":"Eli Barzilay","fromEmail":"eli@barzilay.org","sentAt":"2010-05-05T07:52:49Z","receivedAt":"2010-05-05T07:52:49Z","isPatch":true,"sender":{"key":"eli@barzilay.org","avatar":"https://avatars.githubusercontent.com/u/185905?v=4"},"body":"On May  5, Jeff King wrote:\n> On Wed, May 05, 2010 at 08:53:35AM +0200, Johannes Sixt wrote:\n> \n> > Am 5/5/2010 2:51, schrieb Jeff King:\n> > > On Tue, May 04, 2010 at 08:25:22PM -0400, Jared Hance wrote:\n> > > \n> > >> The environment variable GIT_PATHNAME_PREFIX passes on the\n> > >> current working directory (where the git command was called from)\n> > >> to shell aliases (aliases that begin with \"!\"). This allows these\n> > >> shell aliases to know the directory that the git command was called\n> > >> from.\n> > > \n> > > Seems like a reasonable goal, but...\n> > \n> > Sorry, I disagree.\n> > [reasons why it sucks]\n> \n> Yes, I agree it sucks. The problem is that this information is\n> totally lost now for shell aliases, so you can't even do these\n> painful things.  Your alias simply doesn't have access to that\n> information at all. I am open to better interfaces (my \"reasonable\"\n> above was not a ringing endorsement, but rather \"I can see why you\n> might want to do this\").\n\nSomething that Jonathan suggested earlier is a different magic\ncharacter instead of \"!\" that will do the cd -- perhaps a second\ncharacter would be more acceptable, something like \"!!\"...\n\n-- \n          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:\n                    http://barzilay.org/                   Maze is Life!\n"},{"id":"140998","messageId":"7v1vdql4c9.fsf@alter.siamese.dyndns.org","threadId":"23700","inReplyTo":"19425.9169.537598.876589@winooski.ccs.neu.edu","subject":"Re: [PATCH] Set GIT_PATHNAME_PREFIX with aliases.","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-05-05T16:07:34Z","receivedAt":"2010-05-05T16:07:34Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Eli Barzilay <eli@barzilay.org> writes:\n\n> On May  5, Jeff King wrote:\n>> \n>> Yes, I agree it sucks.\n\nI would not use such a strong word but I agree that it would have been\nnicer if the original directory were used.\n\n> Something that Jonathan suggested earlier is a different magic\n> character instead of \"!\" that will do the cd -- perhaps a second\n> character would be more acceptable, something like \"!!\"...\n\nThat sounds a reasonable compromise.\n"},{"id":"141005","messageId":"19425.54504.163875.379151@winooski.ccs.neu.edu","threadId":"23700","inReplyTo":"7v1vdql4c9.fsf@alter.siamese.dyndns.org","subject":"[PATCH] An alias that starts with \"!!\" runs in the current directory.","fromName":"Eli Barzilay","fromEmail":"eli@barzilay.org","sentAt":"2010-05-05T20:28:24Z","receivedAt":"2010-05-05T20:28:24Z","isPatch":true,"sender":{"key":"eli@barzilay.org","avatar":"https://avatars.githubusercontent.com/u/185905?v=4"},"body":"With \"!\"-prefixed shell aliases, the shell command not only gets\nexecuted at the repository top level, but there is no way to know the\ncurrent directory of the original call.  This adds \"!!\"-prefixed aliases\nas a similar variant for \"!\"-prefixed ones, but the commands are\nexecuted in the original directory instead of the top level.\n\nSigned-off-by: Eli Barzilay <eli@barzilay.org>\n---\n\n(Sending as a reply to the earlier message, keeping CCs.)\n\nIt looks like setup_git_directory_gently() returns the original CWD, but\nsince it's not documented or commented, I don't know if this is reliable\nor not, so it might need to change.\n\nAlso, it might make more sense to document the \"!!\" variant first, since\nit is generally more useful, but the way things evolved with \"!!\" being\nthe longer prefix, it seems to me that documenting it after \"!\" is more\nsensible.\n\n Documentation/config.txt |    9 +++++++--\n git.c                    |    8 ++++++++\n 2 files changed, 15 insertions(+), 2 deletions(-)\n\ndiff --git a/Documentation/config.txt b/Documentation/config.txt\nindex 92f851e..055f4e3 100644\n--- a/Documentation/config.txt\n+++ b/Documentation/config.txt\n@@ -549,13 +549,18 @@ alias.*::\n \tspaces, the usual shell quoting and escaping is supported.\n \tquote pair and a backslash can be used to quote them.\n +\n-If the alias expansion is prefixed with an exclamation point,\n+If the alias expansion is prefixed with a single exclamation point,\n it will be treated as a shell command.  For example, defining\n \"alias.new = !gitk --all --not ORIG_HEAD\", the invocation\n \"git new\" is equivalent to running the shell command\n-\"gitk --all --not ORIG_HEAD\".  Note that shell commands will be\n+\"gitk --all --not ORIG_HEAD\".  Note that such shell commands will be\n executed from the top-level directory of a repository, which may\n not necessarily be the current directory.\n++\n+If the alias expansion is prefixed with two exclamation points,\n+it will be treader similarly to the above, except that the shell commands\n+are executed at the current directory.\n+\n \n am.keepcr::\n \tIf true, git-am will call git-mailsplit for patches in mbox format\ndiff --git a/git.c b/git.c\nindex 6bae305..f3f8346 100644\n--- a/git.c\n+++ b/git.c\n@@ -167,6 +167,14 @@ static int handle_alias(int *argcp, const char ***argv)\n \t\t\t\tfree(alias_string);\n \t\t\t\talias_string = buf.buf;\n \t\t\t}\n+\t\t\t/* going to exit anyway, so it's fine to change\n+\t\t\t * alias_string to the actual command */\n+\t\t\talias_string += 1;\n+\t\t\tif (alias_string[0] == '!') {\n+\t\t\t\talias_string += 1;\n+\t\t\t\tif (subdir && chdir(subdir))\n+\t\t\t\t\tdie_errno(\"Cannot change to '%s'\", subdir);\n+\t\t\t}\n \t\t\ttrace_printf(\"trace: alias to shell cmd: %s => %s\\n\",\n \t\t\t\t     alias_command, alias_string + 1);\n \t\t\tret = system(alias_string + 1);\n-- \n1.7.1\n"},{"id":"141006","messageId":"loom.20100505T225117-534@post.gmane.org","threadId":"23700","inReplyTo":"19425.54504.163875.379151@winooski.ccs.neu.edu","subject":"Re: [PATCH] An alias that starts with &quot;!!&quot; runs in the current directory.","fromName":"Jared Hance","fromEmail":"jaredhance@gmail.com","sentAt":"2010-05-05T20:52:37Z","receivedAt":"2010-05-05T20:52:37Z","isPatch":true,"sender":{"key":"jaredhance@gmail.com","avatar":"https://avatars.githubusercontent.com/u/170192?v=4"},"body":"Eli Barzilay <eli <at> barzilay.org> writes:\n\n>  \t\t\tret = system(alias_string + 1);\n\nI don't think that this is correct. You already changed alias_string to the\nactual code earlier in the command, so I think that this will actually chop off\nthe first letter of the command.\n"},{"id":"141008","messageId":"19425.56291.689142.569365@winooski.ccs.neu.edu","threadId":"23700","inReplyTo":"loom.20100505T225117-534@post.gmane.org","subject":"Re: [PATCH] An alias that starts with &quot;!!&quot; runs in the current directory.","fromName":"Eli Barzilay","fromEmail":"eli@barzilay.org","sentAt":"2010-05-05T20:58:11Z","receivedAt":"2010-05-05T20:58:11Z","isPatch":true,"sender":{"key":"eli@barzilay.org","avatar":"https://avatars.githubusercontent.com/u/185905?v=4"},"body":"On May  5, Jared Hance wrote:\n> Eli Barzilay <eli <at> barzilay.org> writes:\n> \n> >  \t\t\tret = system(alias_string + 1);\n> \n> I don't think that this is correct. You already changed alias_string\n> to the actual code earlier in the command, so I think that this will\n> actually chop off the first letter of the command.\n\n(*sigh*)  That's correct, I fixed this, but improperly remade the\npatch.\n\n-- \n          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:\n                    http://barzilay.org/                   Maze is Life!\n"},{"id":"141009","messageId":"19425.56411.745112.753594@winooski.ccs.neu.edu","threadId":"23700","inReplyTo":"19425.56291.689142.569365@winooski.ccs.neu.edu","subject":"Re: [PATCH] An alias that starts with &quot;!!&quot; runs in the current directory.","fromName":"Eli Barzilay","fromEmail":"eli@barzilay.org","sentAt":"2010-05-05T21:00:11Z","receivedAt":"2010-05-05T21:00:11Z","isPatch":true,"sender":{"key":"eli@barzilay.org","avatar":"https://avatars.githubusercontent.com/u/185905?v=4"},"body":"On May  5, Eli Barzilay wrote:\n> On May  5, Jared Hance wrote:\n> > Eli Barzilay <eli <at> barzilay.org> writes:\n> > \n> > >  \t\t\tret = system(alias_string + 1);\n> > \n> > I don't think that this is correct. You already changed alias_string\n> > to the actual code earlier in the command, so I think that this will\n> > actually chop off the first letter of the command.\n> \n> (*sigh*)  That's correct, I fixed this, but improperly remade the\n> patch.\n\nIs there some convention for sending a fixed patch?\n\n-- \n          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:\n                    http://barzilay.org/                   Maze is Life!\n"},{"id":"141011","messageId":"20100505212437.GA26487@progeny.tock","threadId":"23700","inReplyTo":"19425.56411.745112.753594@winooski.ccs.neu.edu","subject":"Re-submitting patches","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2010-05-05T21:24:37Z","receivedAt":"2010-05-05T21:24:37Z","isPatch":false,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Hi Eli,\n\nEli Barzilay wrote:\n> On May  5, Eli Barzilay wrote:\n\n>> (*sigh*)  That's correct, I fixed this, but improperly remade the\n>> patch.\n>\n> Is there some convention for sending a fixed patch?\n\nWith a small patch like this one, you can just send the fixed patch\nas a reply to the thread.  Putting “[PATCH v2]” in the subject would\nmake it clear that this is the newer and better version.\n\nWith larger patches, doing that too often can overload people.\nMy preferred solution: describe the changes as soon as you want, but\nthen take some time to polish them before resubmitting.  This gives\npeople time to breathe. ;-)\n\nThe “ideal patch flow” section in Documentation/SubmittingPatches\nsays:\n\n-------\n (3) Polish, refine, and re-send to the list and the people who\n     spend their time to improve your patch.  Go back to step (2).\n-------\n\nMaybe this could be clearer.  In particular, sometimes it is not\nobvious to people that even the patch submitter can pretend to be a\nreviewer and discuss small incremental changes.\n\nThanks for bringing it up,\nJonathan\n"},{"id":"141012","messageId":"19425.58081.592591.319107@winooski.ccs.neu.edu","threadId":"23700","inReplyTo":"20100505212437.GA26487@progeny.tock","subject":"Re: Re-submitting patches","fromName":"Eli Barzilay","fromEmail":"eli@barzilay.org","sentAt":"2010-05-05T21:28:01Z","receivedAt":"2010-05-05T21:28:01Z","isPatch":false,"sender":{"key":"eli@barzilay.org","avatar":"https://avatars.githubusercontent.com/u/185905?v=4"},"body":"On May  5, Jonathan Nieder wrote:\n> Hi Eli,\n> \n> Eli Barzilay wrote:\n> > On May  5, Eli Barzilay wrote:\n> \n> >> (*sigh*)  That's correct, I fixed this, but improperly remade the\n> >> patch.\n> >\n> > Is there some convention for sending a fixed patch?\n> \n> With a small patch like this one, you can just send the fixed patch\n> as a reply to the thread.  Putting “[PATCH v2]” in the subject would\n> make it clear that this is the newer and better version.\n\nAh -- it's the \"v2\" that I missed, thanks.\n\n\n> With larger patches, doing that too often can overload people.\n> My preferred solution: describe the changes as soon as you want, but\n> then take some time to polish them before resubmitting.  This gives\n> people time to breathe. ;-)\n\nYes, I'd be much more careful if this was not a quick thing.  (BTW, it\nwould be nice if there is a way to get various publishing commands\nlike `format-patch' and `pull' to spit out some warning if there are\nuncommitted changes -- that would have prevented me from sending the\nbogus one.)\n\n-- \n          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:\n                    http://barzilay.org/                   Maze is Life!\n"},{"id":"141013","messageId":"19425.58290.42871.986460@winooski.ccs.neu.edu","threadId":"23700","inReplyTo":"19425.54504.163875.379151@winooski.ccs.neu.edu","subject":"[PATCH v2] An alias that starts with \"!!\" runs in the current directory.","fromName":"Eli Barzilay","fromEmail":"eli@barzilay.org","sentAt":"2010-05-05T21:31:30Z","receivedAt":"2010-05-05T21:31:30Z","isPatch":true,"sender":{"key":"eli@barzilay.org","avatar":"https://avatars.githubusercontent.com/u/185905?v=4"},"body":"With \"!\"-prefixed shell aliases, the shell command not only gets\nexecuted at the repository top level, but there is no way to know the\ncurrent directory of the original call.  This adds \"!!\"-prefixed aliases\nas a similar variant for \"!\"-prefixed ones, but the commands are\nexecuted in the original directory instead of the top level.\n\nSigned-off-by: Eli Barzilay <eli@barzilay.org>\n---\n\nIt looks like setup_git_directory_gently() returns the original CWD, but\nsince it's not documented or commented, I don't know if this is reliable\nor not, so it might need to change.\n\nAlso, it might make more sense to document the \"!!\" variant first, since\nit is generally more useful, but the way things evolved with \"!!\" being\nthe longer prefix, it seems to me that documenting it after \"!\" is more\nsensible.\n\nThis fixes the broken use of alias_command that Jared Hance caught.\n\n Documentation/config.txt |    9 +++++++--\n git.c                    |   14 +++++++++++---\n 2 files changed, 18 insertions(+), 5 deletions(-)\n\ndiff --git a/Documentation/config.txt b/Documentation/config.txt\nindex 92f851e..055f4e3 100644\n--- a/Documentation/config.txt\n+++ b/Documentation/config.txt\n@@ -549,13 +549,18 @@ alias.*::\n \tspaces, the usual shell quoting and escaping is supported.\n \tquote pair and a backslash can be used to quote them.\n +\n-If the alias expansion is prefixed with an exclamation point,\n+If the alias expansion is prefixed with a single exclamation point,\n it will be treated as a shell command.  For example, defining\n \"alias.new = !gitk --all --not ORIG_HEAD\", the invocation\n \"git new\" is equivalent to running the shell command\n-\"gitk --all --not ORIG_HEAD\".  Note that shell commands will be\n+\"gitk --all --not ORIG_HEAD\".  Note that such shell commands will be\n executed from the top-level directory of a repository, which may\n not necessarily be the current directory.\n++\n+If the alias expansion is prefixed with two exclamation points,\n+it will be treader similarly to the above, except that the shell commands\n+are executed at the current directory.\n+\n \n am.keepcr::\n \tIf true, git-am will call git-mailsplit for patches in mbox format\ndiff --git a/git.c b/git.c\nindex 6bae305..3d8ed20 100644\n--- a/git.c\n+++ b/git.c\n@@ -167,14 +167,22 @@ static int handle_alias(int *argcp, const char ***argv)\n \t\t\t\tfree(alias_string);\n \t\t\t\talias_string = buf.buf;\n \t\t\t}\n+\t\t\t/* going to exit anyway, so it's fine to change\n+\t\t\t * alias_string to the actual command */\n+\t\t\talias_string += 1;\n+\t\t\tif (alias_string[0] == '!') {\n+\t\t\t\talias_string += 1;\n+\t\t\t\tif (subdir && chdir(subdir))\n+\t\t\t\t\tdie_errno(\"Cannot change to '%s'\", subdir);\n+\t\t\t}\n \t\t\ttrace_printf(\"trace: alias to shell cmd: %s => %s\\n\",\n-\t\t\t\t     alias_command, alias_string + 1);\n-\t\t\tret = system(alias_string + 1);\n+\t\t\t\t     alias_command, alias_string);\n+\t\t\tret = system(alias_string);\n \t\t\tif (ret >= 0 && WIFEXITED(ret) &&\n \t\t\t    WEXITSTATUS(ret) != 127)\n \t\t\t\texit(WEXITSTATUS(ret));\n \t\t\tdie(\"Failed to run '%s' when expanding alias '%s'\",\n-\t\t\t    alias_string + 1, alias_command);\n+\t\t\t    alias_string, alias_command);\n \t\t}\n \t\tcount = split_cmdline(alias_string, &new_argv);\n \t\tif (count < 0)\n-- \n1.7.1\n"},{"id":"141015","messageId":"7vvdb2hurp.fsf@alter.siamese.dyndns.org","threadId":"23700","inReplyTo":"19425.54504.163875.379151@winooski.ccs.neu.edu","subject":"Re: [PATCH] An alias that starts with \"!!\" runs in the current directory.","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-05-05T22:02:34Z","receivedAt":"2010-05-05T22:02:34Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Eli Barzilay <eli@barzilay.org> writes:\n\n> It looks like setup_git_directory_gently() returns the original CWD,...\n\nIt is designed to return what we internally call \"prefix\".  You however\nhave to be careful as it can return NULL or an empty string when you are\nalready at the top of the working tree.\n"},{"id":"141016","messageId":"19425.60825.824552.716664@winooski.ccs.neu.edu","threadId":"23700","inReplyTo":"7vvdb2hurp.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH] An alias that starts with \"!!\" runs in the current directory.","fromName":"Eli Barzilay","fromEmail":"eli@barzilay.org","sentAt":"2010-05-05T22:13:45Z","receivedAt":"2010-05-05T22:13:45Z","isPatch":true,"sender":{"key":"eli@barzilay.org","avatar":"https://avatars.githubusercontent.com/u/185905?v=4"},"body":"On May  5, Junio C Hamano wrote:\n> Eli Barzilay <eli@barzilay.org> writes:\n> \n> > It looks like setup_git_directory_gently() returns the original CWD,...\n> \n> It is designed to return what we internally call \"prefix\".  You\n> however have to be careful as it can return NULL or an empty string\n> when you are already at the top of the working tree.\n\nOK, in this case it looks like it should work as expected.  At least\nprovided that chdir(\"\") stays in the same directory -- and given the\ncall at the end of handle_alias(), it looks like this assumption is\nalready made.  Does this sound right?\n\n-- \n          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:\n                    http://barzilay.org/                   Maze is Life!\n"},{"id":"141017","messageId":"1273098179.723.10.camel@dreddbeard","threadId":"23700","inReplyTo":"19425.58290.42871.986460@winooski.ccs.neu.edu","subject":"Re: [PATCH v2] An alias that starts with \"!!\" runs in the current directory.","fromName":"Will Palmer","fromEmail":"wmpalmer@gmail.com","sentAt":"2010-05-05T22:22:59Z","receivedAt":"2010-05-05T22:22:59Z","isPatch":true,"sender":{"key":"wmpalmer@gmail.com","avatar":"https://avatars.githubusercontent.com/u/357044?v=4"},"body":"On Wed, 2010-05-05 at 17:31 -0400, Eli Barzilay wrote:\n> With \"!\"-prefixed shell aliases, the shell command not only gets\n> executed at the repository top level, but there is no way to know the\n> current directory of the original call.  This adds \"!!\"-prefixed aliases\n> as a similar variant for \"!\"-prefixed ones, but the commands are\n> executed in the original directory instead of the top level.\n> \n> Signed-off-by: Eli Barzilay <eli@barzilay.org>\n\nIs there any precedent for the \"!!\" syntax? Something like \".!\", \"./!\",\nor \"!(.)\" would make the intention more clear, I'd think, as well as\nleaving room for other extensions to be added later, and some\nexplicit-opposite, like \"/!\", to complement it. (It's not like people\nare going around with binaries called \"!\", is it?)\n\nIgnore my suggestions if it turns out that \"!!\" is used by other things,\nbut this one seems to be begging for someone else to come along with a\n\"me too!\"\n\n\n-- \n-- Will\n"},{"id":"141018","messageId":"19425.61989.608102.77250@winooski.ccs.neu.edu","threadId":"23700","inReplyTo":"1273098179.723.10.camel@dreddbeard","subject":"Re: [PATCH v2] An alias that starts with \"!!\" runs in the current directory.","fromName":"Eli Barzilay","fromEmail":"eli@barzilay.org","sentAt":"2010-05-05T22:33:09Z","receivedAt":"2010-05-05T22:33:09Z","isPatch":true,"sender":{"key":"eli@barzilay.org","avatar":"https://avatars.githubusercontent.com/u/185905?v=4"},"body":"On May  5, Will Palmer wrote:\n> On Wed, 2010-05-05 at 17:31 -0400, Eli Barzilay wrote:\n> > With \"!\"-prefixed shell aliases, the shell command not only gets\n> > executed at the repository top level, but there is no way to know the\n> > current directory of the original call.  This adds \"!!\"-prefixed aliases\n> > as a similar variant for \"!\"-prefixed ones, but the commands are\n> > executed in the original directory instead of the top level.\n> > \n> > Signed-off-by: Eli Barzilay <eli@barzilay.org>\n> \n> Is there any precedent for the \"!!\" syntax? Something like \".!\",\n> \"./!\", or \"!(.)\" would make the intention more clear, I'd think, as\n> well as leaving room for other extensions to be added later, and\n> some explicit-opposite, like \"/!\", to complement it. (It's not like\n> people are going around with binaries called \"!\", is it?)\n\n[\n\nThe first time I saw the \"!\" syntax, it was slightly confusing to me\nin that it's similar to various shells using \"!\" for history expansion\n-- especially given that these things are popular with shell aliases\nmade it hard to remember.\n\nAn alternative character that wouldn't have confused me, and even\nsuggests shell commands is \";\".  So my preference would be for shell\naliases to start with it and to be invoked in the original working\ndirectory, perhaps deprecating the \"!\" syntax.\n\nBut I'm new enough to be safely ignored...  So this is all a\nparenthetical comment...\n\n]\n\n-- \n          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:\n                    http://barzilay.org/                   Maze is Life!\n"},{"id":"141019","messageId":"7vpr19j4ng.fsf@alter.siamese.dyndns.org","threadId":"23700","inReplyTo":"1273098179.723.10.camel@dreddbeard","subject":"Re: [PATCH v2] An alias that starts with \"!!\" runs in the current directory.","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-05-05T23:43:47Z","receivedAt":"2010-05-05T23:43:47Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Will Palmer <wmpalmer@gmail.com> writes:\n\n> Is there any precedent for the \"!!\" syntax? Something like \".!\", \"./!\",\n> or \"!(.)\" would make the intention more clear, I'd think, as well as\n> leaving room for other extensions to be added later...\n\nWhile I don't think !! is particularly good (or bad), possible future\nextension is always a good reason to think about the notation carefully.\n\nIt probably is a good idea to switch aliases to start at the $cwd in 1.8.0\n(or perhaps one major release after it), and using a notation that is more\ndescriptive, something like \"!(cwd)\" vs \"!(root)\", may give us a better\ntranstion strategy than casting cryptic \"!!\" in the stone.\n\nWhat other variants might we want to be able to specify while defining and\nusing aliases?  If cwd vs root is the only distinction, then !(cwd) would\nbe a bit overkill, but if we used !! for this new feature, I suspect that\nit would make it much harder to switch the default in the future.\n\nComments?\n"},{"id":"141020","messageId":"n2qc376da901005051705t821b073do178d0261c4e4b2c0@mail.gmail.com","threadId":"23700","inReplyTo":"7vpr19j4ng.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH v2] An alias that starts with \"!!\" runs in the current directory.","fromName":"Adam Brewster","fromEmail":"adambrewster@gmail.com","sentAt":"2010-05-06T00:05:40Z","receivedAt":"2010-05-06T00:05:40Z","isPatch":true,"sender":{"key":"adambrewster@gmail.com","avatar":"https://avatars.githubusercontent.com/u/223816?v=4"},"body":"On 5/5/10, Junio C Hamano <gitster@pobox.com> wrote:\n>\n> It probably is a good idea to switch aliases to start at the $cwd in 1.8.0\n> (or perhaps one major release after it), and using a notation that is more\n> descriptive, something like \"!(cwd)\" vs \"!(root)\", may give us a better\n> transtion strategy than casting cryptic \"!!\" in the stone.\n>\n\nFor what it's worth, I like \"!cmd\".\n\nWould it be good enough to set some environment variables?\n\n    [alias]\n    command_in_cwd = \"!cd $GIT_CWD; ...\"\n\nAdam\n"},{"id":"141031","messageId":"1273126876.3562.4.camel@dreddbeard","threadId":"23700","inReplyTo":"n2qc376da901005051705t821b073do178d0261c4e4b2c0@mail.gmail.com","subject":"Re: [PATCH v2] An alias that starts with \"!!\" runs in the current directory.","fromName":"Will Palmer","fromEmail":"wmpalmer@gmail.com","sentAt":"2010-05-06T06:21:16Z","receivedAt":"2010-05-06T06:21:16Z","isPatch":true,"sender":{"key":"wmpalmer@gmail.com","avatar":"https://avatars.githubusercontent.com/u/357044?v=4"},"body":"On Wed, 2010-05-05 at 20:05 -0400, Adam Brewster wrote:\n> On 5/5/10, Junio C Hamano <gitster@pobox.com> wrote:\n> >\n> > It probably is a good idea to switch aliases to start at the $cwd in 1.8.0\n> > (or perhaps one major release after it), and using a notation that is more\n> > descriptive, something like \"!(cwd)\" vs \"!(root)\", may give us a better\n> > transtion strategy than casting cryptic \"!!\" in the stone.\n> >\n> \n> For what it's worth, I like \"!cmd\".\n> \n> Would it be good enough to set some environment variables?\n> \n>     [alias]\n>     command_in_cwd = \"!cd $GIT_CWD; ...\"\n> \n> Adam\n\nI'd be tempted to say that setting $GIT_CWD was an ideal solution, if\nJunio hadn't mentioned the possibility of cwd being the default in\n1.8.0, which to me sounds much more sane than defaulting to the\nrepository root. Defaulting to the root has never made sense to me and\nhas some perfectly good built-ins to emulate if needed. I know I have at\nleast two scripts-which-should-be-aliases sitting around because of this\nrestriction.\n\n-- \n-- Will\n"},{"id":"141034","messageId":"1273127200.3562.10.camel@dreddbeard","threadId":"23700","inReplyTo":"7vpr19j4ng.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH v2] An alias that starts with \"!!\" runs in the current directory.","fromName":"Will Palmer","fromEmail":"wmpalmer@gmail.com","sentAt":"2010-05-06T06:26:40Z","receivedAt":"2010-05-06T06:26:40Z","isPatch":true,"sender":{"key":"wmpalmer@gmail.com","avatar":"https://avatars.githubusercontent.com/u/357044?v=4"},"body":"On Wed, 2010-05-05 at 16:43 -0700, Junio C Hamano wrote:\n> What other variants might we want to be able to specify while defining and\n> using aliases?  If cwd vs root is the only distinction, then !(cwd) would\n> be a bit overkill, but if we used !! for this new feature, I suspect that\n> it would make it much harder to switch the default in the future.\n> \n> Comments?\n> \n> \n\nWhat I had in mind when I mentioned !(...)  were some half-formed ideas\nabout shortcuts for manipulating the environment, !(nopager), for\nexample.\n\nBut these ideas were vague and I can't think of any off-hand which I\nwould use other than !(cwd). I'd say !(root:path/to/dir), but that's\nobviously not necessary (any more than !(root) would be, if cwd were the\ndefault), and honestly I'm quite happy using shell functions for that\nsort of thing.\n\n-- \n-- Will\n"},{"id":"141035","messageId":"4BE26387.1010904@viscovery.net","threadId":"23700","inReplyTo":"7vpr19j4ng.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH v2] An alias that starts with \"!!\" runs in the current directory.","fromName":"Johannes Sixt","fromEmail":"j.sixt@viscovery.net","sentAt":"2010-05-06T06:36:55Z","receivedAt":"2010-05-06T06:36:55Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Am 5/6/2010 1:43, schrieb Junio C Hamano:\n> It probably is a good idea to switch aliases to start at the $cwd in 1.8.0\n> (or perhaps one major release after it), and using a notation that is more\n> descriptive, something like \"!(cwd)\" vs \"!(root)\", may give us a better\n> transtion strategy than casting cryptic \"!!\" in the stone.\n\nAs always, we should start with the verbose tag, and if one turns out to\nbe used frequently, use !! for it as a shortcut.\n\n> What other variants might we want to be able to specify while defining and\n> using aliases?  If cwd vs root is the only distinction, then !(cwd) would\n> be a bit overkill, but if we used !! for this new feature, I suspect that\n> it would make it much harder to switch the default in the future.\n\nThe syntax should use a symbol that is less likely to appear at the start\nof a shell script. Perhaps \"!@cwd\".\n\n-- Hannes\n"},{"id":"141040","messageId":"vpqfx25a4xg.fsf@bauges.imag.fr","threadId":"23700","inReplyTo":"7vpr19j4ng.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH v2] An alias that starts with \"!!\" runs in the current directory.","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@grenoble-inp.fr","sentAt":"2010-05-06T07:02:35Z","receivedAt":"2010-05-06T07:02:35Z","isPatch":true,"sender":{"key":"matthieu.moy@grenoble-inp.fr","avatar":"https://gravatar.com/avatar/72c8a2705971a25dfaff23cece15130d405685845d911aedd5667ace277f3fc5?d=mp&s=160"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> It probably is a good idea to switch aliases to start at the $cwd in 1.8.0\n> (or perhaps one major release after it), and using a notation that is more\n> descriptive, something like \"!(cwd)\" vs \"!(root)\", may give us a better\n> transtion strategy than casting cryptic \"!!\" in the stone.\n\nI like this: Allow !(cwd) and !(root) today, with !(root) being just\nlike \"!\", and change plain \"!\" to mean !(cwd) in a future major\nrelease.\n\nIf other people have ideas for other features, the syntax can also be\nextended to !(cwd,some-option) or so.\n\n-- \nMatthieu Moy\nhttp://www-verimag.imag.fr/~moy/\n"}]}