Skip to content

Commit

Permalink
git-clean: handle errors if removing files fails
Browse files Browse the repository at this point in the history
git-clean simply ignored errors if removing a file or directory failed. This
patch makes it raise a warning and the exit code also greater than zero if
there are remaining files.

Signed-off-by: Miklos Vajna <vmiklos@frugalware.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Miklos Vajna authored and Junio C Hamano committed Feb 21, 2008
1 parent b23b27e commit aa9c83c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
22 changes: 14 additions & 8 deletions builtin-clean.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
{
int i;
int show_only = 0, remove_directories = 0, quiet = 0, ignored = 0;
int ignored_only = 0, baselen = 0, config_set = 0;
int ignored_only = 0, baselen = 0, config_set = 0, errors = 0;
struct strbuf directory;
struct dir_struct dir;
const char *path, *base;
Expand Down Expand Up @@ -137,12 +137,15 @@ 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) {
warning("failed to remove '%s'",
directory.buf + prefix_offset);
errors++;
}
} else if (show_only) {
printf("Would not remove %s\n",
directory.buf + prefix_offset);
Expand All @@ -162,11 +165,14 @@ 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) {
warning("failed to remove '%s'", ent->name);
errors++;
}
}
}
free(seen);

strbuf_release(&directory);
return 0;
return (errors != 0);
}
10 changes: 10 additions & 0 deletions t/t7300-clean.sh
Original file line number Diff line number Diff line change
Expand Up @@ -316,4 +316,14 @@ test_expect_success 'core.excludesfile' '
'

test_expect_success 'removal failure' '
mkdir foo &&
touch foo/bar &&
chmod 0 foo &&
! git clean -f -d
'
chmod 755 foo

test_done

0 comments on commit aa9c83c

Please sign in to comment.