git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] archive: Refuse to write the archive to a terminal.
@ 2009-09-16 10:31 Josh Triplett
  2009-09-16 11:11 ` Johannes Sixt
  0 siblings, 1 reply; 7+ messages in thread
From: Josh Triplett @ 2009-09-16 10:31 UTC (permalink / raw)
  To: git, gitster

If not given the -o/--output option, git archive writes the archive to
stdout.  This proves unhelpful if not redirected or piped somewhere.
Rather than spewing binary at the user's terminal, die with an
appropriate message.

Signed-off-by: Josh Triplett <josh@joshtriplett.org>
---

I considered adding a -f/--force option, like gzip has, but writing an
archive to a tty seems like a sufficiently insane use case that I'll let
whoever actually needs that write the patch for it. ;)

 builtin-archive.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/builtin-archive.c b/builtin-archive.c
index 12351e9..73accd0 100644
--- a/builtin-archive.c
+++ b/builtin-archive.c
@@ -101,6 +101,9 @@ int cmd_archive(int argc, const char **argv, const char *prefix)
 		create_output_file(output);
 		if (!format)
 			format = format_from_name(output);
+	} else if (isatty(1)) {
+		die("Archive not written to a terminal.\n"
+		    "Specify output filename or redirect output.");
 	}
 
 	if (format) {
-- 
1.6.3.3

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] archive: Refuse to write the archive to a terminal.
  2009-09-16 10:31 [PATCH] archive: Refuse to write the archive to a terminal Josh Triplett
@ 2009-09-16 11:11 ` Johannes Sixt
  2009-09-16 11:27   ` Mikael Magnusson
  2009-09-17  1:49   ` Josh Triplett
  0 siblings, 2 replies; 7+ messages in thread
From: Johannes Sixt @ 2009-09-16 11:11 UTC (permalink / raw)
  To: Josh Triplett; +Cc: git, gitster

Josh Triplett schrieb:
> I considered adding a -f/--force option, like gzip has, but writing an
> archive to a tty seems like a sufficiently insane use case that I'll let
> whoever actually needs that write the patch for it. ;)

How about '--output -' instead?

-- Hannes

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] archive: Refuse to write the archive to a terminal.
  2009-09-16 11:11 ` Johannes Sixt
@ 2009-09-16 11:27   ` Mikael Magnusson
  2009-09-16 11:48     ` Reece Dunn
  2009-09-17  1:49   ` Josh Triplett
  1 sibling, 1 reply; 7+ messages in thread
From: Mikael Magnusson @ 2009-09-16 11:27 UTC (permalink / raw)
  To: Johannes Sixt; +Cc: Josh Triplett, git, gitster

2009/9/16 Johannes Sixt <j.sixt@viscovery.net>:
> Josh Triplett schrieb:
>> I considered adding a -f/--force option, like gzip has, but writing an
>> archive to a tty seems like a sufficiently insane use case that I'll let
>> whoever actually needs that write the patch for it. ;)
>
> How about '--output -' instead?

You could always just add '|cat'.

-- 
Mikael Magnusson

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] archive: Refuse to write the archive to a terminal.
  2009-09-16 11:27   ` Mikael Magnusson
@ 2009-09-16 11:48     ` Reece Dunn
  2009-09-16 12:57       ` Matthieu Moy
  0 siblings, 1 reply; 7+ messages in thread
From: Reece Dunn @ 2009-09-16 11:48 UTC (permalink / raw)
  To: Mikael Magnusson; +Cc: Johannes Sixt, Josh Triplett, git, gitster

2009/9/16 Mikael Magnusson <mikachu@gmail.com>:
> 2009/9/16 Johannes Sixt <j.sixt@viscovery.net>:
>> Josh Triplett schrieb:
>>> I considered adding a -f/--force option, like gzip has, but writing an
>>> archive to a tty seems like a sufficiently insane use case that I'll let
>>> whoever actually needs that write the patch for it. ;)
>>
>> How about '--output -' instead?
>
> You could always just add '|cat'.

Except when running on Windows. Yes MSYS and cygwin provide a version
of cat, but this cannot be guaranteed (e.g. with the series to support
building with MSVC).

The `--output -` / `-o -` syntax looks reasonable (the issue with
using -f/--force is: what are you forcing the operation of?). Is -
used elsewhere in git for specifying stdout?

Also, the die message might be more useful (and in keeping with the
other git commands) by showing the 'inline context help'; something
like:

    Failed to generate the archive: output is a terminal.
    Please specify the file to write to (using `-o archive.tar`) or
redirect the output (e.g. `... | gzip`).
    If you want to write the archive out to the terminal, use `-o -`
to force the operation.

- Reece

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] archive: Refuse to write the archive to a terminal.
  2009-09-16 11:48     ` Reece Dunn
