| 818 | } |
| 819 | |
| 820 | static int run_add_untracked(struct add_i_state *s, const struct pathspec *ps, |
| 821 | struct prefix_item_list *files, |
| 822 | struct list_and_choose_options *opts) |
| 823 | { |
| 824 | struct print_file_item_data *d = opts->list_opts.print_item_data; |
| 825 | int res = 0, fd; |
| 826 | size_t count, i; |
| 827 | struct lock_file index_lock; |
| 828 | |
| 829 | if (get_untracked_files(s->r, files, ps) < 0) |
| 830 | return -1; |
| 831 | |
| 832 | if (!files->items.nr) { |
| 833 | printf(_("No untracked files.\n")); |
| 834 | goto finish_add_untracked; |
| 835 | } |
| 836 | |
| 837 | opts->prompt = N_("Add untracked"); |
| 838 | d->only_names = 1; |
| 839 | count = list_and_choose(s, files, opts); |
| 840 | d->only_names = 0; |
| 841 | if (count <= 0) |
| 842 | goto finish_add_untracked; |
| 843 | |
| 844 | fd = repo_hold_locked_index(s->r, &index_lock, LOCK_REPORT_ON_ERROR); |
| 845 | if (fd < 0) { |
| 846 | res = -1; |
| 847 | goto finish_add_untracked; |
| 848 | } |
| 849 | |
| 850 | for (i = 0; i < files->items.nr; i++) { |
| 851 | const char *name = files->items.items[i].string; |
| 852 | if (files->selected[i] && |
| 853 | add_file_to_index(s->r->index, name, 0) < 0) { |
| 854 | res = error(_("could not stage '%s'"), name); |
| 855 | break; |
| 856 | } |
| 857 | } |
| 858 | |
| 859 | if (!res && |
| 860 | write_locked_index(s->r->index, &index_lock, COMMIT_LOCK) < 0) |
| 861 | res = error(_("could not write index")); |
| 862 | |
| 863 | if (!res) |
| 864 | printf(Q_("added %d path\n", |
| 865 | "added %d paths\n", count), (int)count); |
| 866 | |
| 867 | finish_add_untracked: |
| 868 | putchar('\n'); |
| 869 | return res; |
| 870 | } |
| 871 | |
| 872 | static int run_patch(struct add_i_state *s, const struct pathspec *ps, |
| 873 | struct prefix_item_list *files, |
nothing calls this directly
no test coverage detected