{"thread":{"id":"53614","subject":"Change Native Windows shell","startedAt":"2020-06-04T23:33:30Z","lastAt":"2020-06-09T11:18:56Z","messageCount":7,"participants":["Steven Penny","brian m. carlson","Jonathan Nieder","Johannes Schindelin"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"399155","messageId":"CAAXzdLXt4+-34+OhS=Jn=-VeORN3Y2jMzzg9+bhyn88aN4hm0A@mail.gmail.com","threadId":"53614","inReplyTo":null,"subject":"Change Native Windows shell","fromName":"Steven Penny","fromEmail":"svnpenn@gmail.com","sentAt":"2020-06-04T23:33:16Z","receivedAt":"2020-06-04T23:33:30Z","isPatch":false,"sender":{"key":"svnpenn@gmail.com","avatar":"https://avatars.githubusercontent.com/u/60531334?v=4"},"body":"The Git pager is set up by the function `setup_pager` [1]. `setup_pager` calls\n`prepare_pager_args` [2]. `prepare_pager_args` sets `use_shell` [3]. Then\n`setup_pager` calls `start_command` [4]. Then, since `use_shell` has been\ndefined, `prepare_shell_cmd` is called [5]. Finally, regardless of operating\nsystem, `sh` is called [6]:\n\n    #ifndef GIT_WINDOWS_NATIVE\n                    argv_array_push(out, SHELL_PATH);\n    #else\n                    argv_array_push(out, \"sh\");\n    #endif\n                    argv_array_push(out, \"-c\");\n\nThe issue is, that it is possible to build a fully static native Windows\nGit [7]. A Git like this can run on a stock Windows system, with no requirement\non MSYS2 or Cygwin. So it doesnt make sense for Git to be calling `sh`, when a\nuser may not have or need `sh` on their system. I think that on Native Windows\nbuilds, that the Pager should be called directly, or if a shell must be used,\nthen make it `cmd.exe` or `powershell.exe`.\n\n1. https://github.com/git/git/blob/20514004/pager.c#L106\n2. https://github.com/git/git/blob/20514004/pager.c#L127\n3. https://github.com/git/git/blob/20514004/pager.c#L101\n4. https://github.com/git/git/blob/20514004/pager.c#L130\n5. https://github.com/git/git/blob/20514004/run-command.c#L928\n6. https://github.com/git/git/blob/20514004/run-command.c#L272-L277\n7. https://github.com/nu8/gulf/blob/e9ea5c0b/chapter-2/program.sh\n"},{"id":"399157","messageId":"20200605000039.GB6569@camp.crustytoothpaste.net","threadId":"53614","inReplyTo":"CAAXzdLXt4+-34+OhS=Jn=-VeORN3Y2jMzzg9+bhyn88aN4hm0A@mail.gmail.com","subject":"Re: Change Native Windows shell","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2020-06-05T00:00:39Z","receivedAt":"2020-06-05T00:01:39Z","isPatch":false,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On 2020-06-04 at 23:33:16, Steven Penny wrote:\n> The Git pager is set up by the function `setup_pager` [1]. `setup_pager` calls\n> `prepare_pager_args` [2]. `prepare_pager_args` sets `use_shell` [3]. Then\n> `setup_pager` calls `start_command` [4]. Then, since `use_shell` has been\n> defined, `prepare_shell_cmd` is called [5]. Finally, regardless of operating\n> system, `sh` is called [6]:\n> \n>     #ifndef GIT_WINDOWS_NATIVE\n>                     argv_array_push(out, SHELL_PATH);\n>     #else\n>                     argv_array_push(out, \"sh\");\n>     #endif\n>                     argv_array_push(out, \"-c\");\n> \n> The issue is, that it is possible to build a fully static native Windows\n> Git [7]. A Git like this can run on a stock Windows system, with no requirement\n> on MSYS2 or Cygwin. So it doesnt make sense for Git to be calling `sh`, when a\n> user may not have or need `sh` on their system. I think that on Native Windows\n> builds, that the Pager should be called directly, or if a shell must be used,\n> then make it `cmd.exe` or `powershell.exe`.\n\nThis makes it impossible to write a configuration that works across\nplatforms.  CMD, PowerShell, and sh have entirely different quoting\nrules and functionality.  The user would not be able to specify a pager\nor editor with arguments portably.\n\nIn addition, Git supports the EDITOR and VISUAL environment variables\nfor editors and these always, 100% of the time, must be passed to sh to\nfunction correctly.  It would be a bug if, when I used Windows, these\nvariables were passed to CMD or PowerShell.  People also use GIT_EDITOR\nor GIT_SEQUENCE_EDITOR for scripting changes to git rebase -i, and these\nalso need to be interpreted in a portable way across systems, or\nprograms will break.\n\nFinally, Git needs sh for some commands, like git submodule, git bisect,\ngit filter-branch, and others.  While there's an effort to replace a lot\nof these with C because they don't perform very well on Windows, some of\nthem are highly interactive and unlikely to be used for scripting, so\nporting them doesn't make a lot of sense.\n\nIf you really need Git functionality that doesn't rely on sh, you can\nlook into libgit2 and its assorted language wrappers.\n-- \nbrian m. carlson: Houston, Texas, US\nOpenPGP: https://keybase.io/bk2204\n"},{"id":"399162","messageId":"CAAXzdLVk3jLzuB2vgKGObQDjPydpdiawKJJ+-NMa376Gu1zt1A@mail.gmail.com","threadId":"53614","inReplyTo":"20200605000039.GB6569@camp.crustytoothpaste.net","subject":"Re: Change Native Windows shell","fromName":"Steven Penny","fromEmail":"svnpenn@gmail.com","sentAt":"2020-06-05T04:21:32Z","receivedAt":"2020-06-05T04:21:47Z","isPatch":false,"sender":{"key":"svnpenn@gmail.com","avatar":"https://avatars.githubusercontent.com/u/60531334?v=4"},"body":"On Thu, Jun 4, 2020 at 7:01 PM brian m. carlson wrote:\n> If you really need Git functionality that doesn't rely on sh, you can\n> look into libgit2 and its assorted language wrappers.\n\nUh yeah, no. Im not reimplementing the entire Git program, when the fix is 7\nlines. Here it is, if anyone is interested:\n\ndiff --git a/run-command.c b/run-command.c\nindex 9b3a57d..4945632 100644\n--- a/run-command.c\n+++ b/run-command.c\n@@ -271,9 +271,6 @@ static const char **prepare_shell_cmd(struct\nargv_array *out, const char **argv)\n     if (strcspn(argv[0], \"|&;<>()$`\\\\\\\"' \\t\\n*?[#~=%\") != strlen(argv[0])) {\n #ifndef GIT_WINDOWS_NATIVE\n         argv_array_push(out, SHELL_PATH);\n-#else\n-        argv_array_push(out, \"sh\");\n-#endif\n         argv_array_push(out, \"-c\");\n\n         /*\n@@ -284,6 +281,10 @@ static const char **prepare_shell_cmd(struct\nargv_array *out, const char **argv)\n             argv_array_push(out, argv[0]);\n         else\n             argv_array_pushf(out, \"%s \\\"$@\\\"\", argv[0]);\n+#else\n+        argv_array_push(out, \"powershell\");\n+        argv_array_push(out, \"-Command\");\n+#endif\n     }\n\n     argv_array_pushv(out, argv);\n"},{"id":"399163","messageId":"20200605043930.GB193658@google.com","threadId":"53614","inReplyTo":"CAAXzdLVk3jLzuB2vgKGObQDjPydpdiawKJJ+-NMa376Gu1zt1A@mail.gmail.com","subject":"Re: Change Native Windows shell","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2020-06-05T04:39:30Z","receivedAt":"2020-06-05T04:39:37Z","isPatch":false,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Hi,\n\nSteven Penny wrote:\n> On Thu, Jun 4, 2020 at 7:01 PM brian m. carlson wrote:\n\n>> If you really need Git functionality that doesn't rely on sh, you can\n>> look into libgit2 and its assorted language wrappers.\n>\n> Uh yeah, no. Im not reimplementing the entire Git program, when the fix is 7\n> lines. Here it is, if anyone is interested:\n\nUnderstood: that's perfectly reasonable for your own use, and I can\nhope that this is the first step toward becoming an active Git\ncontributor in the future. :)\n\nHowever, for the reasons Brian said, it's not going into Git upstream.\n\nThanks and hope that helps,\nJonathan\n"},{"id":"399329","messageId":"nycvar.QRO.7.76.6.2006081935530.482@ZVAVAG-DN14RQO.ybpnyqbznva","threadId":"53614","inReplyTo":"CAAXzdLVk3jLzuB2vgKGObQDjPydpdiawKJJ+-NMa376Gu1zt1A@mail.gmail.com","subject":"Re: Change Native Windows shell","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2020-06-08T17:39:42Z","receivedAt":"2020-06-08T22:46:41Z","isPatch":false,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Steven,\n\nOn Thu, 4 Jun 2020, Steven Penny wrote:\n\n> On Thu, Jun 4, 2020 at 7:01 PM brian m. carlson wrote:\n> > If you really need Git functionality that doesn't rely on sh, you can\n> > look into libgit2 and its assorted language wrappers.\n>\n> Uh yeah, no. Im not reimplementing the entire Git program, when the fix is 7\n> lines. Here it is, if anyone is interested:\n>\n> diff --git a/run-command.c b/run-command.c\n> index 9b3a57d..4945632 100644\n> --- a/run-command.c\n> +++ b/run-command.c\n> @@ -271,9 +271,6 @@ static const char **prepare_shell_cmd(struct\n> argv_array *out, const char **argv)\n>      if (strcspn(argv[0], \"|&;<>()$`\\\\\\\"' \\t\\n*?[#~=%\") != strlen(argv[0])) {\n>  #ifndef GIT_WINDOWS_NATIVE\n>          argv_array_push(out, SHELL_PATH);\n> -#else\n> -        argv_array_push(out, \"sh\");\n> -#endif\n>          argv_array_push(out, \"-c\");\n>\n>          /*\n> @@ -284,6 +281,10 @@ static const char **prepare_shell_cmd(struct\n> argv_array *out, const char **argv)\n>              argv_array_push(out, argv[0]);\n>          else\n>              argv_array_pushf(out, \"%s \\\"$@\\\"\", argv[0]);\n> +#else\n> +        argv_array_push(out, \"powershell\");\n> +        argv_array_push(out, \"-Command\");\n> +#endif\n\nThat assumes that PowerShell is installed, which is not guaranteed,\neither.\n\nBesides, quoting rules are most likely different with PowerShell than what\nGit assumes, so you will have to take care of that, too.\n\nFinally, there are plenty of tips out there in the internet that simply\nexpect a POSIX shell to execute those script snippets. Any user would be\ncompletely (and unnnecessarily) puzzled if those snippets won't work with\ntheir Git for Windows.\n\nIn short: it would be unwise for me to accept this change into Git for\nWindows, at least as-is.\n\nCiao,\nJohannes\n\n>      }\n>\n>      argv_array_pushv(out, argv);\n>\n"},{"id":"399336","messageId":"CAAXzdLVmuONmow6cB-kko8-CkP2sA=UfpPBkiXqSCuTacGsFWA@mail.gmail.com","threadId":"53614","inReplyTo":"nycvar.QRO.7.76.6.2006081935530.482@ZVAVAG-DN14RQO.ybpnyqbznva","subject":"Re: Change Native Windows shell","fromName":"Steven Penny","fromEmail":"svnpenn@gmail.com","sentAt":"2020-06-08T23:14:05Z","receivedAt":"2020-06-09T00:35:57Z","isPatch":false,"sender":{"key":"svnpenn@gmail.com","avatar":"https://avatars.githubusercontent.com/u/60531334?v=4"},"body":"On Mon, Jun 8, 2020 at 5:46 PM Johannes Schindelin wrote:\n> That assumes that PowerShell is installed, which is not guaranteed,\n> either.\n>\n> Besides, quoting rules are most likely different with PowerShell than what\n> Git assumes, so you will have to take care of that, too.\n>\n> Finally, there are plenty of tips out there in the internet that simply\n> expect a POSIX shell to execute those script snippets. Any user would be\n> completely (and unnnecessarily) puzzled if those snippets won't work with\n> their Git for Windows.\n>\n> In short: it would be unwise for me to accept this change into Git for\n> Windows, at least as-is.\n\nI found a workaround. It seems as long as PAGER or similar is not get, then\nGit just tries to call `less.exe`. I didnt realize when I first posted this,\nbut native Windows Less is available:\n\nhttps://github.com/jftuga/less-Windows/releases\n\nSo I am just bundling that with my Windows native Git:\n\nhttps://github.com/nu8/gulf/releases\n"},{"id":"399346","messageId":"nycvar.QRO.7.76.6.2006090811000.482@ZVAVAG-DN14RQO.ybpnyqbznva","threadId":"53614","inReplyTo":"CAAXzdLVmuONmow6cB-kko8-CkP2sA=UfpPBkiXqSCuTacGsFWA@mail.gmail.com","subject":"Re: Change Native Windows shell","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2020-06-09T06:12:02Z","receivedAt":"2020-06-09T11:18:56Z","isPatch":false,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Steven,\n\nOn Mon, 8 Jun 2020, Steven Penny wrote:\n\n> On Mon, Jun 8, 2020 at 5:46 PM Johannes Schindelin wrote:\n> > That assumes that PowerShell is installed, which is not guaranteed,\n> > either.\n> >\n> > Besides, quoting rules are most likely different with PowerShell than what\n> > Git assumes, so you will have to take care of that, too.\n> >\n> > Finally, there are plenty of tips out there in the internet that simply\n> > expect a POSIX shell to execute those script snippets. Any user would be\n> > completely (and unnnecessarily) puzzled if those snippets won't work with\n> > their Git for Windows.\n> >\n> > In short: it would be unwise for me to accept this change into Git for\n> > Windows, at least as-is.\n>\n> I found a workaround. It seems as long as PAGER or similar is not get, then\n> Git just tries to call `less.exe`. I didnt realize when I first posted this,\n> but native Windows Less is available:\n>\n> https://github.com/jftuga/less-Windows/releases\n>\n> So I am just bundling that with my Windows native Git:\n>\n> https://github.com/nu8/gulf/releases\n\nWhat is your plan to address concerns of users trying to run popular\nhooks? Those example hooks, and recommended hooks, that you can find e.g.\non StackOverflow are all POSIX shell scripts.\n\nCiao,\nJohannes\n"}]}