git-stash: require "save" to be explicit and update documentation
[gitweb.git] / git.c
diff --git a/git.c b/git.c
index 911fd3dabb7bca08365e9dd68a5b52bcb7bdbe6d..cfec5d70ee42852f3819fe46e99ebc70f089ccc7 100644 (file)
--- a/git.c
+++ b/git.c
@@ -224,6 +224,8 @@ struct cmd_struct {
 
 static int run_command(struct cmd_struct *p, int argc, const char **argv)
 {
+       int status;
+       struct stat st;
        const char *prefix;
 
        prefix = NULL;
@@ -237,7 +239,25 @@ static int run_command(struct cmd_struct *p, int argc, const char **argv)
        }
        trace_argv_printf(argv, argc, "trace: built-in: git");
 
-       return p->fn(argc, argv, prefix);
+       status = p->fn(argc, argv, prefix);
+       if (status)
+               return status;
+
+       /* Somebody closed stdout? */
+       if (fstat(fileno(stdout), &st))
+               return 0;
+       /* Ignore write errors for pipes and sockets.. */
+       if (S_ISFIFO(st.st_mode) || S_ISSOCK(st.st_mode))
+               return 0;
+
+       /* Check for ENOSPC and EIO errors.. */
+       if (fflush(stdout))
+               die("write failure on standard output: %s", strerror(errno));
+       if (ferror(stdout))
+               die("unknown write failure on standard output");
+       if (fclose(stdout))
+               die("close failed on standard output: %s", strerror(errno));
+       return 0;
 }
 
 static void handle_internal_command(int argc, const char **argv)