@ 2009-09-16 12:57       ` Matthieu Moy
  0 siblings, 0 replies; 7+ messages in thread
From: Matthieu Moy @ 2009-09-16 12:57 UTC (permalink / raw)
  To: Reece Dunn; +Cc: Mikael Magnusson, Johannes Sixt, Josh Triplett, git, gitster

Reece Dunn <msclrhd@googlemail.com> writes:

> 2009/9/16 Mikael Magnusson <mikachu@gmail.com>:
>> 2009/9/16 Johannes Sixt <j.sixt@viscovery.net>:
>>> Josh Triplett schrieb:
>>>> I considered adding a -f/--force option, like gzip has, but writing an
>>>> archive to a tty seems like a sufficiently insane use case that I'll let
>>>> whoever actually needs that write the patch for it. ;)
>>>
>>> How about '--output -' instead?
>>
>> You could always just add '|cat'.
>
> Except when running on Windows. Yes MSYS and cygwin provide a version
> of cat, but this cannot be guaranteed (e.g. with the series to support
> building with MSVC).

In general, autodectection features sometimes fail, so it's good to
have an explicit override option.

> The `--output -` / `-o -` syntax looks reasonable

I like this too.

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] archive: Refuse to write the archive to a terminal.
  2009-09-16 11:11 ` Johannes Sixt
  2009-09-16 11:27   ` Mikael Magnusson
@ 2009-09-17  1:49   ` Josh Triplett
  2009-09-17  5:53     ` Johannes Sixt
  1 sibling, 1 reply; 7+ messages in thread
From: Josh Triplett @ 2009-09-17  1:49 UTC (permalink / raw)
  To: Johannes Sixt; +Cc: git, gitster

On Wed, Sep 16, 2009 at 01:11:26PM +0200, Johannes Sixt wrote:
> Josh Triplett schrieb:
> > I considered adding a -f/--force option, like gzip has, but writing an
> > archive to a tty seems like a sufficiently insane use case that I'll let
> > whoever actually needs that write the patch for it. ;)
> 
> How about '--output -' instead?

Yeah, that seems significantly better than --force.  Though I don't
particularly care for the '-' convention to mean 'stdout'; in principle
that ought to create a file named '-' in the current directory.
/dev/stdout makes more sense, and doesn't require any work on git's
part beyond this patch.

- Josh Triplett

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] archive: Refuse to write the archive to a terminal.
  2009-09-17  1:49   ` Josh Triplett
@ 2009-09-17  5:53     ` Johannes Sixt
  0 siblings, 0 replies; 7+ messages in thread
From: Johannes Sixt @ 2009-09-17  5:53 UTC (permalink / raw)
  To: Josh Triplett; +Cc: git, gitster

Josh Triplett schrieb:
> On Wed, Sep 16, 2009 at 01:11:26PM +0200, Johannes Sixt wrote:
>> How about '--output -' instead?
> 
> Yeah, that seems significantly better than --force.  Though I don't
> particularly care for the '-' convention to mean 'stdout'; in principle
> that ought to create a file named '-' in the current directory.
> /dev/stdout makes more sense, and doesn't require any work on git's
> part beyond this patch.

Except that /dev/stdout is not portable. You can always say --output ./-
if you want an oddly named file in the current directory.

-- Hannes

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2009-09-17  5:55 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-09-16 10:31 [PATCH] archive: Refuse to write the archive to a terminal Josh Triplett
2009-09-16 11:11 ` Johannes Sixt
2009-09-16 11:27   ` Mikael Magnusson
2009-09-16 11:48     ` Reece Dunn
2009-09-16 12:57       ` Matthieu Moy
2009-09-17  1:49   ` Josh Triplett
2009-09-17  5:53     ` Johannes Sixt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).