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

Function prepare_index

builtin/commit.c:351–561  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

349}
350
351static const char *prepare_index(const char **argv, const char *prefix,
352 const struct commit *current_head, int is_status)
353{
354 struct string_list partial = STRING_LIST_INIT_DUP;
355 struct pathspec pathspec;
356 int refresh_flags = REFRESH_QUIET;
357 const char *ret;
358 char *path = NULL;
359
360 if (interactive_opts.context < -1)
361 die(_("'%s' cannot be negative"), "--unified");
362 if (interactive_opts.interhunkcontext < -1)
363 die(_("'%s' cannot be negative"), "--inter-hunk-context");
364
365 if (is_status)
366 refresh_flags |= REFRESH_UNMERGED;
367 parse_pathspec(&pathspec, 0,
368 PATHSPEC_PREFER_FULL,
369 prefix, argv);
370
371 if (pathspec_from_file) {
372 if (interactive)
373 die(_("options '%s' and '%s' cannot be used together"), "--pathspec-from-file", "--interactive/--patch");
374
375 if (all)
376 die(_("options '%s' and '%s' cannot be used together"), "--pathspec-from-file", "-a");
377
378 if (pathspec.nr)
379 die(_("'%s' and pathspec arguments cannot be used together"), "--pathspec-from-file");
380
381 parse_pathspec_file(&pathspec, 0,
382 PATHSPEC_PREFER_FULL,
383 prefix, pathspec_from_file, pathspec_file_nul);
384 } else if (pathspec_file_nul) {
385 die(_("the option '%s' requires '%s'"), "--pathspec-file-nul", "--pathspec-from-file");
386 }
387
388 if (!pathspec.nr && (also || (only && !allow_empty &&
389 (!amend || (fixup_message && strcmp(fixup_prefix, "amend"))))))
390 die(_("No paths with --include/--only does not make sense."));
391
392 if (repo_read_index_preload(the_repository, &pathspec, 0) < 0)
393 die(_("index file corrupt"));
394
395 if (interactive) {
396 char *old_index_env = NULL, *old_repo_index_file;
397 repo_hold_locked_index(the_repository, &index_lock,
398 LOCK_DIE_ON_ERROR);
399
400 refresh_cache_or_die(refresh_flags);
401
402 if (write_locked_index(the_repository->index, &index_lock, 0))
403 die(_("unable to create temporary index"));
404
405 old_repo_index_file = the_repository->index_file;
406 the_repository->index_file =
407 (char *)get_lock_file_path(&index_lock);
408 old_index_env = xstrdup_or_null(getenv(INDEX_ENVIRONMENT));

Callers 2

dry_run_commitFunction · 0.85
cmd_commitFunction · 0.85

Calls 15

parse_pathspecFunction · 0.85
parse_pathspec_fileFunction · 0.85
repo_read_index_preloadFunction · 0.85
repo_hold_locked_indexFunction · 0.85
refresh_cache_or_dieFunction · 0.85
write_locked_indexFunction · 0.85
get_lock_file_pathFunction · 0.85
xstrdup_or_nullFunction · 0.85
interactive_addFunction · 0.85
discard_indexFunction · 0.85
read_index_fromFunction · 0.85
repo_get_git_dirFunction · 0.85

Tested by

no test coverage detected