Skip to content

Commit

Permalink
git-rm: do not fail on already removed file.
Browse files Browse the repository at this point in the history
Often the user would do "/bin/rm foo" before telling git, but
then want to tell git about it.  "git rm foo" however would fail
because it cannot unlink(2) foo.

Treat ENOENT error return from unlink(2) as if a successful
removal happened.

Signed-off-by: Junio C Hamano <junkio@cox.net>
  • Loading branch information
Junio C Hamano committed Jan 11, 2007
1 parent 3b97fee commit 646ac22
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion builtin-rm.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ static int remove_file(const char *name)
char *slash;

ret = unlink(name);
if (ret && errno == ENOENT)
/* The user has removed it from the filesystem by hand */
ret = errno = 0;

if (!ret && (slash = strrchr(name, '/'))) {
char *n = xstrdup(name);
do {
Expand Down Expand Up @@ -204,7 +208,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
return 0;

/*
* Then, unless we used "--cache", remove the filenames from
* Then, unless we used "--cached", remove the filenames from
* the workspace. If we fail to remove the first one, we
* abort the "git rm" (but once we've successfully removed
* any file at all, we'll go ahead and commit to it all:
Expand Down

0 comments on commit 646ac22

Please sign in to comment.