MCPcopy Index your code
hub / github.com/git/git / cmd_replace

Function cmd_replace

builtin/replace.c:545–639  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

543}
544
545int cmd_replace(int argc,
546 const char **argv,
547 const char *prefix,
548 struct repository *repo UNUSED)
549{
550 int force = 0;
551 int raw = 0;
552 const char *format = NULL;
553 enum {
554 MODE_UNSPECIFIED = 0,
555 MODE_LIST,
556 MODE_DELETE,
557 MODE_EDIT,
558 MODE_GRAFT,
559 MODE_CONVERT_GRAFT_FILE,
560 MODE_REPLACE
561 } cmdmode = MODE_UNSPECIFIED;
562 struct option options[] = {
563 OPT_CMDMODE('l', "list", &cmdmode, N_("list replace refs"), MODE_LIST),
564 OPT_CMDMODE('d', "delete", &cmdmode, N_("delete replace refs"), MODE_DELETE),
565 OPT_CMDMODE('e', "edit", &cmdmode, N_("edit existing object"), MODE_EDIT),
566 OPT_CMDMODE('g', "graft", &cmdmode, N_("change a commit's parents"), MODE_GRAFT),
567 OPT_CMDMODE(0, "convert-graft-file", &cmdmode, N_("convert existing graft file"), MODE_CONVERT_GRAFT_FILE),
568 OPT_BOOL_F('f', "force", &force, N_("replace the ref if it exists"),
569 PARSE_OPT_NOCOMPLETE),
570 OPT_BOOL(0, "raw", &raw, N_("do not pretty-print contents for --edit")),
571 OPT_STRING(0, "format", &format, N_("format"), N_("use this format")),
572 OPT_END()
573 };
574
575 disable_replace_refs();
576 repo_config(the_repository, git_default_config, NULL);
577
578 argc = parse_options(argc, argv, prefix, options, git_replace_usage, 0);
579
580 if (!cmdmode)
581 cmdmode = argc ? MODE_REPLACE : MODE_LIST;
582
583 if (format && cmdmode != MODE_LIST)
584 usage_msg_opt(_("--format cannot be used when not listing"),
585 git_replace_usage, options);
586
587 if (force &&
588 cmdmode != MODE_REPLACE &&
589 cmdmode != MODE_EDIT &&
590 cmdmode != MODE_GRAFT &&
591 cmdmode != MODE_CONVERT_GRAFT_FILE)
592 usage_msg_opt(_("-f only makes sense when writing a replacement"),
593 git_replace_usage, options);
594
595 if (raw && cmdmode != MODE_EDIT)
596 usage_msg_opt(_("--raw only makes sense with --edit"),
597 git_replace_usage, options);
598
599 switch (cmdmode) {
600 case MODE_DELETE:
601 if (argc < 1)
602 usage_msg_opt(_("-d needs at least one argument"),

Callers

nothing calls this directly

Calls 10

disable_replace_refsFunction · 0.85
parse_optionsFunction · 0.85
usage_msg_optFunction · 0.85
for_each_replace_nameFunction · 0.85
edit_and_replaceFunction · 0.85
create_graftFunction · 0.85
convert_graft_fileFunction · 0.85
list_replace_refsFunction · 0.85
replace_objectFunction · 0.70
repo_configFunction · 0.50

Tested by

no test coverage detected