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

Function run_add_untracked

add-interactive.c:820–870  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

818}
819
820static 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
867finish_add_untracked:
868 putchar('\n');
869 return res;
870}
871
872static int run_patch(struct add_i_state *s, const struct pathspec *ps,
873 struct prefix_item_list *files,

Callers

nothing calls this directly

Calls 6

repo_hold_locked_indexFunction · 0.85
add_file_to_indexFunction · 0.85
errorFunction · 0.85
write_locked_indexFunction · 0.85
get_untracked_filesFunction · 0.70
list_and_chooseFunction · 0.70

Tested by

no test coverage detected