| 576 | } |
| 577 | |
| 578 | static int copy(int argc, const char **argv, const char *prefix, |
| 579 | struct repository *repo UNUSED) |
| 580 | { |
| 581 | int retval = 0, force = 0, from_stdin = 0; |
| 582 | const struct object_id *from_note, *note; |
| 583 | const char *object_ref; |
| 584 | struct object_id object, from_obj; |
| 585 | struct notes_tree *t; |
| 586 | const char *rewrite_cmd = NULL; |
| 587 | struct option options[] = { |
| 588 | OPT__FORCE(&force, N_("replace existing notes"), PARSE_OPT_NOCOMPLETE), |
| 589 | OPT_BOOL(0, "stdin", &from_stdin, N_("read objects from stdin")), |
| 590 | OPT_STRING(0, "for-rewrite", &rewrite_cmd, N_("command"), |
| 591 | N_("load rewriting config for <command> (implies " |
| 592 | "--stdin)")), |
| 593 | OPT_END() |
| 594 | }; |
| 595 | |
| 596 | argc = parse_options(argc, argv, prefix, options, git_notes_copy_usage, |
| 597 | 0); |
| 598 | |
| 599 | if (from_stdin || rewrite_cmd) { |
| 600 | if (argc) { |
| 601 | error(_("too many arguments")); |
| 602 | usage_with_options(git_notes_copy_usage, options); |
| 603 | } else { |
| 604 | return notes_copy_from_stdin(force, rewrite_cmd); |
| 605 | } |
| 606 | } |
| 607 | |
| 608 | if (argc < 1) { |
| 609 | error(_("too few arguments")); |
| 610 | usage_with_options(git_notes_copy_usage, options); |
| 611 | } |
| 612 | if (2 < argc) { |
| 613 | error(_("too many arguments")); |
| 614 | usage_with_options(git_notes_copy_usage, options); |
| 615 | } |
| 616 | |
| 617 | if (repo_get_oid(the_repository, argv[0], &from_obj)) |
| 618 | die(_("failed to resolve '%s' as a valid ref."), argv[0]); |
| 619 | |
| 620 | object_ref = 1 < argc ? argv[1] : "HEAD"; |
| 621 | |
| 622 | if (repo_get_oid(the_repository, object_ref, &object)) |
| 623 | die(_("failed to resolve '%s' as a valid ref."), object_ref); |
| 624 | |
| 625 | t = init_notes_check("copy", NOTES_INIT_WRITABLE); |
| 626 | note = get_note(t, &object); |
| 627 | |
| 628 | if (note) { |
| 629 | if (!force) { |
| 630 | retval = error(_("Cannot copy notes. Found existing " |
| 631 | "notes for object %s. Use '-f' to " |
| 632 | "overwrite existing notes"), |
| 633 | oid_to_hex(&object)); |
| 634 | goto out; |
| 635 | } |
no test coverage detected