static void update_callback(struct diff_queue_struct *q, struct diff_options *opt, void *cbdata) { int i; struct update_callback_data *data = cbdata; for (i = 0; i < q->nr; i++) { struct diff_filepair *p = q->queue[i]; const char *path = p->one->path; switch (fix_unmerged_status(p, data)) { default: die(_("unexpected diff status %c"), p->status); case DIFF_STATUS_MODIFIED: case DIFF_STATUS_TYPE_CHANGED: if (add_file_to_index(&the_index, path, data->flags)) { if (!(data->flags & ADD_CACHE_IGNORE_ERRORS)) die(_("updating files failed")); data->add_errors++; } break; case DIFF_STATUS_DELETED: if (data->flags & ADD_CACHE_IGNORE_REMOVAL) break; if (!(data->flags & ADD_CACHE_PRETEND)) remove_file_from_index(&the_index, path); if (data->flags & (ADD_CACHE_PRETEND|ADD_CACHE_VERBOSE)) printf(_("remove '%s'\n"), path); break; } } }
static void update_callback(struct diff_queue_struct *q, struct diff_options *opt, void *cbdata) { int i; struct update_callback_data *data = cbdata; for (i = 0; i < q->nr; i++) { struct diff_filepair *p = q->queue[i]; const char *path = p->one->path; switch (p->status) { default: die("unexpected diff status %c", p->status); case DIFF_STATUS_UNMERGED: /* * ADD_CACHE_IGNORE_REMOVAL is unset if "git * add -u" is calling us, In such a case, a * missing work tree file needs to be removed * if there is an unmerged entry at stage #2, * but such a diff record is followed by * another with DIFF_STATUS_DELETED (and if * there is no stage #2, we won't see DELETED * nor MODIFIED). We can simply continue * either way. */ if (!(data->flags & ADD_CACHE_IGNORE_REMOVAL)) continue; /* * Otherwise, it is "git add path" is asking * to explicitly add it; we fall through. A * missing work tree file is an error and is * caught by add_file_to_index() in such a * case. */ case DIFF_STATUS_MODIFIED: case DIFF_STATUS_TYPE_CHANGED: if (add_file_to_index(&the_index, path, data->flags)) { if (!(data->flags & ADD_CACHE_IGNORE_ERRORS)) die("updating files failed"); data->add_errors++; } break; case DIFF_STATUS_DELETED: if (data->flags & ADD_CACHE_IGNORE_REMOVAL) break; if (!(data->flags & ADD_CACHE_PRETEND)) remove_file_from_index(&the_index, path); if (data->flags & (ADD_CACHE_PRETEND|ADD_CACHE_VERBOSE)) printf("remove '%s'\n", path); break; } } }
static void update_callback(struct diff_queue_struct *q, struct diff_options *opt, void *cbdata) { int i; struct update_callback_data *data = cbdata; const char *implicit_dot = data->implicit_dot; size_t implicit_dot_len = data->implicit_dot_len; for (i = 0; i < q->nr; i++) { struct diff_filepair *p = q->queue[i]; const char *path = p->one->path; /* * Check if "git add -A" or "git add -u" was run from a * subdirectory with a modified file outside that directory, * and warn if so. * * "git add -u" will behave like "git add -u :/" instead of * "git add -u ." in the future. This warning prepares for * that change. */ if (implicit_dot && strncmp_icase(path, implicit_dot, implicit_dot_len)) { warn_pathless_add(); continue; } switch (fix_unmerged_status(p, data)) { default: die(_("unexpected diff status %c"), p->status); case DIFF_STATUS_MODIFIED: case DIFF_STATUS_TYPE_CHANGED: if (add_file_to_index(&the_index, path, data->flags)) { if (!(data->flags & ADD_CACHE_IGNORE_ERRORS)) die(_("updating files failed")); data->add_errors++; } break; case DIFF_STATUS_DELETED: if (data->warn_add_would_remove) { warn_add_would_remove(path); data->warn_add_would_remove = 0; } if (data->flags & ADD_CACHE_IGNORE_REMOVAL) break; if (!(data->flags & ADD_CACHE_PRETEND)) remove_file_from_index(&the_index, path); if (data->flags & (ADD_CACHE_PRETEND|ADD_CACHE_VERBOSE)) printf(_("remove '%s'\n"), path); break; } } }
static void update_paths(struct repository *r, struct string_list *update) { struct lock_file index_lock = LOCK_INIT; int i; repo_hold_locked_index(r, &index_lock, LOCK_DIE_ON_ERROR); for (i = 0; i < update->nr; i++) { struct string_list_item *item = &update->items[i]; if (add_file_to_index(r->index, item->string, 0)) exit(128); fprintf_ln(stderr, _("Staged '%s' using previous resolution."), item->string); } if (write_locked_index(r->index, &index_lock, COMMIT_LOCK | SKIP_IF_UNCHANGED)) die(_("unable to write new index file")); }
static int add_files(struct dir_struct *dir, int flags) { int i, exit_status = 0; if (dir->ignored_nr) { fprintf(stderr, _(ignore_error)); for (i = 0; i < dir->ignored_nr; i++) fprintf(stderr, "%s\n", dir->ignored[i]->name); fprintf(stderr, _("Use -f if you really want to add them.\n")); exit_status = 1; } for (i = 0; i < dir->nr; i++) if (add_file_to_index(&the_index, dir->entries[i]->name, flags)) { if (!ignore_add_errors) die(_("adding files failed")); exit_status = 1; } return exit_status; }