MCPcopy Create free account
hub / github.com/git/git / cmd_rm

Function cmd_rm

builtin/rm.c:265–447  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

263};
264
265int cmd_rm(int argc,
266 const char **argv,
267 const char *prefix,
268 struct repository *repo UNUSED)
269{
270 struct lock_file lock_file = LOCK_INIT;
271 int i, ret = 0;
272 struct pathspec pathspec;
273 char *seen;
274
275 repo_config(the_repository, git_default_config, NULL);
276
277 argc = parse_options(argc, argv, prefix, builtin_rm_options,
278 builtin_rm_usage, 0);
279
280 parse_pathspec(&pathspec, 0,
281 PATHSPEC_PREFER_CWD,
282 prefix, argv);
283
284 if (pathspec_from_file) {
285 if (pathspec.nr)
286 die(_("'%s' and pathspec arguments cannot be used together"), "--pathspec-from-file");
287
288 parse_pathspec_file(&pathspec, 0,
289 PATHSPEC_PREFER_CWD,
290 prefix, pathspec_from_file, pathspec_file_nul);
291 } else if (pathspec_file_nul) {
292 die(_("the option '%s' requires '%s'"), "--pathspec-file-nul", "--pathspec-from-file");
293 }
294
295 if (!pathspec.nr)
296 die(_("No pathspec was given. Which files should I remove?"));
297
298 if (!index_only)
299 setup_work_tree(the_repository);
300
301 prepare_repo_settings(the_repository);
302 the_repository->settings.command_requires_full_index = 0;
303 repo_hold_locked_index(the_repository, &lock_file, LOCK_DIE_ON_ERROR);
304
305 if (repo_read_index(the_repository) < 0)
306 die(_("index file corrupt"));
307
308 refresh_index(the_repository->index, REFRESH_QUIET|REFRESH_UNMERGED, &pathspec, NULL, NULL);
309
310 seen = xcalloc(pathspec.nr, 1);
311
312 if (pathspec_needs_expanded_index(the_repository->index, &pathspec))
313 ensure_full_index(the_repository->index);
314
315 for (unsigned int i = 0; i < the_repository->index->cache_nr; i++) {
316 const struct cache_entry *ce = the_repository->index->cache[i];
317
318 if (!include_sparse &&
319 (ce_skip_worktree(ce) ||
320 !path_in_sparse_checkout(ce->name, the_repository->index)))
321 continue;
322 if (!ce_path_match(the_repository->index, ce, &pathspec, seen))

Callers

nothing calls this directly

Calls 15

parse_optionsFunction · 0.85
parse_pathspecFunction · 0.85
parse_pathspec_fileFunction · 0.85
setup_work_treeFunction · 0.85
prepare_repo_settingsFunction · 0.85
repo_hold_locked_indexFunction · 0.85
repo_read_indexFunction · 0.85
refresh_indexFunction · 0.85
xcallocFunction · 0.85
ensure_full_indexFunction · 0.85
path_in_sparse_checkoutFunction · 0.85

Tested by

no test coverage detected