{"thread":{"id":"20967","subject":"[PATCH] archive: Refuse to write the archive to a terminal.","startedAt":"2009-09-16T10:31:33Z","lastAt":"2009-09-17T05:53:35Z","messageCount":7,"participants":["Josh Triplett","Johannes Sixt","Mikael Magnusson","Reece Dunn","Matthieu Moy"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"123333","messageId":"20090916103129.GA21430@feather","threadId":"20967","inReplyTo":null,"subject":"[PATCH] archive: Refuse to write the archive to a terminal.","fromName":"Josh Triplett","fromEmail":"josh@joshtriplett.org","sentAt":"2009-09-16T10:31:33Z","receivedAt":"2009-09-16T10:31:33Z","isPatch":true,"sender":{"key":"josh@joshtriplett.org","avatar":"https://avatars.githubusercontent.com/u/162737?v=4"},"body":"If not given the -o/--output option, git archive writes the archive to\nstdout.  This proves unhelpful if not redirected or piped somewhere.\nRather than spewing binary at the user's terminal, die with an\nappropriate message.\n\nSigned-off-by: Josh Triplett <josh@joshtriplett.org>\n---\n\nI considered adding a -f/--force option, like gzip has, but writing an\narchive to a tty seems like a sufficiently insane use case that I'll let\nwhoever actually needs that write the patch for it. ;)\n\n builtin-archive.c |    3 +++\n 1 files changed, 3 insertions(+), 0 deletions(-)\n\ndiff --git a/builtin-archive.c b/builtin-archive.c\nindex 12351e9..73accd0 100644\n--- a/builtin-archive.c\n+++ b/builtin-archive.c\n@@ -101,6 +101,9 @@ int cmd_archive(int argc, const char **argv, const char *prefix)\n \t\tcreate_output_file(output);\n \t\tif (!format)\n \t\t\tformat = format_from_name(output);\n+\t} else if (isatty(1)) {\n+\t\tdie(\"Archive not written to a terminal.\\n\"\n+\t\t    \"Specify output filename or redirect output.\");\n \t}\n \n \tif (format) {\n-- \n1.6.3.3\n"},{"id":"123336","messageId":"4AB0C7DE.7030109@viscovery.net","threadId":"20967","inReplyTo":"20090916103129.GA21430@feather","subject":"Re: [PATCH] archive: Refuse to write the archive to a terminal.","fromName":"Johannes Sixt","fromEmail":"j.sixt@viscovery.net","sentAt":"2009-09-16T11:11:26Z","receivedAt":"2009-09-16T11:11:26Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Josh Triplett schrieb:\n> I considered adding a -f/--force option, like gzip has, but writing an\n> archive to a tty seems like a sufficiently insane use case that I'll let\n> whoever actually needs that write the patch for it. ;)\n\nHow about '--output -' instead?\n\n-- Hannes\n"},{"id":"123338","messageId":"237967ef0909160427m4d7de120tf5ef3176f75123ad@mail.gmail.com","threadId":"20967","inReplyTo":"4AB0C7DE.7030109@viscovery.net","subject":"Re: [PATCH] archive: Refuse to write the archive to a terminal.","fromName":"Mikael Magnusson","fromEmail":"mikachu@gmail.com","sentAt":"2009-09-16T11:27:13Z","receivedAt":"2009-09-16T11:27:13Z","isPatch":true,"sender":{"key":"mikachu@gmail.com","avatar":null},"body":"2009/9/16 Johannes Sixt <j.sixt@viscovery.net>:\n> Josh Triplett schrieb:\n>> I considered adding a -f/--force option, like gzip has, but writing an\n>> archive to a tty seems like a sufficiently insane use case that I'll let\n>> whoever actually needs that write the patch for it. ;)\n>\n> How about '--output -' instead?\n\nYou could always just add '|cat'.\n\n-- \nMikael Magnusson\n"},{"id":"123340","messageId":"3f4fd2640909160448x1fbb7a64s1ce0adca2af5010@mail.gmail.com","threadId":"20967","inReplyTo":"237967ef0909160427m4d7de120tf5ef3176f75123ad@mail.gmail.com","subject":"Re: [PATCH] archive: Refuse to write the archive to a terminal.","fromName":"Reece Dunn","fromEmail":"msclrhd@googlemail.com","sentAt":"2009-09-16T11:48:15Z","receivedAt":"2009-09-16T11:48:15Z","isPatch":true,"sender":{"key":"msclrhd@googlemail.com","avatar":null},"body":"2009/9/16 Mikael Magnusson <mikachu@gmail.com>:\n> 2009/9/16 Johannes Sixt <j.sixt@viscovery.net>:\n>> Josh Triplett schrieb:\n>>> I considered adding a -f/--force option, like gzip has, but writing an\n>>> archive to a tty seems like a sufficiently insane use case that I'll let\n>>> whoever actually needs that write the patch for it. ;)\n>>\n>> How about '--output -' instead?\n>\n> You could always just add '|cat'.\n\nExcept when running on Windows. Yes MSYS and cygwin provide a version\nof cat, but this cannot be guaranteed (e.g. with the series to support\nbuilding with MSVC).\n\nThe `--output -` / `-o -` syntax looks reasonable (the issue with\nusing -f/--force is: what are you forcing the operation of?). Is -\nused elsewhere in git for specifying stdout?\n\nAlso, the die message might be more useful (and in keeping with the\nother git commands) by showing the 'inline context help'; something\nlike:\n\n    Failed to generate the archive: output is a terminal.\n    Please specify the file to write to (using `-o archive.tar`) or\nredirect the output (e.g. `... | gzip`).\n    If you want to write the archive out to the terminal, use `-o -`\nto force the operation.\n\n- Reece\n"},{"id":"123345","messageId":"vpq8wgfm4ho.fsf@bauges.imag.fr","threadId":"20967","inReplyTo":"3f4fd2640909160448x1fbb7a64s1ce0adca2af5010@mail.gmail.com","subject":"Re: [PATCH] archive: Refuse to write the archive to a terminal.","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@grenoble-inp.fr","sentAt":"2009-09-16T12:57:39Z","receivedAt":"2009-09-16T12:57:39Z","isPatch":true,"sender":{"key":"matthieu.moy@grenoble-inp.fr","avatar":"https://gravatar.com/avatar/72c8a2705971a25dfaff23cece15130d405685845d911aedd5667ace277f3fc5?d=mp&s=160"},"body":"Reece Dunn <msclrhd@googlemail.com> writes:\n\n> 2009/9/16 Mikael Magnusson <mikachu@gmail.com>:\n>> 2009/9/16 Johannes Sixt <j.sixt@viscovery.net>:\n>>> Josh Triplett schrieb:\n>>>> I considered adding a -f/--force option, like gzip has, but writing an\n>>>> archive to a tty seems like a sufficiently insane use case that I'll let\n>>>> whoever actually needs that write the patch for it. ;)\n>>>\n>>> How about '--output -' instead?\n>>\n>> You could always just add '|cat'.\n>\n> Except when running on Windows. Yes MSYS and cygwin provide a version\n> of cat, but this cannot be guaranteed (e.g. with the series to support\n> building with MSVC).\n\nIn general, autodectection features sometimes fail, so it's good to\nhave an explicit override option.\n\n> The `--output -` / `-o -` syntax looks reasonable\n\nI like this too.\n\n-- \nMatthieu Moy\nhttp://www-verimag.imag.fr/~moy/\n"},{"id":"123398","messageId":"20090917014854.GD3274@feather","threadId":"20967","inReplyTo":"4AB0C7DE.7030109@viscovery.net","subject":"Re: [PATCH] archive: Refuse to write the archive to a terminal.","fromName":"Josh Triplett","fromEmail":"josh@joshtriplett.org","sentAt":"2009-09-17T01:49:10Z","receivedAt":"2009-09-17T01:49:10Z","isPatch":true,"sender":{"key":"josh@joshtriplett.org","avatar":"https://avatars.githubusercontent.com/u/162737?v=4"},"body":"On Wed, Sep 16, 2009 at 01:11:26PM +0200, Johannes Sixt wrote:\n> Josh Triplett schrieb:\n> > I considered adding a -f/--force option, like gzip has, but writing an\n> > archive to a tty seems like a sufficiently insane use case that I'll let\n> > whoever actually needs that write the patch for it. ;)\n> \n> How about '--output -' instead?\n\nYeah, that seems significantly better than --force.  Though I don't\nparticularly care for the '-' convention to mean 'stdout'; in principle\nthat ought to create a file named '-' in the current directory.\n/dev/stdout makes more sense, and doesn't require any work on git's\npart beyond this patch.\n\n- Josh Triplett\n"},{"id":"123408","messageId":"4AB1CEDF.7020105@viscovery.net","threadId":"20967","inReplyTo":"20090917014854.GD3274@feather","subject":"Re: [PATCH] archive: Refuse to write the archive to a terminal.","fromName":"Johannes Sixt","fromEmail":"j.sixt@viscovery.net","sentAt":"2009-09-17T05:53:35Z","receivedAt":"2009-09-17T05:53:35Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Josh Triplett schrieb:\n> On Wed, Sep 16, 2009 at 01:11:26PM +0200, Johannes Sixt wrote:\n>> How about '--output -' instead?\n> \n> Yeah, that seems significantly better than --force.  Though I don't\n> particularly care for the '-' convention to mean 'stdout'; in principle\n> that ought to create a file named '-' in the current directory.\n> /dev/stdout makes more sense, and doesn't require any work on git's\n> part beyond this patch.\n\nExcept that /dev/stdout is not portable. You can always say --output ./-\nif you want an oddly named file in the current directory.\n\n-- Hannes\n"}]}