| 620 | } |
| 621 | |
| 622 | static int run_update(struct add_i_state *s, const struct pathspec *ps, |
| 623 | struct prefix_item_list *files, |
| 624 | struct list_and_choose_options *opts) |
| 625 | { |
| 626 | int res = 0, fd; |
| 627 | size_t count, i; |
| 628 | struct lock_file index_lock; |
| 629 | |
| 630 | if (get_modified_files(s->r, WORKTREE_ONLY, files, ps, NULL, NULL) < 0) |
| 631 | return -1; |
| 632 | |
| 633 | if (!files->items.nr) { |
| 634 | putchar('\n'); |
| 635 | return 0; |
| 636 | } |
| 637 | |
| 638 | opts->prompt = N_("Update"); |
| 639 | count = list_and_choose(s, files, opts); |
| 640 | if (count <= 0) { |
| 641 | putchar('\n'); |
| 642 | return 0; |
| 643 | } |
| 644 | |
| 645 | fd = repo_hold_locked_index(s->r, &index_lock, LOCK_REPORT_ON_ERROR); |
| 646 | if (fd < 0) { |
| 647 | putchar('\n'); |
| 648 | return -1; |
| 649 | } |
| 650 | |
| 651 | for (i = 0; i < files->items.nr; i++) { |
| 652 | const char *name = files->items.items[i].string; |
| 653 | struct stat st; |
| 654 | |
| 655 | if (!files->selected[i]) |
| 656 | continue; |
| 657 | if (lstat(name, &st) && is_missing_file_error(errno)) { |
| 658 | if (remove_file_from_index(s->r->index, name) < 0) { |
| 659 | res = error(_("could not stage '%s'"), name); |
| 660 | break; |
| 661 | } |
| 662 | } else if (add_file_to_index(s->r->index, name, 0) < 0) { |
| 663 | res = error(_("could not stage '%s'"), name); |
| 664 | break; |
| 665 | } |
| 666 | } |
| 667 | |
| 668 | if (!res && write_locked_index(s->r->index, &index_lock, COMMIT_LOCK) < 0) |
| 669 | res = error(_("could not write index")); |
| 670 | |
| 671 | if (!res) |
| 672 | printf(Q_("updated %d path\n", |
| 673 | "updated %d paths\n", count), (int)count); |
| 674 | |
| 675 | putchar('\n'); |
| 676 | return res; |
| 677 | } |
| 678 | |
| 679 | static void revert_from_diff(struct diff_queue_struct *q, |
nothing calls this directly
no test coverage detected