git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Miklos Vajna <vmiklos@frugalware.org>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org
Subject: [PATCH] git-clean: handle errors if removing files fails
Date: Thu, 21 Feb 2008 00:41:54 +0100	[thread overview]
Message-ID: <20080220234154.GS31441@genesis.frugalware.org> (raw)

Consider the following case:

$ sudo mkdir foo
$ sudo touch foo/bar

This is the old output:

$ git clean -f -d
Removing foo/

No error message.

This is the new output:

$ ~/git/git/git clean -f -d
Removing foo/
fatal: failed to remove 'foo/'

Signed-off-by: Miklos Vajna <vmiklos@frugalware.org>
---
 builtin-clean.c  |   14 ++++++++------
 t/t7300-clean.sh |    9 +++++++++
 2 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/builtin-clean.c b/builtin-clean.c
index eb853a3..c8753a5 100644
--- a/builtin-clean.c
+++ b/builtin-clean.c
@@ -137,12 +137,13 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
 			if (show_only && (remove_directories || matches)) {
 				printf("Would remove %s\n",
 				       directory.buf + prefix_offset);
-			} else if (quiet && (remove_directories || matches)) {
-				remove_dir_recursively(&directory, 0);
 			} else if (remove_directories || matches) {
-				printf("Removing %s\n",
-				       directory.buf + prefix_offset);
-				remove_dir_recursively(&directory, 0);
+				if (!quiet)
+					printf("Removing %s\n",
+					       directory.buf + prefix_offset);
+				if (remove_dir_recursively(&directory, 0) != 0)
+					die("failed to remove '%s'",
+						directory.buf + prefix_offset);
 			} else if (show_only) {
 				printf("Would not remove %s\n",
 				       directory.buf + prefix_offset);
@@ -162,7 +163,8 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
 				printf("Removing %s\n",
 				       ent->name + prefix_offset);
 			}
-			unlink(ent->name);
+			if (unlink(ent->name) != 0)
+				die("failed to remove '%s'", ent->name);
 		}
 	}
 	free(seen);
diff --git a/t/t7300-clean.sh b/t/t7300-clean.sh
index dfd1188..bd0a814 100755
--- a/t/t7300-clean.sh
+++ b/t/t7300-clean.sh
@@ -316,4 +316,13 @@ test_expect_success 'core.excludesfile' '
 
 '
 
+test_expect_success 'removal failure' '
+
+	mkdir foo &&
+	touch foo/bar &&
+	chmod 0 foo &&
+	! git clean -f -d
+
+'
+
 test_done
-- 
1.5.4.1

             reply	other threads:[~2008-02-20 23:43 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-02-20 23:41 Miklos Vajna [this message]
2008-02-21  0:12 ` [PATCH] git-clean: handle errors if removing files fails Junio C Hamano
2008-02-21  1:44   ` Miklos Vajna

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080220234154.GS31441@genesis.frugalware.org \
    --to=vmiklos@frugalware.org \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).