Skip to contentSkip to conversation

archive: Refuse to write the archive to a terminal.

PATCH In review Josh Triplett 5 participants 7 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 archive: Refuse to write the archive to a terminal.

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.

---

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(-)
builtin-archive.c +3 -0
index 12351e9..73accd0 100644
@@ -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) {
Signature · 1 line
1.6.3.3
#1 lore raw
Quoted 3 lines · Josh Triplett

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

#2 lore raw
Quoted 6 lines · Johannes Sixt
Quoted 3 lines · Josh Triplett

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

#3 lore raw
Quoted 8 lines · Josh Triplett
Quoted 1 line · Johannes Sixt

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

#4 lore raw
In reply to Johannes Sixt

2009/9/16 Johannes Sixt <[email protected]>:

Quoted 6 lines
Quoted 3 lines · Josh Triplett

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'.

Signature · 1 line
Mikael Magnusson
#5 lore raw

2009/9/16 Mikael Magnusson <[email protected]>:

Quoted 9 lines

2009/9/16 Johannes Sixt <[email protected]>:

Quoted 6 lines
Quoted 3 lines · Josh Triplett

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

#6 lore raw
Quoted 7 lines · Reece Dunn

2009/9/16 Mikael Magnusson <[email protected]>:

Quoted 6 lines

2009/9/16 Johannes Sixt <[email protected]>:

Quoted 5 lines
Quoted 3 lines · Josh Triplett

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. ;)

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

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.

Quoted 1 line

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

I like this too.

Signature · 2 lines
Matthieu Moy
http://www-verimag.imag.fr/~moy/