summaryrefslogtreecommitdiff
path: root/builtin/rm.c
diff options
context:
space:
mode:
Diffstat (limited to 'builtin/rm.c')
-rw-r--r--builtin/rm.c37
1 files changed, 26 insertions, 11 deletions
diff --git a/builtin/rm.c b/builtin/rm.c
index 4858631..d89f241 100644
--- a/builtin/rm.c
+++ b/builtin/rm.c
@@ -5,6 +5,7 @@
*/
#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "builtin.h"
+#include "advice.h"
#include "config.h"
#include "lockfile.h"
#include "dir.h"
@@ -254,7 +255,7 @@ static struct option builtin_rm_options[] = {
int cmd_rm(int argc, const char **argv, const char *prefix)
{
struct lock_file lock_file = LOCK_INIT;
- int i;
+ int i, ret = 0;
struct pathspec pathspec;
char *seen;
@@ -293,8 +294,12 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
seen = xcalloc(pathspec.nr, 1);
+ /* TODO: audit for interaction with sparse-index. */
+ ensure_full_index(&the_index);
for (i = 0; i < active_nr; i++) {
const struct cache_entry *ce = active_cache[i];
+ if (ce_skip_worktree(ce))
+ continue;
if (!ce_path_match(&the_index, ce, &pathspec, seen))
continue;
ALLOC_GROW(list.entry, list.nr + 1, list.alloc);
@@ -308,24 +313,34 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
if (pathspec.nr) {
const char *original;
int seen_any = 0;
+ char *skip_worktree_seen = NULL;
+ struct string_list only_match_skip_worktree = STRING_LIST_INIT_NODUP;
+
for (i = 0; i < pathspec.nr; i++) {
original = pathspec.items[i].original;
- if (!seen[i]) {
- if (!ignore_unmatch) {
- die(_("pathspec '%s' did not match any files"),
- original);
- }
- }
- else {
+ if (seen[i])
seen_any = 1;
- }
+ else if (ignore_unmatch)
+ continue;
+ else if (matches_skip_worktree(&pathspec, i, &skip_worktree_seen))
+ string_list_append(&only_match_skip_worktree, original);
+ else
+ die(_("pathspec '%s' did not match any files"), original);
+
if (!recursive && seen[i] == MATCHED_RECURSIVELY)
die(_("not removing '%s' recursively without -r"),
*original ? original : ".");
}
+ if (only_match_skip_worktree.nr) {
+ advise_on_updating_sparse_paths(&only_match_skip_worktree);
+ ret = 1;
+ }
+ free(skip_worktree_seen);
+ string_list_clear(&only_match_skip_worktree, 0);
+
if (!seen_any)
- exit(0);
+ exit(ret);
}
if (!index_only)
@@ -405,5 +420,5 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
COMMIT_LOCK | SKIP_IF_UNCHANGED))
die(_("Unable to write new index file"));
- return 0;
+ return ret;
}